From 3c7ede5859ab9babb099b160e9e817461bf623f6 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 18 Aug 2020 12:36:44 +0800 Subject: [PATCH] Make core lib can be build as dll, fix link issue for external --- CMakeLists.txt | 2 +- cocos/CMakeLists.txt | 30 ++++++++++--------- templates/cpp-template-default/CMakeLists.txt | 2 +- tests/cpp-empty-test/CMakeLists.txt | 2 +- tests/cpp-tests/CMakeLists.txt | 2 +- tests/fairygui-tests/CMakeLists.txt | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index facf2fa387..39d729a08a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ cmake_minimum_required(VERSION 3.6) -project(Cocos2d-x) +project(EGNX) # set default minimum deployment target # if(XCODE) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 092bd48519..f8c81f5972 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -29,9 +29,11 @@ # build luacocos2d if BUILD_LUA_LIBS=ON # The version number -set(COCOS2D_X_VERSION 4.0) +set(EGNX_VERSION 1.0) -set(COCOS_CORE_LIB cocos2d) +if(NOT DEFINED EGNX_CORE_LIB) + set(EGNX_CORE_LIB cocos2d CACHE INTERNAL "The EGNX core lib name" ) +endif() project(cocos2d_libs) @@ -80,7 +82,7 @@ set(COCOS_SRC cocos2d.cpp list(APPEND COCOS_SRC ${COCOS_HEADER}) -add_library(cocos2d ${COCOS_SRC}) +add_library(${EGNX_CORE_LIB} ${COCOS_SRC}) # if (NOT APPLE) # set_source_files_properties("audio/src/AudioEngineImpl.mm" PROPERTIES LANGUAGE CXX) @@ -88,16 +90,16 @@ add_library(cocos2d ${COCOS_SRC}) # use external libs add_subdirectory(${COCOS2DX_ROOT_PATH}/external ${ENGINE_BINARY_PATH}/external) -target_link_libraries(cocos2d external) +target_link_libraries(${EGNX_CORE_LIB} external) # add base macro define and compile options -use_cocos2dx_compile_define(cocos2d) -use_cocos2dx_compile_options(cocos2d) +use_cocos2dx_compile_define(${EGNX_CORE_LIB}) +use_cocos2dx_compile_options(${EGNX_CORE_LIB}) # use all platform related system libs -use_cocos2dx_libs_depend(cocos2d) +use_cocos2dx_libs_depend(${EGNX_CORE_LIB}) -target_include_directories(cocos2d +target_include_directories(${EGNX_CORE_LIB} PUBLIC ${COCOS2DX_ROOT_PATH} PUBLIC ${COCOS2DX_ROOT_PATH}/external PUBLIC ${COCOS2DX_ROOT_PATH}/extensions @@ -110,11 +112,11 @@ target_include_directories(cocos2d INTERFACE ${COCOS2DX_ROOT_PATH}/cocos/platform/${PLATFORM_FOLDER} ) -set_target_properties(cocos2d +set_target_properties(${EGNX_CORE_LIB} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - VERSION "${COCOS2D_X_VERSION}" + VERSION "${EGNX_VERSION}" FOLDER "Internal" ) @@ -124,13 +126,13 @@ if(BUILD_LUA_LIBS) endif() if(XCODE OR VS) - cocos_mark_code_files("cocos2d") + cocos_mark_code_files("${EGNX_CORE_LIB}") endif() if(WINDOWS) # precompiled header. Compilation time speedup ~4x. - target_sources(cocos2d PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/precheader.cpp") - set_target_properties(cocos2d PROPERTIES COMPILE_FLAGS "/Yuprecheader.h /FIprecheader.h") + target_sources(${EGNX_CORE_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/precheader.cpp") + set_target_properties(${EGNX_CORE_LIB} PROPERTIES COMPILE_FLAGS "/Yuprecheader.h /FIprecheader.h") set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/precheader.cpp" PROPERTIES COMPILE_FLAGS "/Ycprecheader.h") # compile c as c++. needed for precompiled header set_source_files_properties(${COCOS_SPINE_SRC} base/ccFPSImages.c PROPERTIES LANGUAGE CXX) @@ -142,5 +144,5 @@ add_subdirectory(${COCOS2DX_ROOT_PATH}/extensions ${ENGINE_BINARY_PATH}/extensio #if(XCODE) # # Later versions of Xcode clang want to compile C++17 with aligned allocation turned on and this is only supported on iOS 11.0+ # # TODO: Only turn this off if ${CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET} < 11.0 -# target_compile_options(cocos2d PUBLIC $<$:-fno-aligned-allocation>) +# target_compile_options(${EGNX_CORE_LIB} PUBLIC $<$:-fno-aligned-allocation>) #endif() diff --git a/templates/cpp-template-default/CMakeLists.txt b/templates/cpp-template-default/CMakeLists.txt index 5e5ccf7670..3c4a78b805 100644 --- a/templates/cpp-template-default/CMakeLists.txt +++ b/templates/cpp-template-default/CMakeLists.txt @@ -131,7 +131,7 @@ else() config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() -target_link_libraries(${APP_NAME} cocos2d) +target_link_libraries(${APP_NAME} ${EGNX_CORE_LIB}) target_include_directories(${APP_NAME} PRIVATE Classes PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/ diff --git a/tests/cpp-empty-test/CMakeLists.txt b/tests/cpp-empty-test/CMakeLists.txt index c2dbe0c0d8..3f700bf733 100644 --- a/tests/cpp-empty-test/CMakeLists.txt +++ b/tests/cpp-empty-test/CMakeLists.txt @@ -127,7 +127,7 @@ else() config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() -target_link_libraries(${APP_NAME} cocos2d) +target_link_libraries(${APP_NAME} ${EGNX_CORE_LIB}) target_include_directories(${APP_NAME} PRIVATE Classes) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 1227493406..3557767061 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -392,7 +392,7 @@ else() config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() -target_link_libraries(${APP_NAME} cocos2d) +target_link_libraries(${APP_NAME} ${EGNX_CORE_LIB}) target_include_directories(${APP_NAME} PRIVATE Classes diff --git a/tests/fairygui-tests/CMakeLists.txt b/tests/fairygui-tests/CMakeLists.txt index 200c220264..47b48b373a 100644 --- a/tests/fairygui-tests/CMakeLists.txt +++ b/tests/fairygui-tests/CMakeLists.txt @@ -117,7 +117,7 @@ else() config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() -target_link_libraries(${APP_NAME} cocos2d) +target_link_libraries(${APP_NAME} ${EGNX_CORE_LIB}) target_include_directories(${APP_NAME} PRIVATE Classes)