[CMake] Build several libraries with different compilation flags
Hello everybody, I would like to build two libraries that contain the same files but with a slightly different set of compilation flags from one library to another. This within the same makefile. I was thinking about an approach such as: add_library(my_lib1, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) add_library(my_lib2, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) does cmake sensitive to the order of these instruction ? thank you very much Eric -- Eric Pellegrini Calcul Scientifique Insitut Laue-Langevin Grenoble, France ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
Hi Marcel, Yes, you are right but as I said to Ryan my problem is that I do not want to change the compiler flags for the whole library (in that case the set_target_properties would be the appropriated way to do) but only for a few files of my library. What I want to do seems tricky (or perhaps non sense ?). What about the following approach ? I will create two separate projects that I will call in my main CMakeLists.txt on the following way: project(my_whole_project Fortran) include(my_first_project) include(my_second_project) ... In doing so, each project does not see the other one (I hope) and I should be able to do whatever I want with one without disturbing the other. What do you think ?. Eric Marcel Loose a écrit : Hi Eric, I'm not sure your solution is going to work. Once your file1, file2, ... are compiled for building my_lib1, there's reason for CMake to compile them again for my_lib2, because the object files are already up-to-date. I guess you'll have a better chance using target_properties, as Ryan suggested. HTH, Marcel Loose. On Fri, 2010-10-01 at 17:10 +0200, pellegrini wrote: Hi Ryan, Yes, that might be the solution if I wanted to change the compiler flags for the whole library but in my case, that is not on the whole library that I want to apply a new set of compiler flags but only on a small number of files. Ryan Pavlik a écrit : Look at the target properties instead of the source file properties. Ryan On 10/01/2010 08:27 AM, pellegrini wrote: Hello everybody, I would like to build two libraries that contain the same files but with a slightly different set of compilation flags from one library to another. This within the same makefile. I was thinking about an approach such as: add_library(my_lib1, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) add_library(my_lib2, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) does cmake sensitive to the order of these instruction ? thank you very much Eric -- Eric Pellegrini Calcul Scientifique Insitut Laue-Langevin Grenoble, France ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
On 10/01/2010 05:10 PM, pellegrini wrote: > Hi Ryan, > > Yes, that might be the solution if I wanted to change the compiler flags > for the whole library but in my case, that is not on the whole > library that I want to apply a new set of compiler flags but only on a > small number of files. You could use symbolic links in junction with source properties: CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(SYMLINKSOURCE C) FILE(WRITE ${CMAKE_BINARY_DIR}/f1.c "void f(void){}\n") ADD_LIBRARY(l1 SHARED f1.c) ADD_CUSTOM_COMMAND(OUTPUT f2.c COMMAND ${CMAKE_COMMAND} -E create_symlink f1.c f2.c) SET_SOURCE_FILES_PROPERTIES(f2.c PROPERTIES COMPILE_FLAGS "-O0") ADD_LIBRARY(l2 SHARED f2.c) So, the l{1,2} targets are compiled from the same source but with different flags, and the latters can be specified per source file. Regards, Michael > Ryan Pavlik a écrit : >> Look at the target properties instead of the source file properties. >> >> Ryan >> >> On 10/01/2010 08:27 AM, pellegrini wrote: >>> Hello everybody, >>> >>> I would like to build two libraries that contain the same files but >>> with a slightly different set of compilation flags >>> from one library to another. This within the same makefile. I was >>> thinking about an approach such as: >>> >>> add_library(my_lib1, STATIC, src_files ...) >>> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS >>> ...) >>> add_library(my_lib2, STATIC, src_files ...) >>> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS >>> ...) >>> >>> does cmake sensitive to the order of these instruction ? >>> >>> thank you very much >>> >>> Eric ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
On Fri, Oct 1, 2010 at 8:32 AM, Marcel Loose wrote: > Hi Eric, > > I'm not sure your solution is going to work. Once your file1, file2, ... > are compiled for building my_lib1, there's reason for CMake to compile > them again for my_lib2, because the object files are already up-to-date. > I guess you'll have a better chance using target_properties, as Ryan > suggested. > That's not really true... objects get built into .dir ... so they are different. the problem is cmake only maintains a single list of sources, and the flags end up getting set for both versions. Really have to use target_properties ... or somehow invent a way to set_target_source_files_properties( target source ) maybe seperate the sources that need different flags into another library, and apply said flags to that target.. then link the whole mess together? > HTH, > Marcel Loose. > > On Fri, 2010-10-01 at 17:10 +0200, pellegrini wrote: >> Hi Ryan, >> >> Yes, that might be the solution if I wanted to change the compiler flags >> for the whole library but in my case, that is not on the whole >> library that I want to apply a new set of compiler flags but only on a >> small number of files. >> >> Ryan Pavlik a écrit : >> > Look at the target properties instead of the source file properties. >> > >> > Ryan >> > >> > On 10/01/2010 08:27 AM, pellegrini wrote: >> >> Hello everybody, >> >> >> >> I would like to build two libraries that contain the same files but >> >> with a slightly different set of compilation flags >> >> from one library to another. This within the same makefile. I was >> >> thinking about an approach such as: >> >> >> >> add_library(my_lib1, STATIC, src_files ...) >> >> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS >> >> ...) >> >> add_library(my_lib2, STATIC, src_files ...) >> >> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS >> >> ...) >> >> >> >> does cmake sensitive to the order of these instruction ? >> >> >> >> thank you very much >> >> >> >> Eric >> >> >> >> >> > >> >> > > > ___ > Powered by www.kitware.com > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Follow this link to subscribe/unsubscribe: > http://www.cmake.org/mailman/listinfo/cmake > ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
Look at the target properties instead of the source file properties. Ryan On 10/01/2010 08:27 AM, pellegrini wrote: Hello everybody, I would like to build two libraries that contain the same files but with a slightly different set of compilation flags from one library to another. This within the same makefile. I was thinking about an approach such as: add_library(my_lib1, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) add_library(my_lib2, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) does cmake sensitive to the order of these instruction ? thank you very much Eric -- Ryan Pavlik HCI Graduate Student Virtual Reality Applications Center Iowa State University Member, ACM and ACM SIGCHI Member, ASME http://academic.cleardefinition.com ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
Hi Ryan, Yes, that might be the solution if I wanted to change the compiler flags for the whole library but in my case, that is not on the whole library that I want to apply a new set of compiler flags but only on a small number of files. Ryan Pavlik a écrit : Look at the target properties instead of the source file properties. Ryan On 10/01/2010 08:27 AM, pellegrini wrote: Hello everybody, I would like to build two libraries that contain the same files but with a slightly different set of compilation flags from one library to another. This within the same makefile. I was thinking about an approach such as: add_library(my_lib1, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) add_library(my_lib2, STATIC, src_files ...) set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS ...) does cmake sensitive to the order of these instruction ? thank you very much Eric -- Eric Pellegrini Calcul Scientifique Insitut Laue-Langevin Grenoble, France ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build several libraries with different compilation flags
Hi Eric, I'm not sure your solution is going to work. Once your file1, file2, ... are compiled for building my_lib1, there's reason for CMake to compile them again for my_lib2, because the object files are already up-to-date. I guess you'll have a better chance using target_properties, as Ryan suggested. HTH, Marcel Loose. On Fri, 2010-10-01 at 17:10 +0200, pellegrini wrote: > Hi Ryan, > > Yes, that might be the solution if I wanted to change the compiler flags > for the whole library but in my case, that is not on the whole > library that I want to apply a new set of compiler flags but only on a > small number of files. > > Ryan Pavlik a écrit : > > Look at the target properties instead of the source file properties. > > > > Ryan > > > > On 10/01/2010 08:27 AM, pellegrini wrote: > >> Hello everybody, > >> > >> I would like to build two libraries that contain the same files but > >> with a slightly different set of compilation flags > >> from one library to another. This within the same makefile. I was > >> thinking about an approach such as: > >> > >> add_library(my_lib1, STATIC, src_files ...) > >> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS > >> ...) > >> add_library(my_lib2, STATIC, src_files ...) > >> set_source_files_properties(file1, file2 ... PROPERTIES COMPILE_FLAGS > >> ...) > >> > >> does cmake sensitive to the order of these instruction ? > >> > >> thank you very much > >> > >> Eric > >> > >> > > > > ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake