# cmake-lint: disable=R0912,R0915,C0103 # Supply include directories and compiler flags get_directory_property(INCLUDE_DIRS INCLUDE_DIRECTORIES) set(CMAKE_REQUIRED_FLAGS "-c -fPIC") add_custom_target( check-header COMMAND ${CMAKE_COMMAND} -E remove -f CMakeFiles/CMakeError.log COMMAND ${CMAKE_COMMAND} . -DOGS_CHECK_HEADER_COMPILATION=ON COMMAND ${CMAKE_COMMAND} . -DOGS_CHECK_HEADER_COMPILATION=OFF || true COMMAND if [ -f CMakeFiles/CMakeError.log ]\; then cat CMakeFiles/CMakeError.log\; return 1\; else return 0\; fi\; WORKING_DIRECTOY ${PROJECT_BINARY_DIR} COMMENT "Checking header files" USES_TERMINAL ) # Checks header for standalone compilation function(_check_header_compilation target) # cmake-lint: disable=R0915 if(NOT TARGET ${target}) return() endif() get_target_property(SOURCE_FILES ${target} SOURCES) get_target_property(SOURCE_DIR ${target} SOURCE_DIR) get_directory_property(DEFS DIRECTORY ${SOURCE_DIR} COMPILE_DEFINITIONS) foreach(def ${DEFS}) if(${def} MATCHES ".*[0-9]\\(.*") continue() endif() list(APPEND DEFS_CLEANED "-D${def}") endforeach() get_target_property(INCLUDE_DIRS ${target} INCLUDE_DIRECTORIES) get_target_property( INTERFACE_INCLUDE_DIRS ${target} INTERFACE_INCLUDE_DIRECTORIES ) if(INTERFACE_INCLUDE_DIRS) list(APPEND INCLUDE_DIRS ${INTERFACE_INCLUDE_DIRS}) endif() get_target_property(LINK_LIBS ${target} LINK_LIBRARIES) # Transitive dependencies are not resolved foreach(lib ${LINK_LIBS} spdlog Boost::boost Eigen3::Eigen nlohmann_json::nlohmann_json range-v3 ) # Ignore non-existing targets or interface libs if(NOT TARGET ${lib}) continue() endif() get_target_property(LIB_TYPE ${lib} TYPE) if(LIB_TYPE STREQUAL "INTERFACE_LIBRARY") get_target_property( TARGET_INCLUDE_DIRS ${lib} INTERFACE_INCLUDE_DIRECTORIES ) else() get_target_property(TARGET_INCLUDE_DIRS ${lib} INCLUDE_DIRECTORIES) endif() if(TARGET_INCLUDE_DIRS) if("${TARGET_INCLUDE_DIRS}" MATCHES ".*]*)") list(APPEND INCLUDE_DIRS ${CMAKE_MATCH_1}) else() list(APPEND INCLUDE_DIRS ${TARGET_INCLUDE_DIRS}) endif() endif() endforeach() list(REMOVE_DUPLICATES INCLUDE_DIRS) string(REPLACE "${PROJECT_SOURCE_DIR}/" "" DIRECTORY ${SOURCE_DIR}) message(STATUS "Checking header compilation for ${DIRECTORY} ...") include(CheckCXXSourceCompiles) # cmake-lint: disable=C0103 set(CMAKE_REQUIRED_INCLUDES ${INCLUDE_DIRS} ${SOURCE_DIR}) # HACK, maybe add Gui Widgets Xml XmlPatterns as well if(OGS_BUILD_GUI) set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ) endif() get_target_property(_target_defs ${target} COMPILE_DEFINITIONS) foreach(def ${_target_defs}) # strip generator expressions if(${def} MATCHES "\\$<.*") continue() endif() if(${def} MATCHES ".*[0-9]\\(.*") continue() endif() list(APPEND DEFS_CLEANED "-D${def}") endforeach() set(CMAKE_REQUIRED_DEFINITIONS ${DEFS_CLEANED}) foreach(file ${SOURCE_FILES}) if(NOT "${file}" MATCHES ".*\\.h") # Check only header files continue() endif() if("${file}" MATCHES ".*-impl\\.h") # Ignore *-impl.h files continue() endif() if("${file}" MATCHES ".*Dialog\\.h") # Ignore Qt Dialog files continue() endif() if("${file}" MATCHES ".*Widget\\.h") # Ignore Qt Widget files continue() endif() if("${file}" MATCHES ".*Window\\.h") # Ignore Qt Window files continue() endif() if("${file}" MATCHES "ui_.*\\.h") # Ignore Qt-generated ui files continue() endif() if("${file}" MATCHES "MeshItem|ModelTreeItem") # These files have transitive vtk includes, see below. message(STATUS "Ignoring ${file} due to (transitive) vtk include.") continue() endif() file(READ "${file}" file_contents LIMIT 8000) # Ignore files including vtk. There is no easy way to get all required # VTK include directories with the vtk 9 module system. if("${file_contents}" MATCHES "#include