From 73536290b2319f7976afa3f5fbc7dd8b034975d0 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 19 Jul 2015 18:11:12 +0200 Subject: [PATCH] Fix for incorrect compile flags in colobot-lint --- CMakeLists.txt | 8 ++++++-- cmake/colobot-lint.cmake | 17 +++++++++-------- src/CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 5 +++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3f2a5be..aa93067d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,10 @@ option(GLEW_STATIC "Link statically with GLEW" OFF) # Sometimes helpful if there is a different version of gtest installed on system vs bundled option(FORCE_BUNDLED_GTEST "Force the use of bundled gtest" OFF) +# This is for use with colobot-lint tool +option(COLOBOT_LINT_BUILD "Generate some additional CMake targets for use with colobot-lint" OFF) + + # Default build type if not given is debug if(NOT DEFINED CMAKE_BUILD_TYPE) message(STATUS "Build type not specified - assuming debug") @@ -267,12 +271,12 @@ include("${colobot_SOURCE_DIR}/cmake/mxe.cmake") ## include("${colobot_SOURCE_DIR}/cmake/msys.cmake") - ## -# Additional settings for colobot-lint +# Additional functions for colobot-lint ## include("${colobot_SOURCE_DIR}/cmake/colobot-lint.cmake") + ## # MSVC specific settings ## diff --git a/cmake/colobot-lint.cmake b/cmake/colobot-lint.cmake index 7efa5cb3..ab2a293e 100644 --- a/cmake/colobot-lint.cmake +++ b/cmake/colobot-lint.cmake @@ -1,15 +1,17 @@ # Some functions for use with colobot-lint -option(COLOBOT_LINT_BUILD "Enable some additional functions for use with colobot-lint") - -if(COLOBOT_LINT_BUILD) - +## +# This adds a new target with generated fake source files that include single header files +# It is a workaround for how CMake and Clang handle header files in compilation database +# And we need that to check each header file in the project exactly once, the same as .cpp modules +## +macro(add_fake_header_sources subdir) set(all_fake_header_src_files "") set(fake_headers_src_dir ${colobot_BINARY_DIR}/fake_header_sources) file(MAKE_DIRECTORY ${fake_headers_src_dir}) - file(GLOB_RECURSE all_header_files RELATIVE ${colobot_SOURCE_DIR} src/*.h test/*.h) + file(GLOB_RECURSE all_header_files RELATIVE ${colobot_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h) foreach(header_file ${all_header_files}) string(REGEX REPLACE "\\.h$" ".cpp" fake_header_src_file "${fake_headers_src_dir}/${header_file}") @@ -23,6 +25,5 @@ if(COLOBOT_LINT_BUILD) endforeach() include_directories(${colobot_SOURCE_DIR}) - add_library(colobot_fake_header_srcs STATIC ${all_fake_header_src_files}) - -endif() + add_library(colobot_${subdir}_fake_header_srcs STATIC ${all_fake_header_src_files}) +endmacro() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4157c91f..9c929325 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -306,3 +306,7 @@ install(TARGETS colobot RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) if(NOT CBOT_STATIC) set_target_properties(colobot PROPERTIES INSTALL_RPATH ${COLOBOT_INSTALL_LIB_DIR}) endif() + +if(COLOBOT_LINT_BUILD) + add_fake_header_sources("src") +endif() \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6c67d91..4720a953 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,3 +11,8 @@ add_subdirectory(unit) # Test environments add_subdirectory(envs) + + +if(COLOBOT_LINT_BUILD) + add_fake_header_sources("test") +endif()