Fix linter
parent
17e38bf66c
commit
2143f21828
|
@ -4,17 +4,20 @@
|
|||
# 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
|
||||
# Note: This is modifying an existing target by adding fake source files.
|
||||
##
|
||||
macro(add_fake_header_sources subdir)
|
||||
macro(add_fake_header_sources subdir the_target)
|
||||
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} ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
|
||||
get_target_property(the_target_sources ${the_target} SOURCES)
|
||||
|
||||
if(all_header_files)
|
||||
foreach(header_file ${all_header_files})
|
||||
foreach(source_file IN LISTS the_target_sources)
|
||||
string(REGEX MATCH [[^.*\.h$]] is_header_file ${source_file})
|
||||
if(is_header_file)
|
||||
file(RELATIVE_PATH header_file ${colobot_SOURCE_DIR} ${colobot_SOURCE_DIR}/${subdir}/${source_file})
|
||||
string(REGEX REPLACE "\\.h$" ".cpp" fake_header_src_file "${fake_headers_src_dir}/${header_file}")
|
||||
|
||||
get_filename_component(fake_header_src_dir ${fake_header_src_file} PATH)
|
||||
|
@ -22,10 +25,8 @@ macro(add_fake_header_sources subdir)
|
|||
|
||||
file(WRITE ${fake_header_src_file} "#include \"${header_file}\"\n\n")
|
||||
|
||||
list(APPEND all_fake_header_src_files ${fake_header_src_file})
|
||||
endforeach()
|
||||
|
||||
add_library(colobot_${subdir}_fake_header_srcs STATIC ${all_fake_header_src_files})
|
||||
target_include_directories(colobot_${subdir}_fake_header_srcs PUBLIC ${colobot_SOURCE_DIR})
|
||||
endif()
|
||||
target_sources(${the_target} PRIVATE ${fake_header_src_file})
|
||||
target_include_directories(${the_target} PUBLIC ${colobot_SOURCE_DIR})
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
|
|
@ -164,3 +164,7 @@ target_sources(CBot PRIVATE
|
|||
)
|
||||
target_include_directories(CBot PUBLIC ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||
target_link_libraries(CBot PRIVATE Boost::headers)
|
||||
|
||||
if(COLOBOT_LINT_BUILD)
|
||||
add_fake_header_sources("src/CBot" CBot)
|
||||
endif()
|
||||
|
|
|
@ -593,5 +593,6 @@ endif()
|
|||
|
||||
# Linter-specific
|
||||
if(COLOBOT_LINT_BUILD)
|
||||
add_fake_header_sources("src")
|
||||
add_fake_header_sources("src" colobotbase)
|
||||
add_fake_header_sources("src" colobot)
|
||||
endif()
|
||||
|
|
|
@ -7,4 +7,3 @@ add_executable(convert_model
|
|||
convert_model.cpp)
|
||||
target_link_libraries(convert_model PRIVATE Boost::headers)
|
||||
target_include_directories(convert_model PRIVATE . ..)
|
||||
|
||||
|
|
|
@ -8,8 +8,3 @@ add_subdirectory(unit)
|
|||
|
||||
# CBot tests
|
||||
add_subdirectory(cbot)
|
||||
|
||||
|
||||
if(COLOBOT_LINT_BUILD)
|
||||
add_fake_header_sources("test")
|
||||
endif()
|
||||
|
|
|
@ -11,3 +11,8 @@ target_link_directories(CBot_compile_graph PRIVATE
|
|||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
target_link_libraries(CBot_compile_graph CBot)
|
||||
|
||||
if(COLOBOT_LINT_BUILD)
|
||||
add_fake_header_sources("test/cbot" CBot_console)
|
||||
add_fake_header_sources("test/cbot" CBot_compile_graph)
|
||||
endif()
|
||||
|
|
|
@ -48,3 +48,7 @@ gtest_discover_tests(colobot_ut
|
|||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
||||
target_compile_options(colobot_ut PRIVATE "-Wno-suggest-override")
|
||||
endif()
|
||||
|
||||
if(COLOBOT_LINT_BUILD)
|
||||
add_fake_header_sources("test/unit" colobot_ut)
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue