Skip to content
Snippets Groups Projects
Commit 1a9e7684 authored by Dominic Kempf's avatar Dominic Kempf
Browse files

[CMake] make the headercheck feature configurable

As proposed in FS1584, make headercheck is now disabled by
default in cmake. This fact and how to enable it is printed
upon "make headercheck".
parent fd912ce4
No related branches found
No related tags found
No related merge requests found
# sets up a global property with the names of all header files
# in the module and a global target depending on all checks
macro(setup_headercheck)
#glob for headers
file(GLOB_RECURSE all_headers "*.hh")
# strip hidden files
string(REGEX REPLACE "[^;]*/\\.[^;]*\\.hh;?" "" headers "${all_headers}")
set_property(GLOBAL PROPERTY headercheck_list ${headers})
if(ENABLE_HEADERCHECK)
#glob for headers
file(GLOB_RECURSE all_headers "*.hh")
# strip hidden files
string(REGEX REPLACE "[^;]*/\\.[^;]*\\.hh;?" "" headers "${all_headers}")
set_property(GLOBAL PROPERTY headercheck_list ${headers})
endif()
#define headercheck target
dune_common_script_dir(SCRIPT_DIR)
add_custom_target(headercheck ${CMAKE_COMMAND} -P ${SCRIPT_DIR}/FinalizeHeadercheck.cmake
add_custom_target(headercheck ${CMAKE_COMMAND} -P ${SCRIPT_DIR}/FinalizeHeadercheck.cmake -DENABLE_HEADERCHECK=${ENABLE_HEADERCHECK}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endmacro(setup_headercheck)
......@@ -44,29 +46,31 @@ endmacro(exclude_all_but_from_headercheck)
# configure all headerchecks
macro(finalize_headercheck)
get_property(headerlist GLOBAL PROPERTY headercheck_list)
foreach(header ${headerlist})
#do some name conversion
string(REGEX REPLACE ".*/([^/]*)" "\\1" simple ${header})
string(REPLACE ${PROJECT_SOURCE_DIR} "" rel ${header})
string(REGEX REPLACE "(.*)/[^/]*" "\\1" relpath ${rel})
string(REGEX REPLACE "/" "_" targname ${rel})
if(ENABLE_HEADERCHECK)
get_property(headerlist GLOBAL PROPERTY headercheck_list)
foreach(header ${headerlist})
#do some name conversion
string(REGEX REPLACE ".*/([^/]*)" "\\1" simple ${header})
string(REPLACE ${PROJECT_SOURCE_DIR} "" rel ${header})
string(REGEX REPLACE "(.*)/[^/]*" "\\1" relpath ${rel})
string(REGEX REPLACE "/" "_" targname ${rel})
#generate the headercheck .cc file
file(WRITE ${CMAKE_BINARY_DIR}/headercheck/${rel}.cc "#ifdef HAVE_CONFIG_H\n#include<config.h>\n#endif\n#include<${simple}>\n#include<${simple}>\nint main(){return 0;}")
#generate the headercheck .cc file
file(WRITE ${CMAKE_BINARY_DIR}/headercheck/${rel}.cc "#ifdef HAVE_CONFIG_H\n#include<config.h>\n#endif\n#include<${simple}>\n#include<${simple}>\nint main(){return 0;}")
# add target for the check of current header, this is implemented as a library
# to prevent CMake from automatically trying to link the target, functionality
# of macro try_compile() is unfortunately not availbale due to it not being scriptable.
add_library(headercheck_${targname} STATIC EXCLUDE_FROM_ALL
${CMAKE_BINARY_DIR}/headercheck/${rel}.cc)
add_dependencies(headercheck headercheck_${targname})
# add target for the check of current header, this is implemented as a library
# to prevent CMake from automatically trying to link the target, functionality
# of macro try_compile() is unfortunately not availbale due to it not being scriptable.
add_library(headercheck_${targname} STATIC EXCLUDE_FROM_ALL
${CMAKE_BINARY_DIR}/headercheck/${rel}.cc)
add_dependencies(headercheck headercheck_${targname})
#add PKG_ALL_FLAGS and the directory where the header is located
set_property(TARGET headercheck_${targname}
APPEND_STRING PROPERTY COMPILE_FLAGS "-DHEADERCHECK -I${PROJECT_SOURCE_DIR}${relpath} -I${CMAKE_BINARY_DIR}")
set_property(TARGET headercheck_${targname} PROPERTY ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/headercheck/${relpath}")
add_dune_all_flags(headercheck_${targname})
unset(headercheck_${targname}_LIB_DEPENDS CACHE)
endforeach(header ${headerlist})
#add PKG_ALL_FLAGS and the directory where the header is located
set_property(TARGET headercheck_${targname}
APPEND_STRING PROPERTY COMPILE_FLAGS "-DHEADERCHECK -I${PROJECT_SOURCE_DIR}${relpath} -I${CMAKE_BINARY_DIR}")
set_property(TARGET headercheck_${targname} PROPERTY ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/headercheck/${relpath}")
add_dune_all_flags(headercheck_${targname})
unset(headercheck_${targname}_LIB_DEPENDS CACHE)
endforeach(header ${headerlist})
endif()
endmacro(finalize_headercheck)
# this is script is called at the end of all header checks
message("Headerchecks finished! Rerun CMake if a new file has not been checked!")
if(ENABLE_HEADERCHECK)
message("Headerchecks finished! Rerun CMake if a new file has not been checked!")
else()
message("The headercheck feature is currently disabled. You can enable it by adding ENABLE_HEADERCHECK=1 to your cmake flags.")
endif()
#message("Running make clean on headercheck targets...")
#this cleans the build directory from pollution through headerchecks but prevents caching... :/
......
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