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 # sets up a global property with the names of all header files
# in the module and a global target depending on all checks # in the module and a global target depending on all checks
macro(setup_headercheck) macro(setup_headercheck)
#glob for headers if(ENABLE_HEADERCHECK)
file(GLOB_RECURSE all_headers "*.hh") #glob for headers
# strip hidden files file(GLOB_RECURSE all_headers "*.hh")
string(REGEX REPLACE "[^;]*/\\.[^;]*\\.hh;?" "" headers "${all_headers}") # strip hidden files
set_property(GLOBAL PROPERTY headercheck_list ${headers}) string(REGEX REPLACE "[^;]*/\\.[^;]*\\.hh;?" "" headers "${all_headers}")
set_property(GLOBAL PROPERTY headercheck_list ${headers})
endif()
#define headercheck target #define headercheck target
dune_common_script_dir(SCRIPT_DIR) 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}) WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endmacro(setup_headercheck) endmacro(setup_headercheck)
...@@ -44,29 +46,31 @@ endmacro(exclude_all_but_from_headercheck) ...@@ -44,29 +46,31 @@ endmacro(exclude_all_but_from_headercheck)
# configure all headerchecks # configure all headerchecks
macro(finalize_headercheck) macro(finalize_headercheck)
get_property(headerlist GLOBAL PROPERTY headercheck_list) if(ENABLE_HEADERCHECK)
foreach(header ${headerlist}) get_property(headerlist GLOBAL PROPERTY headercheck_list)
#do some name conversion foreach(header ${headerlist})
string(REGEX REPLACE ".*/([^/]*)" "\\1" simple ${header}) #do some name conversion
string(REPLACE ${PROJECT_SOURCE_DIR} "" rel ${header}) string(REGEX REPLACE ".*/([^/]*)" "\\1" simple ${header})
string(REGEX REPLACE "(.*)/[^/]*" "\\1" relpath ${rel}) string(REPLACE ${PROJECT_SOURCE_DIR} "" rel ${header})
string(REGEX REPLACE "/" "_" targname ${rel}) string(REGEX REPLACE "(.*)/[^/]*" "\\1" relpath ${rel})
string(REGEX REPLACE "/" "_" targname ${rel})
#generate the headercheck .cc file #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;}") 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 # 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 # 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. # of macro try_compile() is unfortunately not availbale due to it not being scriptable.
add_library(headercheck_${targname} STATIC EXCLUDE_FROM_ALL add_library(headercheck_${targname} STATIC EXCLUDE_FROM_ALL
${CMAKE_BINARY_DIR}/headercheck/${rel}.cc) ${CMAKE_BINARY_DIR}/headercheck/${rel}.cc)
add_dependencies(headercheck headercheck_${targname}) add_dependencies(headercheck headercheck_${targname})
#add PKG_ALL_FLAGS and the directory where the header is located #add PKG_ALL_FLAGS and the directory where the header is located
set_property(TARGET headercheck_${targname} set_property(TARGET headercheck_${targname}
APPEND_STRING PROPERTY COMPILE_FLAGS "-DHEADERCHECK -I${PROJECT_SOURCE_DIR}${relpath} -I${CMAKE_BINARY_DIR}") 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}") set_property(TARGET headercheck_${targname} PROPERTY ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/headercheck/${relpath}")
add_dune_all_flags(headercheck_${targname}) add_dune_all_flags(headercheck_${targname})
unset(headercheck_${targname}_LIB_DEPENDS CACHE) unset(headercheck_${targname}_LIB_DEPENDS CACHE)
endforeach(header ${headerlist}) endforeach(header ${headerlist})
endif()
endmacro(finalize_headercheck) endmacro(finalize_headercheck)
# this is script is called at the end of all header checks # 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...") #message("Running make clean on headercheck targets...")
#this cleans the build directory from pollution through headerchecks but prevents caching... :/ #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