Discussion:
[CMake] Recompile with different flags
Adam Weiss
2009-01-19 20:02:34 UTC
Permalink
I couldn't find an answer to this, so I thought I should ask.

I have a set of source files that are compiled and built into a library.
Works great.
Now I want to recompile those same files with a compiler flag added into
another library. Don't ask, this is how it has to be.

I tried doing add_library, then set_source_files_properties, then
add_library but then the flag is set for both.

I would like to keep it all inside of one CMakeLists.txt file, but I might
be able to work it out another way.


Thanks for any help,
Adam
Dmytro Ovdiienko
2009-01-19 21:10:29 UTC
Permalink
Adam,

How about two configurations for your library: cfg_1, cfg_2.
cfg_1 - is configuration without flag.
cfg_2 - is configuration with flag.
Post by Adam Weiss
I couldn't find an answer to this, so I thought I should ask.
I have a set of source files that are compiled and built into a library.
Works great.
Now I want to recompile those same files with a compiler flag added into
another library. Don't ask, this is how it has to be.
I tried doing add_library, then set_source_files_properties, then
add_library but then the flag is set for both.
I would like to keep it all inside of one CMakeLists.txt file, but I might
be able to work it out another way.
Thanks for any help,
Adam
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
Adam Weiss
2009-01-19 21:44:49 UTC
Permalink
I am still fairly new to cmake, and I am not sure how to make
configurations. Let me see if I can provide some more details.

The hope is that a third party can run:

mkdir build
cd build
cmake ..
make

and have both libraries built. A less graceful way I was considering
was to have cmake copy all the files that need the flag set and then
use the copies to build the second version of the library. If you
could elaborate on how to build configurations of a library I would
appreciate it.

-Adam

On Mon, Jan 19, 2009 at 4:10 PM, Dmytro Ovdiienko
Post by Dmytro Ovdiienko
Adam,
How about two configurations for your library: cfg_1, cfg_2.
cfg_1 - is configuration without flag.
cfg_2 - is configuration with flag.
Post by Adam Weiss
I couldn't find an answer to this, so I thought I should ask.
I have a set of source files that are compiled and built into a library. Works great.
Now I want to recompile those same files with a compiler flag added into another library. Don't ask, this is how it has to be.
I tried doing add_library, then set_source_files_properties, then add_library but then the flag is set for both.
I would like to keep it all inside of one CMakeLists.txt file, but I might be able to work it out another way.
Thanks for any help,
Adam
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
Philip Lowman
2009-01-19 22:48:16 UTC
Permalink
On Mon, Jan 19, 2009 at 4:44 PM, Adam Weiss
Post by Adam Weiss
I am still fairly new to cmake, and I am not sure how to make
configurations. Let me see if I can provide some more details.
mkdir build
cd build
cmake ..
make
and have both libraries built. A less graceful way I was considering
was to have cmake copy all the files that need the flag set and then
use the copies to build the second version of the library. If you
could elaborate on how to build configurations of a library I would
appreciate it.
Sounds like you could call add_library() twice and use the COMPILE_FLAGS
property on each target?

set(my_SRCS foo.h foo.cc)

add_library(foo ${my_SRCS})
set_target_properties(foo PROPERTIES COMPILE_FLAGS "-DFOO")

add_library(foo2 ${my_SRCS})
set_target_properties(foo2 PROPERTIES COMPILE_FLAGS "-DFOO2")
--
Philip Lowman
Adam Weiss
2009-01-20 00:48:09 UTC
Permalink
I thought only LINK_FLAGS could be added there, I'll try it when I get
back to my work machine.

As for ignoring the flags, I don't think that will work since several files have

#ifndef VAR_NAME
<code>
#else
<code>
#endif

Again, this method bothers me, but I'm supposed to make a few code
changes as possible.

Thanks
Post by Philip Lowman
Post by Adam Weiss
I am still fairly new to cmake, and I am not sure how to make
configurations. Let me see if I can provide some more details.
mkdir build
cd build
cmake ..
make
and have both libraries built. A less graceful way I was considering
was to have cmake copy all the files that need the flag set and then
use the copies to build the second version of the library. If you
could elaborate on how to build configurations of a library I would
appreciate it.
Sounds like you could call add_library() twice and use the COMPILE_FLAGS
property on each target?
set(my_SRCS foo.h foo.cc)
add_library(foo ${my_SRCS})
set_target_properties(foo PROPERTIES COMPILE_FLAGS "-DFOO")
add_library(foo2 ${my_SRCS})
set_target_properties(foo2 PROPERTIES COMPILE_FLAGS "-DFOO2")
--
Philip Lowman
Matthew Woehlke
2009-01-20 00:52:41 UTC
Permalink
Post by Adam Weiss
I thought only LINK_FLAGS could be added there, I'll try it when I get
back to my work machine.
Not AFAIK; I'm using COMPILE_FLAGS as well as LINK_FLAGS per-target.
Post by Adam Weiss
As for ignoring the flags, I don't think that will work since several files have
#ifndef VAR_NAME
<code>
#else
<code>
#endif
If it's just definitions, at worst you can change things to use a unique
definition per library being built (and if needed, define other things
based on that), since you can fiddle with preprocessor stuff in the
source files. Things like optimization flags would be a much more
serious problem.
--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
morphir: so much confusion :S kmake, kdemake, qmake make cmake etc.
logixoul: you forgot cmakekde :)
morphir: and bakemeacake
Matthew Woehlke
2009-01-19 22:40:20 UTC
Permalink
Post by Adam Weiss
I couldn't find an answer to this, so I thought I should ask.
I have a set of source files that are compiled and built into a library.
Works great.
Now I want to recompile those same files with a compiler flag added into
another library. Don't ask, this is how it has to be.
I tried doing add_library, then set_source_files_properties, then
add_library but then the flag is set for both.
I would like to keep it all inside of one CMakeLists.txt file, but I might
be able to work it out another way.
I have a project with similar requirements. Can you arrange for the
additional flags to be ignored by any other sources in the second
library? (If they're definitions, this shouldn't be too hard, if they're
e.g. optimization flags, that might be an issue.) If so, you can set
properties on the target (the library) instead of the sources.

This either works, or I haven't looked closely enough at my build :-).
--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
morphir: so much confusion :S kmake, kdemake, qmake make cmake etc.
logixoul: you forgot cmakekde :)
morphir: and bakemeacake
Mike Arthur
2009-01-20 10:04:05 UTC
Permalink
Post by Adam Weiss
I have a set of source files that are compiled and built into a library.
Works great.
Now I want to recompile those same files with a compiler flag added into
another library. Don't ask, this is how it has to be.
Purely for intellectual curiosity, why does this have to be? No worries if you
don't have time to reply to this, I'm just interested by other peoples
configurations :)
--
Cheers,
Mike Arthur
http://mikearthur.co.uk/
Adam Weiss
2009-01-20 13:05:10 UTC
Permalink
Due to proprietary information issues I can't go into detail, but I
can give a vague description.

Our company started in Ada now is transitioning to C++. The older
employees don't really want to learn and tend to code the C++ in the
style of Ada and avoid using any of the features like polymorphic
dispatch, templates, or abstract interfaces. The code that is being
compiled into 2 libraries and 2 executables need to be built by a
third party without too much change to their current gmake procedure.

The other problem is that I was told to try to convert to cmake with a
few code changes as possible (except for the obvious additions of
CMakeLists.txt files). So far everything has been great. Then I
found in the current make file that they recompile this set of files
twice, once with a flag set and once without.

The file structure is horrendous, the files themselves are full of
things like this, and there are no formal test procedures. Some days
I wish I could just sit down and rewrite it all.

So that's my venting for today :) Hope that sheds some light on
things but wasn't too much.

P.S. The set_target_properties with COMPILE_FLAGS seems to be working, thanks!

-Adam
Post by Mike Arthur
Post by Adam Weiss
I have a set of source files that are compiled and built into a library.
Works great.
Now I want to recompile those same files with a compiler flag added into
another library. Don't ask, this is how it has to be.
Purely for intellectual curiosity, why does this have to be? No worries if you
don't have time to reply to this, I'm just interested by other peoples
configurations :)
--
Cheers,
Mike Arthur
http://mikearthur.co.uk/
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
Loading...