From: TimePath Date: Sat, 19 Mar 2016 04:21:09 +0000 (+1100) Subject: CMake: behave nicely in multi-project build X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=136322429755bc8f72e45e82d8dea4641a4b4ba2;p=xonotic%2Fnetradiant.git CMake: behave nicely in multi-project build --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bed416a5..d5fb2d61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,9 +32,9 @@ if (GIT_VERSION) set(Q3MAP_VERSION "${Q3MAP_VERSION}-git-${GIT_VERSION}") endif () -configure_file("${CMAKE_SOURCE_DIR}/include/version.cpp.in" "${CMAKE_BINARY_DIR}/version.cpp") +configure_file("${PROJECT_SOURCE_DIR}/include/version.cpp.in" "${PROJECT_BINARY_DIR}/version.cpp") -add_library(version "${CMAKE_BINARY_DIR}/version.cpp") +add_library(version "${PROJECT_BINARY_DIR}/version.cpp") set_property(TARGET version PROPERTY POSITION_INDEPENDENT_CODE TRUE) set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message") @@ -183,13 +183,13 @@ set_target_properties(radiant PROPERTIES add_subdirectory(tools) -if (NOT (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)) +if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)) # Copy data files from sources to the build directory message(STATUS "Copying data files") - file(GLOB DATA_FILES "${CMAKE_SOURCE_DIR}/setup/data/tools/*") - file(COPY ${DATA_FILES} DESTINATION "${CMAKE_BINARY_DIR}") - file(GLOB DATA_FILES "${CMAKE_SOURCE_DIR}/docs/*") - file(COPY ${DATA_FILES} DESTINATION "${CMAKE_BINARY_DIR}/docs") + file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*") + file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}") + file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/docs/*") + file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}/docs") endif () #----------------------------------------------------------------------- @@ -199,7 +199,7 @@ endif () option(DOWNLOAD_GAMEPACKS "Download game packs" ON) add_custom_target(game_packs COMMAND ${CMAKE_COMMAND} -E make_directory games - COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/install-gamepacks.sh" "${CMAKE_BINARY_DIR}" + COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}" COMMENT "Downloading game packs" ) add_custom_command(OUTPUT games diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 7ef65337..e14be811 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -1,7 +1,7 @@ -include_directories("${CMAKE_SOURCE_DIR}/libs") -include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/libs") +include_directories("${PROJECT_SOURCE_DIR}/include") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/plugins") add_custom_target(plugins) macro(radiant_plugin name) diff --git a/include/version.cpp.in b/include/version.cpp.in index d16aa348..21283980 100644 --- a/include/version.cpp.in +++ b/include/version.cpp.in @@ -1,4 +1,4 @@ -#include "@CMAKE_SOURCE_DIR@/include/version.h" +#include "@PROJECT_SOURCE_DIR@/include/version.h" namespace radiant { std::string version() diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index d4636270..19ed8fa9 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE 1) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/include") add_subdirectory(cmdlib) add_subdirectory(container) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index b5f2a7af..3660a68a 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,7 +1,7 @@ -include_directories("${CMAKE_SOURCE_DIR}/libs") -include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/libs") +include_directories("${PROJECT_SOURCE_DIR}/include") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/modules") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/modules") add_custom_target(modules) macro(radiant_plugin name) diff --git a/radiant/CMakeLists.txt b/radiant/CMakeLists.txt index ab40b2a0..aabaef72 100644 --- a/radiant/CMakeLists.txt +++ b/radiant/CMakeLists.txt @@ -1,9 +1,9 @@ -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") find_package(OpenGL REQUIRED) -include_directories("${CMAKE_SOURCE_DIR}/libs") -include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/libs") +include_directories("${PROJECT_SOURCE_DIR}/include") string(SUBSTRING ${CMAKE_SHARED_MODULE_SUFFIX} 1 -1 _clibext) add_definitions(-DCMAKE_SHARED_MODULE_SUFFIX="${_clibext}") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a3fee086..29ce9cdc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,18 +1,18 @@ # Todo split further and actually compile the tools -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") macro(radiant_tool name) add_executable(${name} ${ARGN}) if(NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL RADIANT_EXECUTABLE)) add_custom_command(TARGET ${name} POST_BUILD - COMMAND ln -f -s "$" "${CMAKE_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}" + COMMAND ln -f -s "$" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}" VERBATIM ) endif() endmacro() -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.c.in" "${CMAKE_BINARY_DIR}/version.c") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.c.in" "${PROJECT_BINARY_DIR}/version.c") include_directories("${CMAKE_CURRENT_SOURCE_DIR}") add_subdirectory(quake3) add_subdirectory(quake2) diff --git a/tools/quake2/CMakeLists.txt b/tools/quake2/CMakeLists.txt index 82867102..6945ad27 100644 --- a/tools/quake2/CMakeLists.txt +++ b/tools/quake2/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories(common) -include_directories("${CMAKE_SOURCE_DIR}/libs") -include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${PROJECT_SOURCE_DIR}/libs") +include_directories("${PROJECT_SOURCE_DIR}/include") find_package(LibXml2 REQUIRED) include_directories(${LIBXML2_INCLUDE_DIR}) @@ -54,7 +54,7 @@ radiant_tool(q2map EXCLUDE_FROM_ALL q2map/trace.c q2map/tree.c q2map/writebsp.c - "${CMAKE_BINARY_DIR}/version.c" + "${PROJECT_BINARY_DIR}/version.c" ) target_link_libraries(q2map ${LIBXML2_LIBRARIES} @@ -92,7 +92,7 @@ radiant_tool(qdata3 EXCLUDE_FROM_ALL qdata/sprites.c qdata/tables.c qdata/video.c - "${CMAKE_BINARY_DIR}/version.c" + "${PROJECT_BINARY_DIR}/version.c" ) target_link_libraries(qdata3 @@ -166,7 +166,7 @@ radiant_tool(h2data EXCLUDE_FROM_ALL qdata_heretic2/tables.c qdata_heretic2/tmix.c qdata_heretic2/video.c - "${CMAKE_BINARY_DIR}/version.c" + "${PROJECT_BINARY_DIR}/version.c" ) target_include_directories(h2data BEFORE PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/qdata_heretic2/common" diff --git a/tools/quake3/CMakeLists.txt b/tools/quake3/CMakeLists.txt index dfd11469..48275e97 100644 --- a/tools/quake3/CMakeLists.txt +++ b/tools/quake3/CMakeLists.txt @@ -1,5 +1,5 @@ include_directories(common) -include_directories("${CMAKE_SOURCE_DIR}/libs") +include_directories("${PROJECT_SOURCE_DIR}/libs") find_package(GLIB REQUIRED) include_directories(${GLIB_INCLUDE_DIRS}) @@ -102,7 +102,7 @@ radiant_tool(q3map2 q3map2/vis.c q3map2/visflow.c q3map2/writebsp.c - "${CMAKE_BINARY_DIR}/version.c" + "${PROJECT_BINARY_DIR}/version.c" ) target_link_libraries(q3map2 @@ -155,7 +155,7 @@ radiant_tool(q3data q3data/q3data.h q3data/stripper.c q3data/video.c - "${CMAKE_BINARY_DIR}/version.c" + "${PROJECT_BINARY_DIR}/version.c" ) target_link_libraries(q3data