<div dir="ltr"><div><div><div><div><div><div><div>Dear Robert,<br><br></div></div>I can see that your solution to this is much cleaner and more failsafe, so I appreciate it.<br><br></div><div>I do have some technical remarks:<br></div><div>* exec_program is deprecated, you should use execute_process instead.<br></div><div>* the part in finalize, where you write the script looks much like you want to use the configure_file command with a template.<br><br></div>More importantly, I consider it bad style to:<br></div>* push it to master AND release branch without ever even letting somebody know.<br></div>* changing the name of the switch without consulting anybody.<br><br></div>Best,<br></div>Dominic<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 1, 2015 at 11:45 AM, Robert K <span dir="ltr"><<a href="mailto:robertk@posteo.org" target="_blank">robertk@posteo.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">New commit, appeared at Wed Jul 1 11:45:15 2015 +0200<br>
as part of the following ref changes:<br>
<br>
branch refs/heads/releases/2.4 updated from b3d8b8f -> 5704c3d<br>
<br>
Browsable version: <a href="http://cgit.dune-project.org/repositories/dune-common/commit/?id=15057f0af4f2379cdaeef9ed0ef80c26339950db" rel="noreferrer" target="_blank">http://cgit.dune-project.org/repositories/dune-common/commit/?id=15057f0af4f2379cdaeef9ed0ef80c26339950db</a><br>
<br>
======================================================================<br>
<br>
commit 15057f0af4f2379cdaeef9ed0ef80c26339950db<br>
Author: Robert K <<a href="mailto:robertk@posteo.org">robertk@posteo.org</a>><br>
Date: Wed Jul 1 10:54:24 2015 +0200<br>
<br>
[Cmake][feature] allow overloading of compiler flags on the command line via a compiler<br>
script. This feature is disabled by default and can be enabled by<br>
-DALLOW_CXXFLAGS_OVERWRITE=ON.<br>
<br>
cmake/modules/DuneMacros.cmake | 15 +++----<br>
cmake/modules/OverloadCompilerFlags.cmake | 69 +++++++++++++++++++++++++++++++<br>
2 files changed, 77 insertions(+), 7 deletions(-)<br>
create mode 100644 cmake/modules/OverloadCompilerFlags.cmake<br>
<br>
<br>
<br>
diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake<br>
index 39b7ff5..1372881 100644<br>
--- a/cmake/modules/DuneMacros.cmake<br>
+++ b/cmake/modules/DuneMacros.cmake<br>
@@ -80,6 +80,7 @@ enable_language(C) # Enable C to skip CXX bindings for some tests.<br>
<br>
include(FeatureSummary)<br>
include(DuneEnableAllPackages)<br>
+include(OverloadCompilerFlags)<br>
<br>
include(DuneSymlinkOrCopy)<br>
<br>
@@ -546,6 +547,9 @@ macro(dune_project)<br>
message(FATAL_ERROR "You need to specify an absolute path to your compiler instead of just the compiler name. cmake >= 3.0 fixes this issue.")<br>
endif()<br>
<br>
+ # check if CXX flag overloading has been enabled (see OverloadCompilerFlags.cmake)<br>
+ initialize_compiler_script()<br>
+<br>
# extract information from dune.module<br>
dune_module_information(${CMAKE_SOURCE_DIR})<br>
set(ProjectName "${DUNE_MOD_NAME}")<br>
@@ -677,13 +681,6 @@ macro(dune_project)<br>
include(Headercheck)<br>
setup_headercheck()<br>
<br>
- # check whether the user wants to append compile flags upon calling make<br>
- if(ALLOW_EXTRA_CXXFLAGS AND (${CMAKE_GENERATOR} MATCHES ".*Unix Makefiles.*"))<br>
- file(WRITE ${CMAKE_BINARY_DIR}/compiler.sh<br>
- "#!/bin/bash\nif [ -n \"$VERBOSE\" ] ; then\necho 1>&2 \"Additional flags: \$EXTRA_CXXFLAGS\"\nfi\nexec ${CMAKE_CXX_COMPILER} \"\$@\" \$EXTRA_CXXFLAGS")<br>
- exec_program(chmod ARGS "+x ${CMAKE_BINARY_DIR}/compiler.sh")<br>
- set(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/compiler.sh)<br>
- endif()<br>
endmacro(dune_project)<br>
<br>
# create a new config.h file and overwrite the existing one<br>
@@ -886,6 +883,10 @@ endif()<br>
include(CPack)<br>
<br>
feature_summary(WHAT ALL)<br>
+<br>
+ # check if CXX flag overloading has been enabled<br>
+ # and write compiler script (see OverloadCompilerFlags.cmake)<br>
+ finalize_compiler_script()<br>
endmacro(finalize_dune_project)<br>
<br>
macro(target_link_dune_default_libraries _target)<br>
diff --git a/cmake/modules/OverloadCompilerFlags.cmake b/cmake/modules/OverloadCompilerFlags.cmake<br>
new file mode 100644<br>
index 0000000..c5783e8<br>
--- /dev/null<br>
+++ b/cmake/modules/OverloadCompilerFlags.cmake<br>
@@ -0,0 +1,69 @@<br>
+# check whether the user wants to overload compile flags upon calling make<br>
+#<br>
+# Provides the following macros:<br>
+#<br>
+# initialize_compiler_script() : needs to be called before further flags are added to CMAKE_CXX_FLAGS<br>
+# finalize_compiler_script() : needs to be called at the end of the cmake macros, e.g. in finalize_dune_project<br>
+#<br>
+# By default this feature is disabled. Use -DALLOW_CXXFLAGS_OVERWRITE=ON to activate.<br>
+# Then the following is possible:<br>
+#<br>
+# make CXXFLAGS="your flags" GRIDTYPE="grid type"<br>
+#<br>
+# Furthermore any CPP variable of the form -DVAR=VALUE can be overloaded on the command line.<br>
+#<br>
+# Note: If you don't know what this is or what it's good for, don't use it.<br>
+#<br>
+option(ALLOW_CXXFLAGS_OVERWRITE OFF)<br>
+<br>
+# check whether the user wants to append compile flags upon calling make<br>
+if(ALLOW_EXTRA_CXXFLAGS AND (${CMAKE_GENERATOR} MATCHES ".*Unix Makefiles.*"))<br>
+ message("ALLOW_EXTRA_CXXFLAGS is deprecated, please use -DALLOW_CXXFLAGS_OVERWRITE=ON")<br>
+ set(ALLOW_CXXFLAGS_OVERWRITE ON)<br>
+endif()<br>
+<br>
+# init compiler script and store CXX flags<br>
+macro(initialize_compiler_script)<br>
+ if(ALLOW_CXXFLAGS_OVERWRITE AND (${CMAKE_GENERATOR} MATCHES ".*Unix Makefiles.*"))<br>
+ find_program (BASH_PROGRAM bash)<br>
+ # set CXXFLAGS as environment variable<br>
+ set( DEFAULT_CXXFLAGS ${CMAKE_CXX_FLAGS})<br>
+ set( CMAKE_CXX_FLAGS "" )<br>
+ set( DEFAULT_CXX_COMPILER ${CMAKE_CXX_COMPILER} )<br>
+ set( COMPILER_SCRIPT_FILE "#!${BASH_PROGRAM}\nexec ${CMAKE_CXX_COMPILER} \"\$@\"")<br>
+ file(WRITE ${CMAKE_BINARY_DIR}/compiler.sh "${COMPILER_SCRIPT_FILE}" )<br>
+ exec_program(chmod ARGS "+x ${CMAKE_BINARY_DIR}/compiler.sh")<br>
+ set(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/compiler.sh)<br>
+ endif()<br>
+endmacro()<br>
+<br>
+# finalize compiler script and write it<br>
+macro(finalize_compiler_script)<br>
+ if(ALLOW_CXXFLAGS_OVERWRITE AND (${CMAKE_GENERATOR} MATCHES ".*Unix Makefiles.*"))<br>
+ find_program (GREP_PROGRAM grep)<br>
+ find_program (SED_PROGRAM sed)<br>
+ find_program (CUT_PROGRAM cut)<br>
+ find_program (ENV_PROGRAM env)<br>
+ find_program (ECHO_PROGRAM echo)<br>
+ set( COMPILER_SCRIPT_FILE "#!${BASH_PROGRAM}\nSED=${SED_PROGRAM}\nGREP=${GREP_PROGRAM}")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nCUT=${CUT_PROGRAM}\nENV=${ENV_PROGRAM}\nECHO=${ECHO_PROGRAM}")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n# store flags\nFLAGS=\"\$@\"")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nMAKE_EXECUTABLE_NEW=0\n")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nif [ \"\$CXXFLAGS\" == \"\" ]; then\n # default CXX flags\n CXXFLAGS=\"${DEFAULT_CXXFLAGS}\"\nfi\n")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nGRIDS=\nCONFIG_H=${CMAKE_BINARY_DIR}/config.h")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nif [ \"\$GRIDTYPE\" != \"\" ]; then")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n GRIDS=`\$GREP \"defined USED_[A-Z_]*_GRIDTYPE\" \$CONFIG_H | \$SED 's/\\(.*defined USED\\_\\)\\(.*\\)\\(\\_GRIDTYPE*\\)/\\2/g'`\nfi\n")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nOLDFLAGS=\$FLAGS\nFLAGS=")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nfor FLAG in \$OLDFLAGS; do")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n NEWFLAG=\$FLAG\n VARNAME=`\$ECHO \$FLAG | \$GREP \"\\-D\" | \$SED 's/-D//g'`")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n for GRID in \$GRIDS; do\n if [ \"\$VARNAME\" == \"\$GRID\" ]; then\n NEWFLAG=\"-D\$GRIDTYPE\"\n break\n fi\n done")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n VARNAME=`\$ECHO \$VARNAME | \$GREP \"=\" | \$CUT -d \"=\" -f 1`")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n if [ \"\$VARNAME\" != \"\" ]; then\n VAR=`\$ENV | \$GREP \$VARNAME`\n if [ \"\$VAR\" != \"\" ]; then")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n # add variable from environment to flags list\n NEWFLAG=\"-D\$VARNAME=\${!VARNAME}\"\n fi\n fi")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n FLAGS=\"\$FLAGS \$NEWFLAG\"\ndone")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\n\$ECHO \"${DEFAULT_CXX_COMPILER} \$CXXFLAGS \$FLAGS\"")<br>
+ set( COMPILER_SCRIPT_FILE "${COMPILER_SCRIPT_FILE}\nexec ${DEFAULT_CXX_COMPILER} \$CXXFLAGS \$FLAGS")<br>
+ file(WRITE ${CMAKE_BINARY_DIR}/compiler.sh "${COMPILER_SCRIPT_FILE}" )<br>
+ exec_program(chmod ARGS "+x ${CMAKE_BINARY_DIR}/compiler.sh")<br>
+ endif()<br>
+endmacro()<br>
<br>
_______________________________________________<br>
Dune-Commit mailing list<br>
<a href="mailto:Dune-Commit@dune-project.org">Dune-Commit@dune-project.org</a><br>
<a href="http://lists.dune-project.org/mailman/listinfo/dune-commit" rel="noreferrer" target="_blank">http://lists.dune-project.org/mailman/listinfo/dune-commit</a><br>
</blockquote></div><br></div>