Discussion:
[Cmake] Adding compile flags in several steps
Martin Magnusson
2004-08-17 12:18:30 UTC
Permalink
I'd like to specify a set of compiler flags which should always be used,
and another set which should be appended under certain circumstances. I
tried doing it like this:

SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-Wall -Werror")

IF(DEBUG_MODE)
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-g -O0 -DDEBUG_MODE=1" )
MESSAGE("Debug build.")
ELSE(DEBUG_MODE)
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-O3 -DDEBUG_MODE=0" )
MESSAGE("Release build.")
ENDIF(DEBUG_MODE)

but then, the "-Wall -Werror" is always overwritten. What's the correct
way to do this?

/ martin
Brad King
2004-08-17 12:35:07 UTC
Permalink
Post by Martin Magnusson
I'd like to specify a set of compiler flags which should always be used,
and another set which should be appended under certain circumstances. I
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-Wall -Werror")
IF(DEBUG_MODE)
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-g -O0 -DDEBUG_MODE=1" )
MESSAGE("Debug build.")
ELSE(DEBUG_MODE)
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS "-O3 -DDEBUG_MODE=0" )
MESSAGE("Release build.")
ENDIF(DEBUG_MODE)
but then, the "-Wall -Werror" is always overwritten. What's the correct
way to do this?
You can use GET_SOURCE_FILE_PROPERTY to obtain the previous value of the
COMPILE_FLAGS property and then append the flags and use
SET_SOURCE_FILES_PROPERTIES to set the new value. In your case, though,
you should just set the flags in the CMAKE_CXX_FLAGS_DEBUG and
CMAKE_CXX_FLAGS_RELEASE variables. Flags in these variables are
automatically included in release or debug builds.

If DEBUG_MODE is actually an option available to the user in the CMake
cache to enable/disable some extra debugging code then you should not
add it to the build this way. When the user changes it you want the
project to rebuild properly. You should use CONFIGURE_FILE to configure
a header file with this setting recorded. When it changes the file will
be updated and any dependent sources will rebuild.

-Brad
Brad King
2004-08-17 12:57:15 UTC
Permalink
Thanks for the quick reply. Just another quick (stupid) question.
How do you append flags? Doing something like
SET_SOURCE_FILES_PROPERTIES(
${SOURCES}
COMPILE_FLAGS ${OLD_FLAGS} ${NEW_FLAGS} )
doesn't seem to work. (It gives me the error message
"SET_SOURCE_FILES_PROPERTIES called with illegal arguments, maybe
missing a PROPERTIES specifier?") I don't see anything about it in the
online documentation either.
You can always pass values as a single argument by using double quotes:

SET_SOURCE_FILES_PROPERTIES(
${SOURCES} PROPERTIES
COMPILE_FLAGS "${OLD_FLAGS} ${NEW_FLAGS}"
)

-Brad
Iker Arizmendi
2004-08-17 17:55:49 UTC
Permalink
Our network has cmake 1.8.3 and I've noticed that
when I use the INSTALL_FILES directive the destination
files are updated even if they haven't changed (which forces
some of our other packages to rebuild). Does the most
recent version of CMake check to see if the install of
a file is necessary?

Regards,
Iker
--
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: ***@research.att.com
w: http://research.att.com
Andy Cedilnik
2004-08-17 19:14:16 UTC
Permalink
Hi Iker,

CMake 2.0 uses redesigned install procedure. That said, it still always
overwrites files. To my knowledge, this is a common practice.

Any arguments for and against?

I am not really sure you should depend on the files that are installed.

Andy
Post by Iker Arizmendi
Our network has cmake 1.8.3 and I've noticed that
when I use the INSTALL_FILES directive the destination
files are updated even if they haven't changed (which forces
some of our other packages to rebuild). Does the most
recent version of CMake check to see if the install of
a file is necessary?
Iker Arizmendi
2004-08-17 22:39:38 UTC
Permalink
Andy,

The argument in favor would be that it avoids
unnecessary builds of other sources that rely
on the installed files.

If I build several packages with dependencies
like so:

A <- B <- C

then I could have package B point into A's source
directory, but it seems more natural to have B
simply rely on whatever A installs (*). This is
especially true if A's install routine calls for
installing more than what's in A's include directory.
For instance, in my case A's build process creates
a config.h file and a custom cmake include file -
both of which reside in A's build directory.

Regards,
Iker

(*) Package B would use FIND macros over common
install locations to find A's files, just like
it would if installed on an end user's machine.
Post by Andy Cedilnik
Hi Iker,
CMake 2.0 uses redesigned install procedure. That said, it still always
overwrites files. To my knowledge, this is a common practice.
Any arguments for and against?
I am not really sure you should depend on the files that are installed.
Andy
Post by Iker Arizmendi
Our network has cmake 1.8.3 and I've noticed that
when I use the INSTALL_FILES directive the destination
files are updated even if they haven't changed (which forces
some of our other packages to rebuild). Does the most
recent version of CMake check to see if the install of
a file is necessary?
_______________________________________________
Cmake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: ***@research.att.com
w: http://research.att.com
Brad King
2004-08-18 16:12:36 UTC
Permalink
Post by Iker Arizmendi
The argument in favor would be that it avoids
unnecessary builds of other sources that rely
on the installed files.
It should not be too hard to modify the installation process to do
copy-if-different for each file installed. This will not change the
time it takes to install the first time very much. Later times may be a
bit slower but not compared to the savings from not rebuilding projects.

Please add this as a feature request here:

http://www.cmake.org/Bug

-Brad

Continue reading on narkive:
Loading...