diff --git a/CMakeLists.txt b/CMakeLists.txt index 80bc1387..0726ad10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -446,3 +446,6 @@ file (COPY GNUmakefile DESTINATION ${PROJECT_BINARY_DIR} ) + +# provide compatibility with using this build in dunecontrol +include (DuneCompat) diff --git a/cmake/Modules/DuneCompat.cmake b/cmake/Modules/DuneCompat.cmake new file mode 100644 index 00000000..baec5ebf --- /dev/null +++ b/cmake/Modules/DuneCompat.cmake @@ -0,0 +1,23 @@ +# - Dunecontrol compatibility +# +# Enables this build to be a part of a dunecontrol chain. The +# DUNE_CHECK_MODULES macro greps the top-level Makefile for the +# presence of the abs_top_srcdir variable (!) and uses that as +# the include directory of a module. Also, the contents are not +# checked so if the variable is not present, it generates an +# invalid command line (-I without argument) which causes the +# autoconf probe to fail. This module patches our Makefile (!!) +# so the necessary string will be there; in itself this string +# has no use for us, it is solemnly to satisfy the M4 scripts. + +if (CMAKE_GENERATOR MATCHES "Unix Makefiles") + # we need an up-to-date, patched Makefile. this is always checked when + # the makefile is run, thus the need for a marker file to keep a + # timestamp to see when it was last patched (by us) + # amazingly, nothing depends on the generated Makefile, so this can be + # run whenever in the build without trigging a compile of e.g. config.h + add_custom_target (dune-compat ALL + COMMAND ${CMAKE_COMMAND} -DCMAKE_HOME_DIRECTORY=${CMAKE_HOME_DIRECTORY} -P ${PROJECT_SOURCE_DIR}/cmake/Scripts/DuneCompat2.cmake + COMMENT "Patching Makefile to be DUNE compatible" + ) +endif (CMAKE_GENERATOR MATCHES "Unix Makefiles") diff --git a/cmake/Scripts/DuneCompat2.cmake b/cmake/Scripts/DuneCompat2.cmake new file mode 100644 index 00000000..e6a83258 --- /dev/null +++ b/cmake/Scripts/DuneCompat2.cmake @@ -0,0 +1,18 @@ +# - Emulate a rule to patch the Makefile, adding a line to the source +# tree and write a marker file indicating it is done. + +set (base_dir ".") +set (marker_file "${base_dir}/CMakeFiles/marker") +set (makefile "${base_dir}/Makefile") + +# if the Makefile has changed, then update it and touch the marker so that +# the marker is newer and won't update the Makefile again +if ("${makefile}" IS_NEWER_THAN "${marker_file}") + file (APPEND "${makefile}" + "abs_top_srcdir = ${CMAKE_HOME_DIRECTORY}\n" + ) + execute_process (COMMAND + ${CMAKE_COMMAND} -E touch "${marker_file}" + ) +endif ("${makefile}" IS_NEWER_THAN "${marker_file}") +