From 6ce0873d07a29ed4cce735a857f23ec48d3cbf01 Mon Sep 17 00:00:00 2001
From: Stephan Schulz <stephan.schulz-x2q@rub.de>
Date: Mon, 25 Jan 2021 11:39:02 +0100
Subject: [PATCH] propagate compile definitions outwards, for VTK and Voronoi

---
 CMakeLists.txt                    |  3 ---
 example/CMakeProject/build_all.sh |  1 +
 misc/preprocess.sh                |  2 +-
 src/CMakeLists.txt                | 14 ++++----------
 4 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff9acfb..c8bf7fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,8 +75,6 @@ if(CM_ALL_VTK_OUTPUT)
     if(NOT VTK_FOUND)
         message(FATAL_ERROR "VTK not found, help CMake to find it by setting VTK_LIBRARY and VTK_INCLUDE_DIR")
     endif()
-    # todo(s.schulz): this can be replaced from 3.12 onwards with add_compile_definitions
-    add_compile_definitions("ALL_VTK_OUTPUT")
 endif(CM_ALL_VTK_OUTPUT)
 
 if (CM_ALL_DEBUG)
@@ -97,7 +95,6 @@ endif(CM_ALL_USE_F08 AND MPI_Fortran_HAVE_F08_MODULE)
 if(CM_ALL_VORONOI)
     message(STATUS "compiling voro++ version in contrib/voro++")
     add_subdirectory(contrib/voro++)
-    add_compile_definitions("ALL_VORONOI_ACTIVE")
 endif()
 
 set(STB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contrib/stb)
diff --git a/example/CMakeProject/build_all.sh b/example/CMakeProject/build_all.sh
index 1acd12f..d212482 100755
--- a/example/CMakeProject/build_all.sh
+++ b/example/CMakeProject/build_all.sh
@@ -38,6 +38,7 @@ build_all () {
 	cmake --install "$ALL_BUILD_DIR"
 	if [[ $ALL_INSTALL_DIR != $ALL_PACKAGE ]]
 	then
+		rm -rf "$ALL_PACKAGE"
 		mv "$ALL_INSTALL_DIR" "$ALL_PACKAGE"
 	fi
 }
diff --git a/misc/preprocess.sh b/misc/preprocess.sh
index 1fa92ad..7864756 100755
--- a/misc/preprocess.sh
+++ b/misc/preprocess.sh
@@ -50,7 +50,7 @@ do
 	DEFINES="$DEFINES -D$d"
 done
 
-gcc -E -fdirectives-only $DEFINES -o ALL.ii ALL.hpp
+cpp -undef -fdirectives-only $DEFINES -o ALL.ii ALL.hpp
 
 mkdir -p "${OUTFILE%/*}"
 cat ALL.ii | sed -e 's!// PPIGNORE <!#include <!' > "$OUTFILE"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ef58417..9d7cf93 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,9 +17,11 @@ add_library (ALL ALL.cpp ALL_fortran.cpp ${ALL_HEADER_FILES})
 if(CM_ALL_VTK_OUTPUT)
     target_include_directories(ALL PUBLIC ${VTK_INCLUDE_DIRS})
     target_link_libraries(ALL PUBLIC ${VTK_LIBRARIES})
+    target_compile_definitions(ALL PUBLIC ALL_VTK_OUTPUT)
 endif(CM_ALL_VTK_OUTPUT)
 if(CM_ALL_VORONOI)
     target_link_libraries(ALL PUBLIC voro)
+    target_compile_definitions(ALL PUBLIC ALL_VORONOI_ACTIVE)
 endif(CM_ALL_VORONOI)
 
 target_include_directories(ALL PUBLIC ${MPI_CXX_INCLUDE_PATH})
@@ -40,16 +42,8 @@ install(TARGETS ALL
     ARCHIVE DESTINATION lib
     INCLUDES DESTINATION include)
 
-get_property(_glob_comp_def DIRECTORY PROPERTY COMPILE_DEFINITIONS)
-add_custom_command(
-    TARGET ALL
-    PRE_BUILD
-    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../misc/preprocess.sh ${ALL_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../include/ALL.hpp ${_glob_comp_def}
-    )
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../include/ALL.hpp DESTINATION include)
-
-#install(FILES ${ALL_HEADER_FILES}
-#    DESTINATION include)
+install(FILES ${ALL_HEADER_FILES}
+    DESTINATION include)
 
 if (CM_ALL_FORTRAN)
     set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../modules)
-- 
GitLab