mirror of https://github.com/axmolengine/axmol.git
Improve VS Ninja workflow
This commit is contained in:
parent
430030a6c3
commit
c9f3ca9278
|
@ -2,9 +2,9 @@
|
||||||
# Copyright (c) 2013 cocos2d-x.org
|
# Copyright (c) 2013 cocos2d-x.org
|
||||||
# Copyright (c) 2014 martell malone
|
# Copyright (c) 2014 martell malone
|
||||||
# Copyright (c) 2015-2017 Chukong Technologies Inc.
|
# Copyright (c) 2015-2017 Chukong Technologies Inc.
|
||||||
# Copyright (c) 2021 Bytedance Inc.
|
# Copyright (c) 2021-2022 Bytedance Inc.
|
||||||
#
|
#
|
||||||
# https://adxe.org
|
# https://adxeproject.github.io/
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -42,6 +42,9 @@ THE SOFTWARE.
|
||||||
#include "base/CCScheduler.h"
|
#include "base/CCScheduler.h"
|
||||||
#include "base/CCDirector.h"
|
#include "base/CCDirector.h"
|
||||||
|
|
||||||
|
#define AX_PC_RESOURCES_DIR "Resources/"
|
||||||
|
#define AX_PC_RESOURCES_DIR_LEN (sizeof("Resources/") - 1)
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Copyright (c) 2011 Laschweinski
|
Copyright (c) 2011 Laschweinski
|
||||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||||
Copyright (c) 2021 Bytedance Inc.
|
Copyright (c) 2021-2022 Bytedance Inc.
|
||||||
|
|
||||||
https://adxeproject.github.io
|
https://adxeproject.github.io
|
||||||
|
|
||||||
|
@ -34,10 +34,6 @@ THE SOFTWARE.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef CC_RESOURCE_FOLDER_LINUX
|
|
||||||
# define CC_RESOURCE_FOLDER_LINUX ("/Resources/")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
||||||
|
@ -75,8 +71,8 @@ bool FileUtilsLinux::init()
|
||||||
|
|
||||||
fullpath[length] = '\0';
|
fullpath[length] = '\0';
|
||||||
std::string appPath = fullpath;
|
std::string appPath = fullpath;
|
||||||
_defaultResRootPath = appPath.substr(0, appPath.find_last_of('/'));
|
_defaultResRootPath = appPath.substr(0, appPath.find_last_of('/') + 1);
|
||||||
_defaultResRootPath += CC_RESOURCE_FOLDER_LINUX;
|
_defaultResRootPath += AX_PC_RESOURCES_DIR;
|
||||||
|
|
||||||
// Set writable path to $XDG_CONFIG_HOME or ~/.config/<app name>/ if $XDG_CONFIG_HOME not exists.
|
// Set writable path to $XDG_CONFIG_HOME or ~/.config/<app name>/ if $XDG_CONFIG_HOME not exists.
|
||||||
const char* xdg_config_path = getenv("XDG_CONFIG_HOME");
|
const char* xdg_config_path = getenv("XDG_CONFIG_HOME");
|
||||||
|
@ -105,7 +101,6 @@ string FileUtilsLinux::getWritablePath() const
|
||||||
|
|
||||||
std::string FileUtilsLinux::getNativeWritableAbsolutePath() const
|
std::string FileUtilsLinux::getNativeWritableAbsolutePath() const
|
||||||
{
|
{
|
||||||
DECLARE_GUARD;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
stat(_writablePath.c_str(), &st);
|
stat(_writablePath.c_str(), &st);
|
||||||
if (!S_ISDIR(st.st_mode))
|
if (!S_ISDIR(st.st_mode))
|
||||||
|
@ -118,19 +113,6 @@ std::string FileUtilsLinux::getNativeWritableAbsolutePath() const
|
||||||
|
|
||||||
bool FileUtilsLinux::isFileExistInternal(std::string_view path) const
|
bool FileUtilsLinux::isFileExistInternal(std::string_view path) const
|
||||||
{
|
{
|
||||||
DECLARE_GUARD;
|
|
||||||
if (path.empty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string strPath;
|
|
||||||
if (!isAbsolutePath(path))
|
|
||||||
{ // Not absolute path, add the default root path at the beginning.
|
|
||||||
strPath.assign(_defaultResRootPath).append(path);
|
|
||||||
path = strPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct stat sts;
|
struct stat sts;
|
||||||
return (stat(path.data(), &sts) == 0) && S_ISREG(sts.st_mode);
|
return (stat(path.data(), &sts) == 0) && S_ISREG(sts.st_mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Copyright (c) 2010-2012 cocos2d-x.org
|
Copyright (c) 2010-2012 cocos2d-x.org
|
||||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||||
Copyright (c) 2021 Bytedance Inc.
|
Copyright (c) 2021-2022 Bytedance Inc.
|
||||||
|
|
||||||
https://adxeproject.github.io/
|
https://adxeproject.github.io/
|
||||||
|
|
||||||
|
@ -44,54 +44,43 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
// The root path of resources, the character encoding is UTF-8.
|
// The root path of resources, the character encoding is UTF-8.
|
||||||
// UTF-8 is the only encoding supported by adxe API by default.
|
// UTF-8 is the only encoding supported by adxe API by default.
|
||||||
static std::wstring s_workingPath;
|
static std::wstring s_workingDir;
|
||||||
static std::string s_exePath;
|
static std::wstring s_exeDir;
|
||||||
|
|
||||||
// D:\aaa\bbb\ccc\ddd\abc.txt --> D:/aaa/bbb/ccc/ddd/abc.txt
|
// D:\aaa\bbb\ccc\ddd\abc.txt --> D:/aaa/bbb/ccc/ddd/abc.txt
|
||||||
static std::string convertPathFormatToUnixStyle(std::string_view path)
|
static std::string convertPathFormatToUnixStyle(const std::string_view& path)
|
||||||
{
|
{
|
||||||
std::string ret{path};
|
std::string ret{path};
|
||||||
int len = ret.length();
|
int len = ret.length();
|
||||||
for (int i = 0; i < len; ++i)
|
std::replace(ret.begin(), ret.end(), '\\', '/');
|
||||||
{
|
|
||||||
if (ret[i] == '\\')
|
|
||||||
{
|
|
||||||
ret[i] = '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string convertPathFormatToWinStyle(std::string_view path)
|
static std::string convertPathFormatToWinStyle(const std::string_view& path)
|
||||||
{
|
{
|
||||||
std::string ret{path};
|
std::string ret{path};
|
||||||
int len = ret.length();
|
int len = ret.length();
|
||||||
for (int i = 0; i < len; ++i)
|
std::replace(ret.begin(), ret.end(), '/', '\\');
|
||||||
{
|
|
||||||
if (ret[i] == '/')
|
|
||||||
{
|
|
||||||
ret[i] = '\\';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _checkWorkingPath()
|
static void _checkWorkingPath()
|
||||||
{
|
{
|
||||||
if (s_workingPath.empty())
|
if (s_workingDir.empty())
|
||||||
{
|
{
|
||||||
WCHAR utf16Path[CC_MAX_PATH] = {0};
|
WCHAR utf16Path[CC_MAX_PATH] = {0};
|
||||||
int nNum = GetCurrentDirectoryW(CC_MAX_PATH - 2, utf16Path);
|
size_t nNum = GetCurrentDirectoryW(CC_MAX_PATH - 2, utf16Path);
|
||||||
|
|
||||||
s_workingPath.reserve(nNum + 1);
|
s_workingDir.reserve(nNum + 1);
|
||||||
s_workingPath.assign(utf16Path, nNum);
|
s_workingDir.assign(utf16Path, nNum);
|
||||||
s_workingPath.push_back('\\');
|
s_workingDir.push_back('/');
|
||||||
|
std::replace(s_workingDir.begin(), s_workingDir.end(), L'\\', L'/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _checkExePath()
|
static void _checkExePath()
|
||||||
{
|
{
|
||||||
if (s_exePath.empty())
|
if (s_exeDir.empty())
|
||||||
{
|
{
|
||||||
WCHAR utf16Path[CC_MAX_PATH] = {0};
|
WCHAR utf16Path[CC_MAX_PATH] = {0};
|
||||||
GetModuleFileNameW(NULL, utf16Path, CC_MAX_PATH - 1);
|
GetModuleFileNameW(NULL, utf16Path, CC_MAX_PATH - 1);
|
||||||
|
@ -100,9 +89,8 @@ static void _checkExePath()
|
||||||
// We need only directory part without exe
|
// We need only directory part without exe
|
||||||
WCHAR* pUtf16DirEnd = wcsrchr(pUtf16ExePath, L'\\');
|
WCHAR* pUtf16DirEnd = wcsrchr(pUtf16ExePath, L'\\');
|
||||||
|
|
||||||
auto utf8ExeDir = ntcvt::wcbs2a<std::string>(pUtf16ExePath, pUtf16DirEnd - pUtf16ExePath + 1);
|
s_exeDir.assign(pUtf16ExePath, static_cast<size_t>(pUtf16DirEnd - pUtf16ExePath + 1));
|
||||||
|
std::replace(s_exeDir.begin(), s_exeDir.end(), '\\', '/');
|
||||||
s_exePath = convertPathFormatToUnixStyle(utf8ExeDir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,18 +113,20 @@ FileUtilsWin32::FileUtilsWin32() {}
|
||||||
|
|
||||||
bool FileUtilsWin32::init()
|
bool FileUtilsWin32::init()
|
||||||
{
|
{
|
||||||
DECLARE_GUARD;
|
|
||||||
|
|
||||||
_checkWorkingPath();
|
_checkWorkingPath();
|
||||||
_defaultResRootPath = ntcvt::from_chars(s_workingPath);
|
_checkExePath();
|
||||||
_defaultResRootPathUtf16 = s_workingPath;
|
|
||||||
|
bool startedFromSelfLocation = s_workingDir == s_exeDir;
|
||||||
|
if (!startedFromSelfLocation)
|
||||||
|
_defaultResRootPath = ntcvt::from_chars(s_workingDir);
|
||||||
|
else
|
||||||
|
_defaultResRootPath.assign(ntcvt::from_chars(s_exeDir)).append(AX_PC_RESOURCES_DIR, AX_PC_RESOURCES_DIR_LEN);
|
||||||
|
|
||||||
bool bRet = FileUtils::init();
|
bool bRet = FileUtils::init();
|
||||||
|
|
||||||
_checkExePath();
|
// make sure any path relative to exe dir can be found when app working directory location not exe path
|
||||||
|
if (!startedFromSelfLocation)
|
||||||
if (_defaultResRootPath != s_exePath)
|
addSearchPath(ntcvt::from_chars(s_exeDir));
|
||||||
addSearchPath(s_exePath);
|
|
||||||
|
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
@ -149,21 +139,7 @@ bool FileUtilsWin32::isDirectoryExistInternal(std::string_view dirPath) const
|
||||||
|
|
||||||
bool FileUtilsWin32::isFileExistInternal(std::string_view strFilePath) const
|
bool FileUtilsWin32::isFileExistInternal(std::string_view strFilePath) const
|
||||||
{
|
{
|
||||||
DECLARE_GUARD;
|
DWORD attr = GetFileAttributesW(ntcvt::from_chars(strFilePath).c_str());
|
||||||
if (strFilePath.empty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring strPathUtf16;
|
|
||||||
if (!isAbsolutePath(strFilePath))
|
|
||||||
{ // Not absolute path, add the default root path at the beginning.
|
|
||||||
strPathUtf16.insert(0, _defaultResRootPathUtf16);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strPathUtf16 = ntcvt::from_chars(strFilePath);
|
|
||||||
|
|
||||||
DWORD attr = GetFileAttributesW(strPathUtf16.c_str());
|
|
||||||
return (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY));
|
return (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
Copyright (c) 2010-2012 cocos2d-x.org
|
Copyright (c) 2010-2012 cocos2d-x.org
|
||||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||||
|
Copyright (c) 2020 C4games Ltd.
|
||||||
|
Copyright (c) 2021-2022 Bytedance Inc.
|
||||||
|
|
||||||
https://adxeproject.github.io/
|
https://adxeproject.github.io/
|
||||||
|
|
||||||
|
@ -133,9 +135,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual std::string getFullPathForFilenameWithinDirectory(std::string_view directory,
|
virtual std::string getFullPathForFilenameWithinDirectory(std::string_view directory,
|
||||||
std::string_view filename) const override;
|
std::string_view filename) const override;
|
||||||
|
|
||||||
private:
|
|
||||||
std::wstring_view _defaultResRootPathUtf16;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -342,6 +342,11 @@ if (_AX_USE_PREBUILT) # support windows only
|
||||||
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
||||||
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll.lib)
|
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll.lib)
|
||||||
target_include_directories(${ADXE_CORE_LIB} PUBLIC ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/include)
|
target_include_directories(${ADXE_CORE_LIB} PUBLIC ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/include)
|
||||||
|
add_custom_command(TARGET ${cocos_target} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll"
|
||||||
|
$<TARGET_FILE_DIR:${APP_NAME}>
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
|
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -357,6 +357,11 @@ if (_AX_USE_PREBUILT) # support windows only
|
||||||
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
||||||
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll.lib)
|
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll.lib)
|
||||||
target_include_directories(${ADXE_CORE_LIB} PUBLIC ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/include)
|
target_include_directories(${ADXE_CORE_LIB} PUBLIC ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/include)
|
||||||
|
add_custom_command(TARGET ${cocos_target} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/${ARCH_ALIAS}/WebView2Loader.dll"
|
||||||
|
$<TARGET_FILE_DIR:${APP_NAME}>
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
|
target_link_libraries(${ADXE_CORE_LIB} ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in New Issue