[CMake] Build-time override? (was Re: ExternalProject_Add and inheritance)

Christopher Sean Morrison brlcad at mac.com
Fri Dec 11 11:29:10 EST 2015


On Dec 11, 2015, at 2:44 AM, CHEVRIER, Marc <marc.chevrier at sap.com> wrote:

> With CMake, you can control compilation and link flags with the following environment variables:
> CC: specify C compiler
> CFLAGS: C compiler flags
> CXX: specify C++ compiler
> CXXFLAGS: C++ compiler flags
> LDFLAGS: linker flags
> And to finish you can overload make command for generation using CMAKE_COMMAND option of ExternalProject_Add:
> CMAKE_CMMAND “${CMAKE_COMMAND}” -E env CXX=${CMAKE_CXX_COMPILER} LDFLAGS=“…” “${CMAKE_COMMAND}”

This has probably been mentioned before, but it would be very useful if the output generators would take environment variable overrides into account.  This is particularly useful during adhoc development testing where one wants to override build flags, or two-stage compilation, or when the generated output is unhelpful for a given user’s configuration, etc.  It’s also a feature lost for projects converting from Autotools-generated Makefile builds.  An example, two-stage compilation might be something like:

CC=icc cmake .. 
make CFLAGS=“-fast -O3 -prof_gen /path/to/filename”
# run some tools
make CFLAGS=“-fast -O3 prof_use /path/to/filename”

Gets even more complicated if one only wants to instrument one/few files down in some subdir.  Editing flags.make doesn’t really work well in that situation.  Editing a CMakeLists.txt property for those few files is also particularly inconvenient when re-running CMake takes several minutes and/or the build change is merely exploratory development.

Apologies if there is already a way to do this now.  Last I looked a couple years ago, there was not and the docs on CMAKE_C_COMPILER seem to indicate this is still not possible.

Cheers!
Sean

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151211/471127e0/attachment.html>


More information about the CMake mailing list