2015-07-19 12:03:39 +00:00
|
|
|
# Some functions for use with colobot-lint
|
|
|
|
|
2015-07-19 16:11:12 +00:00
|
|
|
##
|
|
|
|
# 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)
|
2015-07-19 12:03:39 +00:00
|
|
|
set(all_fake_header_src_files "")
|
|
|
|
|
|
|
|
set(fake_headers_src_dir ${colobot_BINARY_DIR}/fake_header_sources)
|
|
|
|
file(MAKE_DIRECTORY ${fake_headers_src_dir})
|
|
|
|
|
2015-07-19 16:11:12 +00:00
|
|
|
file(GLOB_RECURSE all_header_files RELATIVE ${colobot_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
|
2015-07-19 12:03:39 +00:00
|
|
|
|
2015-08-11 19:01:02 +00:00
|
|
|
if(all_header_files)
|
|
|
|
foreach(header_file ${all_header_files})
|
|
|
|
string(REGEX REPLACE "\\.h$" ".cpp" fake_header_src_file "${fake_headers_src_dir}/${header_file}")
|
2015-07-19 12:03:39 +00:00
|
|
|
|
2015-08-11 19:01:02 +00:00
|
|
|
get_filename_component(fake_header_src_dir ${fake_header_src_file} PATH)
|
|
|
|
file(MAKE_DIRECTORY ${fake_header_src_dir})
|
2015-07-19 12:03:39 +00:00
|
|
|
|
2015-08-11 19:01:02 +00:00
|
|
|
file(WRITE ${fake_header_src_file} "#include \"${header_file}\"\n\n")
|
2015-07-19 12:03:39 +00:00
|
|
|
|
2015-08-11 19:01:02 +00:00
|
|
|
list(APPEND all_fake_header_src_files ${fake_header_src_file})
|
|
|
|
endforeach()
|
2015-07-19 12:03:39 +00:00
|
|
|
|
2015-08-11 19:01:02 +00:00
|
|
|
include_directories(${colobot_SOURCE_DIR})
|
|
|
|
add_library(colobot_${subdir}_fake_header_srcs STATIC ${all_fake_header_src_files})
|
|
|
|
endif()
|
2015-07-19 16:11:12 +00:00
|
|
|
endmacro()
|