diff --git a/CMakeLists.txt b/CMakeLists.txt index 512d1e916b..2e92c43ba0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,13 +5,16 @@ project (Cocos2dxSamples) set(Cocos2dxSamples_VERSION_MAJOR 3) set(Cocos2dxSamples_VERSION_MINOR 0) -add_definitions(-DLINUX) +include(build/BuildHelpers.CMakeLists.txt) -# debug -message( "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" ) -if ( "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG" ) - add_definitions(-D_DEBUG) -endif() +set(CMAKE_BUILE_TYPE DEBUG) +set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") +set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) + +set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99") +set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") + +add_definitions(-DLINUX) # architecture if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) @@ -20,9 +23,6 @@ else() set(ARCH_DIR "32-bit") endif() -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99") - include_directories( cocos/2d cocos/2d/platform @@ -73,8 +73,6 @@ add_subdirectory(cocos/math/kazmath) # chipmunk library set(BUILD_STATIC 1) - -# chipmunk library add_subdirectory(external/chipmunk/src) # unzip library @@ -86,12 +84,9 @@ add_subdirectory(external/tinyxml2) # cocos base library add_subdirectory(cocos/base) -# cocos physics sources -#add_subdirectory(cocos/physics) - # cocos 2d library add_subdirectory(cocos/2d) -# sample HelloCpp -add_subdirectory(samples/Cpp/HelloCpp) +# build samples +add_subdirectory(samples) diff --git a/build/BuildHelpers.CMakeLists.txt b/build/BuildHelpers.CMakeLists.txt new file mode 100644 index 0000000000..c60446bd30 --- /dev/null +++ b/build/BuildHelpers.CMakeLists.txt @@ -0,0 +1,37 @@ + +# Copies files for the given game into the target res directory +# GAME_NAME name of the game +# REL_DIR to which directory these files are relative +# SRC_FILES which files from the REL_DIR to copy (GLOB) +macro(COPY_RES_FILES GAME_NAME GAME_RES_TARGET REL_DIR SRC_FILES DST) + file( GLOB_RECURSE RES_FILES RELATIVE ${REL_DIR} ${SRC_FILES} ) + + set(ALL_FILES) + foreach(SRC_FILE ${RES_FILES}) + add_custom_command( + OUTPUT "${DST}/${SRC_FILE}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${REL_DIR}/${SRC_FILE}" + "${DST}/${SRC_FILE}" + COMMENT "Copy ${SRC_FILE}" + ) + list(APPEND ALL_FILES "${DST}/${SRC_FILE}" ) + endforeach() + # create target for copying these files + add_custom_target( ${GAME_RES_TARGET} DEPENDS ${ALL_FILES} ) +endmacro() + +# convenience to call above with current directory and everything in "res" +macro(COPY_RES GAME_NAME CRG_PATTERN DST) + # a target for all addition asserts (will be done in default compile, but if you target the executable + # it won't be done -- good for testing) + add_custom_target( ${GAME_NAME}_ASSETS ALL ) + + COPY_RES_FILES( ${GAME_NAME} ${GAME_NAME}_CORE_RES + ${CMAKE_CURRENT_SOURCE_DIR} + "${CRG_PATTERN}" + ${DST} + ) + add_dependencies( ${GAME_NAME}_ASSETS ${GAME_NAME}_CORE_RES ) +endmacro() + diff --git a/cocos/2d/platform/linux/CCFileUtilsLinux.cpp b/cocos/2d/platform/linux/CCFileUtilsLinux.cpp index 227c59b0ba..dc3fb5b513 100644 --- a/cocos/2d/platform/linux/CCFileUtilsLinux.cpp +++ b/cocos/2d/platform/linux/CCFileUtilsLinux.cpp @@ -49,7 +49,7 @@ bool FileUtilsLinux::init() fullpath[length] = '\0'; std::string appPath = fullpath; _defaultResRootPath = appPath.substr(0, appPath.find_last_of("/")); - _defaultResRootPath += "/../../../Resources/"; + _defaultResRootPath += "/Resources/"; // Set writable path to $XDG_CONFIG_HOME or ~/.config// if $XDG_CONFIG_HOME not exists. const char* xdg_config_path = getenv("XDG_CONFIG_HOME"); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt new file mode 100644 index 0000000000..d8f27098e1 --- /dev/null +++ b/samples/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_subdirectory(Cpp/HelloCpp) +add_subdirectory(Cpp/TestCpp) + diff --git a/samples/Cpp/HelloCpp/CMakeLists.txt b/samples/Cpp/HelloCpp/CMakeLists.txt index f22b681d8f..6ac2ed3548 100644 --- a/samples/Cpp/HelloCpp/CMakeLists.txt +++ b/samples/Cpp/HelloCpp/CMakeLists.txt @@ -12,3 +12,13 @@ add_executable(${SAMPLE_NAME} ) target_link_libraries(${SAMPLE_NAME} ${COCOS_LIBRARIES}) + +set(SAMPLE_BIN_DIR ${CMAKE_BINARY_DIR}/bin) + +SET_TARGET_PROPERTIES(${SAMPLE_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${SAMPLE_BIN_DIR}/HelloCpp") + +message(STATUS "Hello.........." ${CMAKE_BINARY_DIR}) + +COPY_RES( ${SAMPLE_NAME} "Resources/*" "${SAMPLE_BIN_DIR}/HelloCpp") +