Fix linter

fix-squashed-planets
MrSimbax 2020-07-14 11:05:27 +02:00
parent 17e38bf66c
commit 2143f21828
7 changed files with 26 additions and 17 deletions

View File

@ -4,17 +4,20 @@
# This adds a new target with generated fake source files that include single header files # 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 # 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 # 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(all_fake_header_src_files "")
set(fake_headers_src_dir ${colobot_BINARY_DIR}/fake_header_sources) set(fake_headers_src_dir ${colobot_BINARY_DIR}/fake_header_sources)
file(MAKE_DIRECTORY ${fake_headers_src_dir}) 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(source_file IN LISTS the_target_sources)
foreach(header_file ${all_header_files}) 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}") 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) 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") file(WRITE ${fake_header_src_file} "#include \"${header_file}\"\n\n")
list(APPEND all_fake_header_src_files ${fake_header_src_file}) target_sources(${the_target} PRIVATE ${fake_header_src_file})
endforeach() target_include_directories(${the_target} PUBLIC ${colobot_SOURCE_DIR})
endif()
add_library(colobot_${subdir}_fake_header_srcs STATIC ${all_fake_header_src_files}) endforeach()
target_include_directories(colobot_${subdir}_fake_header_srcs PUBLIC ${colobot_SOURCE_DIR})
endif()
endmacro() endmacro()

View File

@ -164,3 +164,7 @@ target_sources(CBot PRIVATE
) )
target_include_directories(CBot PUBLIC ${CMAKE_CURRENT_LIST_DIR}/..) target_include_directories(CBot PUBLIC ${CMAKE_CURRENT_LIST_DIR}/..)
target_link_libraries(CBot PRIVATE Boost::headers) target_link_libraries(CBot PRIVATE Boost::headers)
if(COLOBOT_LINT_BUILD)
add_fake_header_sources("src/CBot" CBot)
endif()

View File

@ -593,5 +593,6 @@ endif()
# Linter-specific # Linter-specific
if(COLOBOT_LINT_BUILD) if(COLOBOT_LINT_BUILD)
add_fake_header_sources("src") add_fake_header_sources("src" colobotbase)
add_fake_header_sources("src" colobot)
endif() endif()

View File

@ -7,4 +7,3 @@ add_executable(convert_model
convert_model.cpp) convert_model.cpp)
target_link_libraries(convert_model PRIVATE Boost::headers) target_link_libraries(convert_model PRIVATE Boost::headers)
target_include_directories(convert_model PRIVATE . ..) target_include_directories(convert_model PRIVATE . ..)

View File

@ -8,8 +8,3 @@ add_subdirectory(unit)
# CBot tests # CBot tests
add_subdirectory(cbot) add_subdirectory(cbot)
if(COLOBOT_LINT_BUILD)
add_fake_header_sources("test")
endif()

View File

@ -11,3 +11,8 @@ target_link_directories(CBot_compile_graph PRIVATE
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
target_link_libraries(CBot_compile_graph CBot) 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()

View File

@ -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) 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") target_compile_options(colobot_ut PRIVATE "-Wno-suggest-override")
endif() endif()
if(COLOBOT_LINT_BUILD)
add_fake_header_sources("test/unit" colobot_ut)
endif()