From d569571dfba3793fff4373ce442e1748680b5de1 Mon Sep 17 00:00:00 2001 From: leda Date: Mon, 21 Jan 2019 17:32:04 +0800 Subject: [PATCH] cmake improve, adapt to support multi config (#345) * cmake, adapt IMPORTED_LOCATION to support multi config * remove custom target property: CC_DEPEND_DLLS --- Box2D/CMakeLists.txt | 3 ++- bullet/CMakeLists.txt | 3 ++- chipmunk/CMakeLists.txt | 3 ++- cmake/CocosExternalConfig.cmake | 18 +----------------- curl/CMakeLists.txt | 10 +++++++--- lua/luajit/CMakeLists.txt | 10 +++++++--- openssl/CMakeLists.txt | 10 +++++++--- spidermonkey/CMakeLists.txt | 10 +++++++--- sqlite3/CMakeLists.txt | 10 +++++++--- uv/CMakeLists.txt | 10 +++++++--- websockets/CMakeLists.txt | 10 +++++++--- win32-specific/MP3Decoder/CMakeLists.txt | 6 +++--- win32-specific/OggDecoder/CMakeLists.txt | 14 +++++++------- win32-specific/OpenalSoft/CMakeLists.txt | 7 +++---- win32-specific/gles/CMakeLists.txt | 6 +++--- win32-specific/icon/CMakeLists.txt | 6 +++--- zlib/CMakeLists.txt | 10 +++++++--- 17 files changed, 82 insertions(+), 64 deletions(-) diff --git a/Box2D/CMakeLists.txt b/Box2D/CMakeLists.txt index 42d2e0f8d8..4b6ef0acc6 100644 --- a/Box2D/CMakeLists.txt +++ b/Box2D/CMakeLists.txt @@ -16,7 +16,8 @@ set_target_properties(${target_name} PROPERTIES if(WINDOWS) set_target_properties(${target_name} PROPERTIES # need use absolutely path - IMPORTED_LOCATION "${platform_spec_path}/lib${lib_name}.lib" + IMPORTED_LOCATION_DEBUG "${platform_spec_path}/debug/lib${lib_name}.lib" + IMPORTED_LOCATION_RELEASE "${platform_spec_path}/release/lib${lib_name}.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/bullet/CMakeLists.txt b/bullet/CMakeLists.txt index b430402273..fee13770f4 100644 --- a/bullet/CMakeLists.txt +++ b/bullet/CMakeLists.txt @@ -18,7 +18,8 @@ set_property(TARGET ${target_name} APPEND PROPERTY if(WINDOWS) set_target_properties(${target_name} PROPERTIES - IMPORTED_LOCATION "${platform_spec_path}/lib${lib_name}.lib" + IMPORTED_LOCATION_DEBUG "${platform_spec_path}/debug/lib${lib_name}.lib" + IMPORTED_LOCATION_RELEASE "${platform_spec_path}/release/lib${lib_name}.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/chipmunk/CMakeLists.txt b/chipmunk/CMakeLists.txt index b458301e40..020f2b60ac 100644 --- a/chipmunk/CMakeLists.txt +++ b/chipmunk/CMakeLists.txt @@ -14,7 +14,8 @@ set_target_properties(${target_name} PROPERTIES ) if(WINDOWS) set_target_properties(${target_name} PROPERTIES - IMPORTED_LOCATION "${platform_spec_path}/lib${lib_name}.lib" + IMPORTED_LOCATION_DEBUG "${platform_spec_path}/debug-lib/lib${lib_name}.lib" + IMPORTED_LOCATION_RELEASE "${platform_spec_path}/release-lib/lib${lib_name}.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/cmake/CocosExternalConfig.cmake b/cmake/CocosExternalConfig.cmake index 1e4307b446..d6510273f7 100644 --- a/cmake/CocosExternalConfig.cmake +++ b/cmake/CocosExternalConfig.cmake @@ -23,15 +23,6 @@ endif() endif() -# part libs existed debug and release both type -string(TOLOWER ${CMAKE_BUILD_TYPE} _type_folder) -# Visual Studio 2017 default build type include "Debug Release MinSizRel RelWithDebInfo" -if(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") - set(_type_folder "debug") -elseif(${CMAKE_BUILD_TYPE} STREQUAL "MinSizRel") - set(_type_folder "release") -endif() - # set platform specific path set(_path_prefix ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/) if(IOS) @@ -42,14 +33,7 @@ elseif(ANDROID) set(platform_spec_path android/${ANDROID_ABI}) elseif(WINDOWS) set(platform_name win32) - # win32/, win32/debug, win32/debug-lib - if(EXISTS ${_path_prefix}/win32/${_type_folder}-lib) - set(platform_spec_path win32/${_type_folder}-lib) - elseif(EXISTS ${_path_prefix}win32/${_type_folder}) - set(platform_spec_path win32/${_type_folder}) - else() - set(platform_spec_path win32) - endif() + set(platform_spec_path win32) elseif(MACOSX) set(platform_name mac) set(platform_spec_path mac) diff --git a/curl/CMakeLists.txt b/curl/CMakeLists.txt index 8f66f759dc..cb02b5a4f8 100644 --- a/curl/CMakeLists.txt +++ b/curl/CMakeLists.txt @@ -7,7 +7,11 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/${platform_name}" @@ -15,8 +19,8 @@ set_target_properties(${target_name} PROPERTIES if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/lib${lib_name}.dll" - IMPORTED_LOCATION "${platform_spec_path}/lib${lib_name}.lib" + IMPORTED_LOCATION "${platform_spec_path}/lib${lib_name}.dll" + IMPORTED_IMPLIB "${platform_spec_path}/lib${lib_name}.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/lua/luajit/CMakeLists.txt b/lua/luajit/CMakeLists.txt index 570d94e000..1037b9b626 100644 --- a/lua/luajit/CMakeLists.txt +++ b/lua/luajit/CMakeLists.txt @@ -6,15 +6,19 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/lua51.dll" - IMPORTED_LOCATION "${platform_spec_path}/lua51.lib" + IMPORTED_LOCATION "${platform_spec_path}/lua51.dll" + IMPORTED_IMPLIB "${platform_spec_path}/lua51.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/openssl/CMakeLists.txt b/openssl/CMakeLists.txt index 8f1c8aad0a..326a9cdb75 100644 --- a/openssl/CMakeLists.txt +++ b/openssl/CMakeLists.txt @@ -10,15 +10,19 @@ include(../cmake/CocosExternalConfig.cmake) macro(set_openssl_sub_target sub_lib_name) set(sub_target_name ext_${sub_lib_name}) - add_library(${sub_target_name} STATIC IMPORTED GLOBAL) + if(WINDOWS) + add_library(${sub_target_name} SHARED IMPORTED GLOBAL) + else() + add_library(${sub_target_name} STATIC IMPORTED GLOBAL) + endif() set_target_properties(${sub_target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/${platform_name}" ) if(WINDOWS) set_target_properties(${sub_target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/lib${sub_lib_name}-1_1.dll" - IMPORTED_LOCATION "${platform_spec_path}/lib${sub_lib_name}.lib" + IMPORTED_LOCATION "${platform_spec_path}/lib${sub_lib_name}-1_1.dll" + IMPORTED_IMPLIB "${platform_spec_path}/lib${sub_lib_name}.lib" ) else() set_target_properties(${sub_target_name} PROPERTIES diff --git a/spidermonkey/CMakeLists.txt b/spidermonkey/CMakeLists.txt index bb2aa4dd5b..d1efda8f35 100644 --- a/spidermonkey/CMakeLists.txt +++ b/spidermonkey/CMakeLists.txt @@ -7,15 +7,19 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/${platform_name}" ) if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/mozjs-33.dll" - IMPORTED_LOCATION "${platform_spec_path}/mozjs-33.lib" + IMPORTED_LOCATION "${platform_spec_path}/mozjs-33.dll" + IMPORTED_IMPLIB "${platform_spec_path}/mozjs-33.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/sqlite3/CMakeLists.txt b/sqlite3/CMakeLists.txt index fb7a35dd6c..293760b0fc 100644 --- a/sqlite3/CMakeLists.txt +++ b/sqlite3/CMakeLists.txt @@ -7,14 +7,18 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${platform_name}/${lib_name}.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${platform_name}/${lib_name}.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${platform_name}/${lib_name}.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${platform_name}/${lib_name}.lib" ) endif() \ No newline at end of file diff --git a/uv/CMakeLists.txt b/uv/CMakeLists.txt index 8435db81f0..6caa2b6f40 100644 --- a/uv/CMakeLists.txt +++ b/uv/CMakeLists.txt @@ -7,15 +7,19 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/${lib_name}.dll" - IMPORTED_LOCATION "${platform_spec_path}/${lib_name}_a.lib" + IMPORTED_LOCATION "${platform_spec_path}/${lib_name}.dll" + IMPORTED_IMPLIB "${platform_spec_path}/${lib_name}_a.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/websockets/CMakeLists.txt b/websockets/CMakeLists.txt index e4558e3fd2..142a9f3202 100644 --- a/websockets/CMakeLists.txt +++ b/websockets/CMakeLists.txt @@ -7,7 +7,11 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/${platform_name}" @@ -22,8 +26,8 @@ set_property(TARGET ${target_name} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "ext if(WINDOWS) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${platform_spec_path}/${lib_name}.dll" - IMPORTED_LOCATION "${platform_spec_path}/${lib_name}.lib" + IMPORTED_LOCATION "${platform_spec_path}/${lib_name}.dll" + IMPORTED_IMPLIB "${platform_spec_path}/${lib_name}.lib" ) else() set_target_properties(${target_name} PROPERTIES diff --git a/win32-specific/MP3Decoder/CMakeLists.txt b/win32-specific/MP3Decoder/CMakeLists.txt index a6af2eb187..f7f797e783 100644 --- a/win32-specific/MP3Decoder/CMakeLists.txt +++ b/win32-specific/MP3Decoder/CMakeLists.txt @@ -7,13 +7,13 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +add_library(${target_name} SHARED IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include ) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libmpg123.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libmpg123.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libmpg123.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libmpg123.lib" ) diff --git a/win32-specific/OggDecoder/CMakeLists.txt b/win32-specific/OggDecoder/CMakeLists.txt index 1dac41b034..412aed7185 100644 --- a/win32-specific/OggDecoder/CMakeLists.txt +++ b/win32-specific/OggDecoder/CMakeLists.txt @@ -7,28 +7,28 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +add_library(${target_name} SHARED IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include ) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libogg.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libogg.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libogg.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libogg.lib" ) # internal link depend set_property(TARGET ${target_name} APPEND PROPERTY - INTERFACE_LINK_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbis.lib" + INTERFACE_LINK_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbis.lib" ) set_property(TARGET ${target_name} APPEND PROPERTY - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbis.dll" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbis.dll" ) set_property(TARGET ${target_name} APPEND PROPERTY - INTERFACE_LINK_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbisfile.lib" + INTERFACE_LINK_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbisfile.lib" ) set_property(TARGET ${target_name} APPEND PROPERTY - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbisfile.dll" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libvorbisfile.dll" ) diff --git a/win32-specific/OpenalSoft/CMakeLists.txt b/win32-specific/OpenalSoft/CMakeLists.txt index 8fd44f23f2..c7929b5fd3 100644 --- a/win32-specific/OpenalSoft/CMakeLists.txt +++ b/win32-specific/OpenalSoft/CMakeLists.txt @@ -7,14 +7,13 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +add_library(${target_name} SHARED IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# todo set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/OpenAL32.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/OpenAL32.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/OpenAL32.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/OpenAL32.lib" ) diff --git a/win32-specific/gles/CMakeLists.txt b/win32-specific/gles/CMakeLists.txt index 0aba69180d..d10f23cfc5 100644 --- a/win32-specific/gles/CMakeLists.txt +++ b/win32-specific/gles/CMakeLists.txt @@ -7,13 +7,13 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +add_library(${target_name} SHARED IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include/OGLES ) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/glew32.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/glew32.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/glew32.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/glew32.lib" ) diff --git a/win32-specific/icon/CMakeLists.txt b/win32-specific/icon/CMakeLists.txt index 7af30c14f8..43d4cfeb64 100644 --- a/win32-specific/icon/CMakeLists.txt +++ b/win32-specific/icon/CMakeLists.txt @@ -7,13 +7,13 @@ project(${lib_name}) include(../../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +add_library(${target_name} SHARED IMPORTED GLOBAL) set_target_properties(${target_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include ) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/iconv.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libiconv.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/iconv.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/libiconv.lib" ) diff --git a/zlib/CMakeLists.txt b/zlib/CMakeLists.txt index 98951b8b98..e46c9f7d27 100644 --- a/zlib/CMakeLists.txt +++ b/zlib/CMakeLists.txt @@ -7,7 +7,11 @@ project(${lib_name}) include(../cmake/CocosExternalConfig.cmake) -add_library(${target_name} STATIC IMPORTED GLOBAL) +if(WINDOWS) + add_library(${target_name} SHARED IMPORTED GLOBAL) +else() + add_library(${target_name} STATIC IMPORTED GLOBAL) +endif() if(MACOSX OR ANDROID) set_target_properties(${target_name} PROPERTIES @@ -21,8 +25,8 @@ elseif(WINDOWS) INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../win32-specific/zlib/include" ) set_target_properties(${target_name} PROPERTIES - CC_DEPEND_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/../win32-specific/zlib/prebuilt/zlib1.dll" - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../win32-specific/zlib/prebuilt/libzlib.lib" + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../win32-specific/zlib/prebuilt/zlib1.dll" + IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/../win32-specific/zlib/prebuilt/libzlib.lib" ) endif()