[CMake] User vs Project vs Cmake vs Target flags; CMAKE_USER_MAKE_RULES_OVERRIDE vs -C

Ateljevich, Eli eli at water.ca.gov
Tue Jun 26 14:19:32 EDT 2012


I know this is a kind of a big scope for a question, but it shadows a lot of customization issues I have seen in many other topics.

To recap an earlier posting, I mentioned that I wanted to allow the user to add some custom definitions in a more persistent way than the cache.  Ben Morgan suggested I try the "-C" option to special an <initial-cache>.  This  initializes the cache when it is first built, so the solution requires the user to either work in two places or blow away the cache when they want to make the change. CMake processes the -C script first and caches any variables it SETs. Thereafter in the main CMake scripts for the project, cmake does what it always does when it encounters a SET and the value is in found in the cache ... it ignores the SET. This is why the -C script takes precedence over the main CMake scripts and no doubt the reason it only works the first time you build your cache. Two other restrictions 1) Cmake checks that the only thing you do in the -C script is SET 2) nothing is loaded or in scope yet... good for some things, bad for others.

The other option I have read about is CMAKE_USER_MAKE_RULES_OVERRIDE and its language specific variants. Can someone guide me in choosing one over the other? Is part of it that CMAKE_USER_MAKE_RULES_OVERRIDE is not cached ... it will be always re-evaluated? Is it legal for me to define anything I want in that script? What other actions are allowed? When is it loaded?

As to requirements ... ours is a numerical code in which it is important to offer users quite a bit of control on flags. At the same time, the project as a whole has some assumed defaults for each platform/compiler combination.  I need to negotiate these two issues (certainly doable):
1. Any properties (COMPILER_FLAGS) and add_definitions I put near the library and executable definitions may just erase whatever the user puts in. Add_definitions seem fine for things that are -D type defines, but  for flags that might be compiler specific I need to assign them earlier on in a more generic variable.
2. I need to get the project-specific defaults everyone wants in first, then let the user override those. So it would be nice to have something like an INCLUDE file that installs flag defaults based on compiler/platform combinations.

I realize that depending on how I do #2 it has the potential to thwart some of what cmake does. I would be perfectly happy working with CMake rather than against it. If there were a variable like "INTEL_Fortran_COMPILE_FLAGS_INIT_RELEASE" I could set early enough to sneak it into the automatic configuration steps, I would prefer that to setting a bunch of IF statements up myself based on platform/compiler combos.

Can anyone help me with this?

Thanks.

Eli


More information about the CMake mailing list