From 88cb8f4516e26070fc7b4620e91f06ee7d7e799d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 9 May 2017 13:01:10 +0200 Subject: [PATCH] Improved CMake structure. --- CMakeLists.txt | 8 ++++++++ app/CMakeLists.txt | 3 ++- src/CMakeLists.txt | 12 ++++++++---- tests/CMakeLists.txt | 3 ++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efe8480..1070d7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,14 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +if (CMAKE_GENERATOR STREQUAL "Ninja" AND + ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. + # Rationale in https://github.com/ninja-build/ninja/issues/814 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") +endif() + add_subdirectory(src) add_subdirectory(app) if(PLASP_BUILD_TESTS) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 7682090..7907fe7 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -3,7 +3,7 @@ set(target plasp-app) file(GLOB core_sources "*.cpp") file(GLOB core_headers "*.h") -include_directories( +set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ) @@ -19,5 +19,6 @@ set(libraries ) add_executable(${target} ${sources}) +target_include_directories(${target} PRIVATE ${includes}) target_link_libraries(${target} ${libraries}) set_target_properties(${target} PROPERTIES OUTPUT_NAME plasp) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 209ea8b..2a46f71 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,11 +21,11 @@ file(GLOB input_headers "../include/plasp/input/*.h") file(GLOB output_sources "plasp/output/*.cpp") file(GLOB output_headers "../include/plasp/output/*.h") -include_directories( - ${Boost_INCLUDE_DIRS} -) +file(GLOB utils_sources "plasp/utils/*.cpp") +file(GLOB utils_headers "../include/plasp/utils/*.h") -include_directories( +set(includes + ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ) @@ -50,6 +50,9 @@ set(sources ${output_sources} ${output_headers} + + ${utils_sources} + ${utils_headers} ) set(libraries @@ -58,4 +61,5 @@ set(libraries ) add_library(${target} ${sources}) +target_include_directories(${target} PRIVATE ${includes}) target_link_libraries(${target} ${libraries}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dfaea46..df36400 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,7 @@ set(target tests) file(GLOB core_sources "*.cpp") -include_directories( +set(includes ${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/lib/catch/single_include @@ -14,6 +14,7 @@ set(libraries ) add_executable(${target} ${core_sources}) +target_include_directories(${target} PRIVATE ${includes}) target_link_libraries(${target} ${libraries}) add_custom_target(run-tests