From 77ab866090befee8ea96c3993293868773ce0850 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 11 Nov 2014 10:25:14 +0300 Subject: [PATCH] Move BuildHelpers.CMakeLists.txt to Modules/CocosBuildHelpers.cmake, this name is more standard for cmake include files, and in future this file can be installed to use by external applications. --- CMakeLists.txt | 2 +- cmake/BuildHelpers.CMakeLists.txt | 96 +------------------ cmake/Modules/CocosBuildHelpers.cmake | 95 ++++++++++++++++++ templates/cocos2dx_files.json | 3 +- templates/cpp-template-default/CMakeLists.txt | 3 +- .../frameworks/CMakeLists.txt | 3 +- 6 files changed, 104 insertions(+), 98 deletions(-) create mode 100644 cmake/Modules/CocosBuildHelpers.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e957c0ccb43..e6120f3a1ad2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,8 @@ project (Cocos2d-X) # The version number set(COCOS2D_X_VERSION 3.3.0-beta0) -include(cmake/BuildHelpers.CMakeLists.txt) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") +include(CocosBuildHelpers) message(${BUILDING_STRING}) diff --git a/cmake/BuildHelpers.CMakeLists.txt b/cmake/BuildHelpers.CMakeLists.txt index 081a5727ef82..f8dd21cff57b 100644 --- a/cmake/BuildHelpers.CMakeLists.txt +++ b/cmake/BuildHelpers.CMakeLists.txt @@ -1,94 +1,2 @@ -include(CMakeParseArguments) - -macro(pre_build TARGET_NAME) - add_custom_target( ${TARGET_NAME}_PRE_BUILD ALL ) - - add_custom_command( - TARGET ${TARGET_NAME}_PRE_BUILD - ${ARGN} - PRE_BUILD - COMMENT "${TARGET_NAME}_PRE_BUILD ..." - ) - - add_custom_target(${TARGET_NAME}_CORE_PRE_BUILD) - add_dependencies(${TARGET_NAME}_PRE_BUILD ${TARGET_NAME}_CORE_PRE_BUILD) - add_dependencies(${TARGET_NAME} ${TARGET_NAME}_PRE_BUILD) -endmacro() - -function(cocos_mark_resources) - set(oneValueArgs BASEDIR RESOURCEBASE) - set(multiValueArgs FILES) - cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - if(NOT opt_RESOURCEBASE) - set(opt_RESOURCEBASE Resources) - endif() - - get_filename_component(BASEDIR_ABS ${opt_BASEDIR} ABSOLUTE) - foreach(RES_FILE ${opt_FILES} ${opt_UNPARSED_ARGUMENTS}) - get_filename_component(RES_FILE_ABS ${RES_FILE} ABSOLUTE) - file(RELATIVE_PATH RES ${BASEDIR_ABS} ${RES_FILE_ABS}) - get_filename_component(RES_LOC ${RES} PATH) - set_source_files_properties(${RES_FILE} PROPERTIES - MACOSX_PACKAGE_LOCATION "${opt_RESOURCEBASE}/${RES_LOC}" - HEADER_FILE_ONLY 1 - ) - endforeach() -endfunction() - -#cmake has some strange defaults, this should help us a lot -#Please use them everywhere - -#WINDOWS = Windows Desktop -#WINRT = Windows RT -#WP8 = Windows Phone 8 -#ANDROID = ANDROID -#IOS = IOS -#MACOSX = MAC OSX - -if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - if(WINRT) - set(SYSTEM_STRING "Windows RT") - elseif(WP8) - set(SYSTEM_STRING "Windows Phone 8") - else() - set(WINDOWS TRUE) - set(SYSTEM_STRING "Windows Desktop") - endif() -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - if(ANDROID) - set(SYSTEM_STRING "Android") - else() - set(LINUX TRUE) - set(SYSTEM_STRING "Linux") - endif() -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - if(IOS) - set(SYSTEM_STRING "IOS") - else() - set(MACOSX TRUE) - set(APPLE TRUE) - set(SYSTEM_STRING "Mac OSX") - endif() -endif() - -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(COMPILER_STRING ${CMAKE_CXX_COMPILER_ID}) - set(CLANG TRUE) -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if(MINGW) - set(COMPILER_STRING "Mingw GCC") - else() - set(COMPILER_STRING "GCC") - endif() -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") - set(COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} C++") -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - set(COMPILER_STRING "Visual Studio C++") -endif() - -if(CMAKE_CROSSCOMPILING) - set(BUILDING_STRING "It appears you are cross compiling for ${SYSTEM_STRING} with ${COMPILER_STRING}") -else() - set(BUILDING_STRING "It appears you are builing natively for ${SYSTEM_STRING} with ${COMPILER_STRING}") -endif() +# For compatibility only, please use include(CocosBuildHelpers) in future projects +include(CocosBuildHelpers) diff --git a/cmake/Modules/CocosBuildHelpers.cmake b/cmake/Modules/CocosBuildHelpers.cmake new file mode 100644 index 000000000000..c90ed82c08f4 --- /dev/null +++ b/cmake/Modules/CocosBuildHelpers.cmake @@ -0,0 +1,95 @@ +include(CMakeParseArguments) + +macro(pre_build TARGET_NAME) + add_custom_target( ${TARGET_NAME}_PRE_BUILD ALL ) + + add_custom_command( + TARGET ${TARGET_NAME}_PRE_BUILD + ${ARGN} + PRE_BUILD + COMMENT "${TARGET_NAME}_PRE_BUILD ..." + ) + + add_custom_target(${TARGET_NAME}_CORE_PRE_BUILD) + add_dependencies(${TARGET_NAME}_PRE_BUILD ${TARGET_NAME}_CORE_PRE_BUILD) + add_dependencies(${TARGET_NAME} ${TARGET_NAME}_PRE_BUILD) +endmacro() + +function(cocos_mark_resources) + set(oneValueArgs BASEDIR RESOURCEBASE) + set(multiValueArgs FILES) + cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT opt_RESOURCEBASE) + set(opt_RESOURCEBASE Resources) + endif() + + get_filename_component(BASEDIR_ABS ${opt_BASEDIR} ABSOLUTE) + foreach(RES_FILE ${opt_FILES} ${opt_UNPARSED_ARGUMENTS}) + get_filename_component(RES_FILE_ABS ${RES_FILE} ABSOLUTE) + file(RELATIVE_PATH RES ${BASEDIR_ABS} ${RES_FILE_ABS}) + get_filename_component(RES_LOC ${RES} PATH) + set_source_files_properties(${RES_FILE} PROPERTIES + MACOSX_PACKAGE_LOCATION "${opt_RESOURCEBASE}/${RES_LOC}" + HEADER_FILE_ONLY 1 + ) + endforeach() +endfunction() + +#cmake has some strange defaults, this should help us a lot +#Please use them everywhere + +#WINDOWS = Windows Desktop +#WINRT = Windows RT +#WP8 = Windows Phone 8 +#ANDROID = Android +#IOS = iOS +#MACOSX = MacOS X +#LINUX = Linux + +if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + if(WINRT) + set(SYSTEM_STRING "Windows RT") + elseif(WP8) + set(SYSTEM_STRING "Windows Phone 8") + else() + set(WINDOWS TRUE) + set(SYSTEM_STRING "Windows Desktop") + endif() +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + if(ANDROID) + set(SYSTEM_STRING "Android") + else() + set(LINUX TRUE) + set(SYSTEM_STRING "Linux") + endif() +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + if(IOS) + set(SYSTEM_STRING "IOS") + else() + set(MACOSX TRUE) + set(APPLE TRUE) + set(SYSTEM_STRING "Mac OSX") + endif() +endif() + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(COMPILER_STRING ${CMAKE_CXX_COMPILER_ID}) + set(CLANG TRUE) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if(MINGW) + set(COMPILER_STRING "Mingw GCC") + else() + set(COMPILER_STRING "GCC") + endif() +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + set(COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} C++") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(COMPILER_STRING "Visual Studio C++") +endif() + +if(CMAKE_CROSSCOMPILING) + set(BUILDING_STRING "It appears you are cross compiling for ${SYSTEM_STRING} with ${COMPILER_STRING}") +else() + set(BUILDING_STRING "It appears you are builing natively for ${SYSTEM_STRING} with ${COMPILER_STRING}") +endif() diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index d0fe91b5959a..f090ae8ebb76 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -51,6 +51,7 @@ "build/wp8/wp8_precompiled_shaders.txt", "cmake/BuildHelpers.CMakeLists.txt", "cmake/Modules/CMakeParseArguments.cmake", + "cmake/Modules/CocosBuildHelpers.cmake", "cmake/Modules/FindChipmunk.cmake", "cmake/Modules/FindGLFW3.cmake", "cmake/Modules/FindPackageHandleStandardArgs.cmake", @@ -5556,4 +5557,4 @@ "tools/tolua/cocos2dx_ui.ini", "tools/tolua/genbindings.py" ] -} \ No newline at end of file +} diff --git a/templates/cpp-template-default/CMakeLists.txt b/templates/cpp-template-default/CMakeLists.txt index 2b810ea4ec5d..649a4b05fbf4 100644 --- a/templates/cpp-template-default/CMakeLists.txt +++ b/templates/cpp-template-default/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 2.8) set(APP_NAME MyGame) project (${APP_NAME}) -include(cocos2d/cmake/BuildHelpers.CMakeLists.txt) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cocos2d/cmake/Modules/") +include(CocosBuildHelpers) option(DEBUG_MODE "Debug or release?" ON) diff --git a/templates/lua-template-default/frameworks/CMakeLists.txt b/templates/lua-template-default/frameworks/CMakeLists.txt index f15068fef431..3b0871ecbff9 100644 --- a/templates/lua-template-default/frameworks/CMakeLists.txt +++ b/templates/lua-template-default/frameworks/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 2.8) set(APP_NAME HelloLua) project (${APP_NAME}) -include(cocos2d-x/cmake/BuildHelpers.CMakeLists.txt) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cocos2d/cmake/Modules/") +include(CocosBuildHelpers) option(DEBUG_MODE "Debug or release?" ON)