Skip to content
Snippets Groups Projects
Commit 9532e3d8 authored by Lars Bilke's avatar Lars Bilke
Browse files

[CMake] Header standalone compilation check working.

parent 054320ec
No related branches found
No related tags found
No related merge requests found
...@@ -41,5 +41,3 @@ endif() ...@@ -41,5 +41,3 @@ endif()
if(OGS_USE_PCH) if(OGS_USE_PCH)
cotire(BaseLib) cotire(BaseLib)
endif() endif()
check_header_compilation()
...@@ -296,5 +296,7 @@ endif() # OGS_BUILD_TESTS ...@@ -296,5 +296,7 @@ endif() # OGS_BUILD_TESTS
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/BaseLib/BuildInfo.cpp.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/BaseLib/BuildInfo.cpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/BaseLib/BuildInfo.cpp" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/BaseLib/BuildInfo.cpp" @ONLY)
check_header_compilation()
include(scripts/cmake/MarkVariablesAdvanced.cmake) include(scripts/cmake/MarkVariablesAdvanced.cmake)
unset(PRE_INSTALL_RUN CACHE) unset(PRE_INSTALL_RUN CACHE)
...@@ -34,3 +34,5 @@ endif() ...@@ -34,3 +34,5 @@ endif()
include(${PROJECT_SOURCE_DIR}/scripts/cmake/packaging/InstallXmlSchemaFiles.cmake) include(${PROJECT_SOURCE_DIR}/scripts/cmake/packaging/InstallXmlSchemaFiles.cmake)
InstallXmlSchemaFiles("IO/XmlIO/*.xsd") InstallXmlSchemaFiles("IO/XmlIO/*.xsd")
#check_header_compilation(GeoLib)
# Supply include directories and compiler flags # Supply include directories and compiler flags
get_directory_property(INCLUDE_DIRS INCLUDE_DIRECTORIES) get_directory_property(INCLUDE_DIRS INCLUDE_DIRECTORIES)
set(CMAKE_REQUIRED_INCLUDES ${INCLUDE_DIRS})
set(CMAKE_REQUIRED_FLAGS "-std=gnu++14") set(CMAKE_REQUIRED_FLAGS "-std=gnu++14")
set(CMAKE_REQUIRED_QUIET TRUE) set(CMAKE_REQUIRED_QUIET TRUE)
# Checks header for standalone compilation # Checks header for standalone compilation
function(check_header_compilation) function(_check_header_compilation TARGET)
if(NOT OGS_CHECK_HEADER_COMPILATION)
return() get_target_property(SOURCE_FILES ${TARGET} SOURCES)
endif() get_target_property(SOURCE_DIR ${TARGET} SOURCE_DIR)
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" DIRECTORY ${CMAKE_CURRENT_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(LINK_LIBS ${TARGET} LINK_LIBRARIES)
foreach(LIB ${LINK_LIBS})
if(NOT TARGET ${LIB}) # Ignore non-existing targets
continue()
endif()
get_target_property(TARGET_INCLUDE_DIRS ${LIB} INCLUDE_DIRECTORIES)
if(TARGET_INCLUDE_DIRS)
list(APPEND INCLUDE_DIRS ${TARGET_INCLUDE_DIRS})
endif()
endforeach()
list(REMOVE_DUPLICATES INCLUDE_DIRS)
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" DIRECTORY ${SOURCE_DIR})
message(STATUS "Checking header compilation for ${DIRECTORY} ...") message(STATUS "Checking header compilation for ${DIRECTORY} ...")
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB_RECURSE FILES *.h) set(CMAKE_REQUIRED_INCLUDES ${INCLUDE_DIRS} ${SOURCE_DIR})
foreach(FILE ${FILES}) set(CMAKE_REQUIRED_DEFINITIONS ${DEFS_CLEANED})
# Ignore *-impl.h files
if("${FILE}" MATCHES ".*-impl.h") 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() continue()
endif() endif()
check_cxx_source_compiles( check_cxx_source_compiles(
" "
#include \"${FILE}\" #include \"${FILE}\"
...@@ -26,10 +53,33 @@ function(check_header_compilation) ...@@ -26,10 +53,33 @@ function(check_header_compilation)
" "
COMPILES COMPILES
) )
if(NOT COMPILES) if(NOT COMPILES)
set(HEADER_COMPILE_ERROR TRUE CACHE INTERNAL "")
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" FILE_SHORT ${FILE}) string(REPLACE "${PROJECT_SOURCE_DIR}/" "" FILE_SHORT ${FILE})
message(STATUS " Compilation failed for ${FILE_SHORT}") message(STATUS " Compilation failed for ${FILE_SHORT}")
endif() endif()
unset(COMPILES CACHE) unset(COMPILES CACHE)
endforeach() endforeach()
endfunction() endfunction()
function(check_header_compilation)
if(NOT OGS_CHECK_HEADER_COMPILATION)
return()
endif()
set(HEADER_COMPILE_ERROR FALSE CACHE INTERNAL "")
_check_header_compilation(BaseLib)
_check_header_compilation(GeoLib)
_check_header_compilation(MaterialLib)
_check_header_compilation(MathLib)
_check_header_compilation(MeshGeoToolsLib)
_check_header_compilation(MeshLib)
_check_header_compilation(NumLib)
_check_header_compilation(ProcessLib)
if(HEADER_COMPILE_ERROR)
message(STATUS "... header compilation check failed, see CMakeFiles/CMakeError.log for details!")
endif()
endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment