Skip to content
Snippets Groups Projects
Commit b3a125b0 authored by Dominic Kempf's avatar Dominic Kempf Committed by Markus Blatt
Browse files

Implements an analogon to autotools "make headercheck" and adds package found summaries

Exclusion from the headercheck can be achieved in a CMakeLists.txt
file via the following macros:

exclude_from_headercheck(list...)
exclude_dir_from_headercheck()
exclude_all_but_from_headercheck(list...)

When not excluded, all headers matching dune/*.hh or src/*.hh
will be checked.

Unlike with autotools, make headercheck can only be called on the
toplevel module directory and then run on all module headers. In
contrast to autotools, CMake will cache the results and rerun only
checks on changed headers.
parent 75f7336d
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,14 @@
find_package(Boost)
set(HAVE_DUNE_BOOST ${Boost_FOUND})
#add all boost realted flags to ALL_PKG_FLAGS, this must happen regardless of a target using add_dune_boost_flags
if(HAVE_DUNE_BOOST)
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-DENABLE_BOOST=1")
foreach(dir ${Boost_INCLUDE_DIRS})
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}")
endforeach()
endif()
function(add_dune_boost_flags _targets)
cmake_parse_arguments(DUNE_BOOST LINK_ALL_BOOST_LIBRARIES "" LIBRARIES ${ARGN})
if(Boost_FOUND)
......@@ -30,4 +38,4 @@ function(add_dune_boost_flags _targets)
"${_props} -DENABLE_BOOST=1")
endforeach(_target)
endif(Boost_FOUND)
endfunction(add_dune_boost_flags)
endfunction(add_dune_boost_flags)
\ No newline at end of file
......@@ -361,6 +361,11 @@ macro(dune_process_dependency_tree DEPENDS DVERSIONS SUGGESTS SVERSIONS)
endforeach(_lib ${${_mod}_LIBRARIES})
endif(${_mod}_LIBRARIES)
message(STATUS "Dependencies for ${_mod}: ${${_mod}_DEPENDENCIES}")
#update ALL_PKG_FLAGS
foreach(dir ${${_mod}_INCLUDE_DIRS})
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}")
endforeach()
endif(NOT ${_mod}_PROCESSED)
endforeach(_mod DEPENDENCIES)
endmacro(dune_process_dependency_tree)
......@@ -501,6 +506,10 @@ macro(dune_project)
"Installation directory for CMake modules. Default is \${CMAKE_INSTALL_DATAROOTDIR}/cmake/modules when not set explicitely")
set(DUNE_INSTALL_MODULEDIR ${CMAKE_INSTALL_DATAROOTDIR}/cmake/modules)
endif(NOT DUNE_INSTALL_MODULEDIR)
# set up make headercheck
include(Headercheck)
setup_headercheck()
endmacro(dune_project)
# create a new config.h file and overwrite the existing one
......@@ -561,6 +570,9 @@ endmacro(dune_regenerate_config_cmake)
# Namely it creates config.h and the cmake-config files,
# some install directives and exports the module.
macro(finalize_dune_project)
#configure all headerchecks
finalize_headercheck()
#create cmake-config files for build tree
configure_file(
${PROJECT_SOURCE_DIR}/${DUNE_MOD_NAME}-config.cmake.in
......@@ -627,6 +639,9 @@ macro(finalize_dune_project)
endif("${ARGC}" EQUAL "1")
test_dep()
include(FeatureSummary)
feature_summary(WHAT ALL)
endmacro(finalize_dune_project)
macro(target_link_dune_default_libraries _target)
......@@ -909,3 +924,16 @@ and a replacement string. ${REPLACE_UNPARSED_ARGUMENTS}")
replace_properties_for_one()
endif(_length EQUAL 0)
endfunction(replace_properties)
macro(add_dune_all_flags targets)
get_property(flags GLOBAL PROPERTY ALL_PKG_FLAGS)
set(FLAGSTR "")
foreach(flag ${flags})
set(FLAGSTR "${FLAGSTR}\ ${flag}")
endforeach()
foreach(target ${targets})
set_property(TARGET ${target}
APPEND_STRING
PROPERTY COMPILE_FLAGS ${FLAGSTR})
endforeach()
endmacro(add_dune_all_flags targets)
\ No newline at end of file
......@@ -82,3 +82,11 @@ endif(GMP_FOUND)
# set HAVE_GMP for config.h
set(HAVE_GMP GMP_FOUND)
#add all GMP related flags to ALL_PKG_FLAGS, this must happen regardless of a target using add_dune_gmp_flags
if(HAVE_GMP)
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-DENABLE_GMP=1")
foreach(dir ${GMP_INCLUDE_DIR})
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}")
endforeach()
endif()
\ No newline at end of file
......@@ -85,3 +85,10 @@ else(METIS_FOUND)
"Include directory: ${METIS_INCLUDE_DIRS}\n"
"Library directory: ${METIS_LIBRARIES}\n\n")
endif(METIS_FOUND)
#add all metis related flags to ALL_PKG_FLAGS, this must happen regardless of a target using add_dune_metis_flags
if(METIS_FOUND)
foreach(dir ${METIS_INCLUDE_DIRS})
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}")
endforeach()
endif()
\ No newline at end of file
......@@ -97,3 +97,10 @@ if(PARMETIS_FOUND)
"Include directory: ${PARMETIS_INCLUDE_DIRS}\n"
"Library directory: ${PARMETIS_LIBRARIES}\n\n")
endif(PARMETIS_FOUND)
#add all parmetis related flags to ALL_PKG_FLAGS, this must happen regardless of a target using add_dune_parmetis_flags
if(PARMETIS_FOUND)
foreach(dir ${PARMETIS_INCLUDE_DIRS})
set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}")
endforeach()
endif()
\ No newline at end of file
# 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 src_headers "src/*.hh")
file(GLOB_RECURSE dune_headers "dune/*.hh")
set_property(GLOBAL PROPERTY headercheck_list ${src_headers} ${dune_headers})
#define headercheck target
dune_common_script_dir(SCRIPT_DIR)
add_custom_target(headercheck ${CMAKE_COMMAND} -P ${SCRIPT_DIR}/FinalizeHeadercheck.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endmacro(setup_headercheck)
# these macros are used to exclude headers from make headercheck
# call this from a CMakeLists.txt file with a list of headers in that directory
macro(exclude_from_headercheck)
#make this robust to argument being passed with or without ""
string(REGEX REPLACE "[\ \n]+([^\ ])" ";\\1" list ${ARGV0})
set(list "${list};${ARGV}")
get_property(headerlist GLOBAL PROPERTY headercheck_list)
foreach(item ${list})
list(REMOVE_ITEM headerlist "${CMAKE_CURRENT_SOURCE_DIR}/${item}")
endforeach()
set_property(GLOBAL PROPERTY headercheck_list ${headerlist})
endmacro(exclude_from_headercheck)
macro(exclude_dir_from_headercheck)
file(GLOB list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.hh")
exclude_from_headercheck(${list})
endmacro(exclude_dir_from_headercheck)
macro(exclude_all_but_from_headercheck)
file(GLOB excllist RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.hh")
#make this robust to argument being passed with or without ""
string(REGEX REPLACE "[\ \n]+([^\ \n])" ";\\1" list ${ARGV0})
set(list "${list};${ARGV}")
foreach(item ${list})
list(REMOVE_ITEM excllist ${item})
endforeach()
exclude_from_headercheck(${excllist})
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(REGEX REPLACE "${PROJECT_SOURCE_DIR}/(.*)" "\\1" 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;}")
# 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})
endforeach(header ${headerlist})
endmacro(finalize_headercheck)
\ No newline at end of file
# 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!")
#message("Running make clean on headercheck targets...")
#this cleans the build directory from pollution through headerchecks but prevents caching... :/
#file(GLOB_RECURSE list "./CMakeFiles/headercheck_*/cmake_clean.cmake")
#foreach(item ${list})
# execute_process(COMMAND ${CMAKE_COMMAND} -P ${item})
#endforeach()
\ No newline at end of file
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