Skip to content
Snippets Groups Projects
Commit 10ece11c authored by Dominic Kempf's avatar Dominic Kempf Committed by Dominic Kempf
Browse files

[CMake] Allow adding compile flags upon running make

Autotools users kept complaining, that it is conceptionally
disappointing that targets cannot be build with flags set upon
entering make (e.g. make CXXFLAGS+="-myflag" mytarget). This
patch introduces a small hack, that allows for such feature
in cmake. It is, however, (at least) questionable whether we
want to include it. Still, for your information and convenience:

To use the feature you must:
- be using a CMake generator that is based on Makefiles (defaults to true)
- set the define ALLOW_EXTRA_CXXFLAGS to true, e.g. by including
  CMAKE_FLAGS="-DALLOW_EXTRA_CXXFLAGS=1" in your optsfile.
- reconfigure your project

cmake will then wrap a small shell script around your compiler
and allow you to append the content of an environment variable
to yout compiler flags. Run for above example:
EXTRA_CXXFLAGS="-myflag" make mytarget

The additional flags will be visually confirmed if and only if
you set the verbosity (as always):
EXTRA_CXXFLAGS="-myflag" make VERBOSE=1 mytarget
parent 4adcfde1
Branches
Tags
No related merge requests found
......@@ -656,6 +656,14 @@ macro(dune_project)
# set up make headercheck
include(Headercheck)
setup_headercheck()
# check whether the user wants to append compile flags upon calling make
if(ALLOW_EXTRA_CXXFLAGS AND (${CMAKE_GENERATOR} MATCHES ".*Unix Makefiles.*"))
file(WRITE ${CMAKE_BINARY_DIR}/compiler.sh
"#!/bin/bash\nif [ -n \"$VERBOSE\" ] ; then\necho 1>&2 \"Additional flags: \$EXTRA_CXXFLAGS\"\nfi\nexec ${CMAKE_CXX_COMPILER} \"\$@\" \$EXTRA_CXXFLAGS")
exec_program(chmod ARGS "+x ${CMAKE_BINARY_DIR}/compiler.sh")
set(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/compiler.sh)
endif()
endmacro(dune_project)
# create a new config.h file and overwrite the existing one
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment