From a0d1808b629b1f2c251a39f8a7dbb2f7043c681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kalinowski?= Date: Sat, 19 Jan 2019 00:57:54 +0100 Subject: [PATCH] CMake transitive compile dependency Moving to more target focusing code that provides better transitive scope --- client/CMakeLists.txt | 14 ++++++++++---- launcher/CMakeLists.txt | 11 +++++------ lib/CMakeLists.txt | 12 +++++++++--- server/CMakeLists.txt | 7 ++++--- test/CMakeLists.txt | 11 ++++++++--- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1b119a5dc..82d31d54a 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,7 +1,3 @@ -include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib) -include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_MIXER_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR}) -include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}) - set(client_SRCS StdInc.cpp ../CCallback.cpp @@ -181,6 +177,16 @@ target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${SDL2_MIXER_LIBRARY} ${SDL2_TTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${FFMPEG_EXTRA_LINKING_OPTIONS} ${SYSTEM_LIBS} ) + +target_include_directories(vcmi + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${SDL2_INCLUDE_DIR} + PRIVATE ${SDL2_TTF_INCLUDE_DIR} + PRIVATE ${SDL2_MIXER_INCLUDE_DIR} + PRIVATE ${SDL2_IMAGE_INCLUDE_DIR} + PRIVATE ${FFMPEG_INCLUDE_DIRS} +) + vcmi_set_output_dir(vcmiclient "") set_target_properties(vcmiclient PROPERTIES ${PCH_PROPERTIES}) diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 828370a7c..250e0ac6c 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1,8 +1,3 @@ -# Detailed information about CMake compatibility available on Qt website -# https://doc.qt.io/qt-5/cmake-manual.html -include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${ZLIB_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) - set(launcher_modmanager_SRCS modManager/cdownloadmanager_moc.cpp modManager/cmodlist.cpp @@ -104,7 +99,11 @@ if(APPLE) endif() target_link_libraries(vcmilauncher vcmi Qt5::Widgets Qt5::Network) - +target_include_directories(vcmilauncher + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${Qt5Widgets_INCLUDE_DIRS} + PRIVATE ${Qt5Network_INCLUDE_DIRS} +) vcmi_set_output_dir(vcmilauncher "") # temporary(?) disabled - generation of PCH takes too much time since cotire is trying to collect all Qt headers diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b250cc810..4c3457746 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,6 +1,3 @@ -include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/lib) -include_directories(${Boost_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) - set(lib_SRCS StdInc.cpp ${CMAKE_BINARY_DIR}/Version.cpp @@ -358,6 +355,15 @@ add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS}) set_target_properties(vcmi PROPERTIES COMPILE_DEFINITIONS "VCMI_DLL=1") target_link_libraries(vcmi ${MINIZIP_LIBRARIES} ${Boost_LIBRARIES} ${SDL2_LIBRARY} ${ZLIB_LIBRARIES} ${SYSTEM_LIBS}) +target_include_directories(vcmi + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_HOME_DIRECTORY} + PUBLIC ${CMAKE_HOME_DIRECTORY}/include + PUBLIC ${Boost_INCLUDE_DIRS} + PUBLIC ${ZLIB_INCLUDE_DIR} + PRIVATE ${SDL2_INCLUDE_DIR} +) + if(WIN32) set_target_properties(vcmi PROPERTIES diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 1fc8eb4f0..6fc33d33e 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,6 +1,3 @@ -include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib) -include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR}) - set(server_SRCS StdInc.cpp @@ -29,6 +26,10 @@ add_executable(vcmiserver ${server_SRCS} ${server_HEADERS}) target_link_libraries(vcmiserver vcmi ${Boost_LIBRARIES} ${SYSTEM_LIBS}) +target_include_directories(vcmiserver + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + if(WIN32) set_target_properties(vcmiserver PROPERTIES diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 87d5d8237..7fb62b2be 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,9 +9,6 @@ if(EXISTS ${googleTest_Dir}) else() message(FATAL_ERROR "No googletest src dir found!") endif() -include_directories(${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include) -include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/test) -include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR}) set(test_SRCS StdInc.cpp @@ -114,6 +111,14 @@ add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL) add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS} ${GTestSrc}/src/gtest-all.cc ${GMockSrc}/src/gmock-all.cc) target_link_libraries(vcmitest vcmi ${RT_LIB} ${DL_LIB}) +target_include_directories( + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${GTestSrc} + PRIVATE ${GTestSrc}/include + PRIVATE ${GMockSrc} + PRIVATE ${GMockSrc}/include +) + if(FALSE AND NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0") # Running tests one by one using ctest not recommended due to vcmi having # slow global initialization.