[CMake] Source List Compilation Depending on Configuration
Hi! if i want to add sources to list of compilation i can rely on CMAKE_BUILD_TYPE. E.g if i want to add a source file only for release, i append it to list of source files only then. BUT: how can i do this for multi configuration like vs? So i want to add it to the sources, so that it appears in vs, but only want to compile it in release build? Is there an easy way to handle this? Thanks, Joerg Mannheim HRB 504702 Geschäftsführer: Dipl.-Ing. (FH) Michael Brenk (Vorsitzender), Dipl.-Ing. (FH) Dipl.-Inf. (FH) Jens Heyen This e-mail may contain confidential and/or legally protected information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden. Thank you! -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
On 07/21/2014 11:46 AM, Jörg Kreuzberger wrote: Hi! if i want to add sources to list of compilation i can rely on CMAKE_BUILD_TYPE. E.g if i want to add a source file only for release, i append it to list of source files only then. BUT: how can i do this for multi configuration like vs? So i want to add it to the sources, so that it appears in vs, but only want to compile it in release build? Is there an easy way to handle this? I don't think CMake supports configuration specific source files (I assume this might not be supported by all target build systems?). It should be possible to use the preprocessor (with configuration specific defines through the COMPILE_DEFINITIONS_CONFIG property) to work around it. E.g. either guard the source file's content itself with #ifdef CONFIG_SPECIFIC_DEFINE source file content #endif or add a wrapper source file that does something like #ifdef CONFIG_SPECIFIC_DEFINE #include config1.cpp #endif or even #ifdef CONFIG_SPECIFIC_DEFINE #include config1.cpp #else #include config2.cpp #endif Nils -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
Jörg Kreuzberger wrote: Is there an easy way to handle this? Try a nightly build: http://www.cmake.org/files/dev/?C=M;O=D And a generator expression: http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html add_library(mylib bar.cpp $$CONFIG:Debug:foo.cpp ) Testing the value of CMAKE_BUILD_TYPE is not the right/portable thing to do for exactly the reason you discovered. Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
Hm, following your suggestion i replace lines if( ${CMAKE_BUILD_TYPE} STREQUAL Release) add_definitions( -DNDEBUG ) endif() with set_directory_properties( PROPERTIES COMPILE_DEFINITIONS_RELEASE ${COMPILE_DEFINITIONS_RELEASE};NDEBUG ) it didnt worked. ( inspecting e.q. flags.make and compilation ) if i set COMPILE_DEFINITIONS (without config) it worked. This is the point i stuct like above again. -Ursprüngliche Nachricht- Von:Nils Gladitz nilsglad...@gmail.com Gesendet: Mo 21.07.2014 12:13 Betreff:Re: [CMake] Source List Compilation Depending on Configuration An: Jörg Kreuzberger j.kreuzber...@procitec.de; cmake@cmake.org; On 07/21/2014 11:46 AM, Jörg Kreuzberger wrote: Hi! if i want to add sources to list of compilation i can rely on CMAKE_BUILD_TYPE. E.g if i want to add a source file only for release, i append it to list of source files only then. BUT: how can i do this for multi configuration like vs? So i want to add it to the sources, so that it appears in vs, but only want to compile it in release build? Is there an easy way to handle this? I don't think CMake supports configuration specific source files (I assume this might not be supported by all target build systems?). It should be possible to use the preprocessor (with configuration specific defines through the COMPILE_DEFINITIONS_CONFIG property) to work around it. E.g. either guard the source file's content itself with #ifdef CONFIG_SPECIFIC_DEFINE source file content #endif or add a wrapper source file that does something like #ifdef CONFIG_SPECIFIC_DEFINE #include config1.cpp #endif or even #ifdef CONFIG_SPECIFIC_DEFINE #include config1.cpp #else #include config2.cpp #endif Nils Mannheim HRB 504702 Geschäftsführer: Dipl.-Ing. (FH) Michael Brenk (Vorsitzender), Dipl.-Ing. (FH) Dipl.-Inf. (FH) Jens Heyen This e-mail may contain confidential and/or legally protected information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden. Thank you! -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
On 07/21/2014 02:29 PM, Jörg Kreuzberger wrote: Hm, following your suggestion i replace lines if( ${CMAKE_BUILD_TYPE} STREQUAL Release) add_definitions( -DNDEBUG ) endif() with set_directory_properties( PROPERTIES COMPILE_DEFINITIONS_RELEASE ${COMPILE_DEFINITIONS_RELEASE};NDEBUG ) ${COMPILE_DEFINITIONS_RELEASE} does not expand the property but you could use set_property() with the APPEND flag for that. NDEBUG is set by default for MinSizeRel, Release and RelWithDebInfo so you should have found it in the Release flags even without using the property (unless you override the default flags). With set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE FOOBAR) I get ./CMakeFiles/foo.dir/flags.make:CXX_DEFINES = -DFOOBAR When configuring a Release build with the Makefiles generator. Nils -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
1) i reset it with set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_INIT} ) set( CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_INIT} ) set( CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG_INIT} ) and then append my own custom compiler definitions. -DNDEBUG appears in flags.make, only in CXX_FLAGS, but not in CXX_DEFINES! and this is the issue i had with it: as long it appears only in CXX_FLAGS, it works for the code compilation but it does not work for qt4_wrapp_cpp (missing defines for moc). 2) the point i want to change global compiler properties is in my toplevel CMakeLists.txt, there i do include( cmake/GlobalCompilerSettings.cmake) 3) following your example, it does not work for COMPILE_DEFINITIONS_RELEASE, but does work for COMPILE_DEFINITIONS. (works means it appears in CXX_DEFINES) using release cmake 3.0.0 version. Platform is ubuntu linux (makefile generator) -Ursprüngliche Nachricht- Von:Nils Gladitz nilsglad...@gmail.com Gesendet: Mo 21.07.2014 14:45 Betreff:Re: AW: [CMake] Source List Compilation Depending on Configuration An: Jörg Kreuzberger j.kreuzber...@procitec.de; CC: cmake@cmake.org; On 07/21/2014 02:29 PM, Jörg Kreuzberger wrote: Hm, following your suggestion i replace lines if( ${CMAKE_BUILD_TYPE} STREQUAL Release) add_definitions( -DNDEBUG ) endif() with set_directory_properties( PROPERTIES COMPILE_DEFINITIONS_RELEASE ${COMPILE_DEFINITIONS_RELEASE};NDEBUG ) ${COMPILE_DEFINITIONS_RELEASE} does not expand the property but you could use set_property() with the APPEND flag for that. NDEBUG is set by default for MinSizeRel, Release and RelWithDebInfo so you should have found it in the Release flags even without using the property (unless you override the default flags). With set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE FOOBAR) I get ./CMakeFiles/foo.dir/flags.make:CXX_DEFINES = -DFOOBAR When configuring a Release build with the Makefiles generator. Nils Mannheim HRB 504702 Geschäftsführer: Dipl.-Ing. (FH) Michael Brenk (Vorsitzender), Dipl.-Ing. (FH) Dipl.-Inf. (FH) Jens Heyen This e-mail may contain confidential and/or legally protected information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden. Thank you! -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
On 07/21/2014 03:19 PM, Jörg Kreuzberger wrote: 1) i reset it with set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_INIT} ) set( CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_INIT} ) set( CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG_INIT} ) and then append my own custom compiler definitions. -DNDEBUG appears in flags.make, only in CXX_FLAGS, but not in CXX_DEFINES! and this is the issue i had with it: as long it appears only in CXX_FLAGS, it works for the code compilation but it does not work for qt4_wrapp_cpp (missing defines for moc). 2) the point i want to change global compiler properties is in my toplevel CMakeLists.txt, there i do include( cmake/GlobalCompilerSettings.cmake) 3) following your example, it does not work for COMPILE_DEFINITIONS_RELEASE, but does work for COMPILE_DEFINITIONS. (works means it appears in CXX_DEFINES) using release cmake 3.0.0 version. Platform is ubuntu linux (makefile generator) I forgot that COMPILE_DEFINITIONS_CONFIG were deprecated. When you require 3.0 the property is ignored (Policy CMP0043). $$CONFIG:Release:NDEBUG in COMPILE_DEFINITIONS should work. Nils -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
ok, then it worked. i got no warning on the policies, maybe i would have then detected it further. Can i enable them globally? -Ursprüngliche Nachricht- Von:Nils Gladitz nilsglad...@gmail.com Gesendet: Mo 21.07.2014 15:36 Betreff:Re: AW: [CMake] Source List Compilation Depending on Configuration An: Jörg Kreuzberger j.kreuzber...@procitec.de; CC: cmake@cmake.org; On 07/21/2014 03:19 PM, Jörg Kreuzberger wrote: 1) i reset it with set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_INIT} ) set( CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_INIT} ) set( CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG_INIT} ) and then append my own custom compiler definitions. -DNDEBUG appears in flags.make, only in CXX_FLAGS, but not in CXX_DEFINES! and this is the issue i had with it: as long it appears only in CXX_FLAGS, it works for the code compilation but it does not work for qt4_wrapp_cpp (missing defines for moc). 2) the point i want to change global compiler properties is in my toplevel CMakeLists.txt, there i do include( cmake/GlobalCompilerSettings.cmake) 3) following your example, it does not work for COMPILE_DEFINITIONS_RELEASE, but does work for COMPILE_DEFINITIONS. (works means it appears in CXX_DEFINES) using release cmake 3.0.0 version. Platform is ubuntu linux (makefile generator) I forgot that COMPILE_DEFINITIONS_CONFIG were deprecated. When you require 3.0 the property is ignored (Policy CMP0043). $$CONFIG:Release:NDEBUG in COMPILE_DEFINITIONS should work. Nils Mannheim HRB 504702 Geschäftsführer: Dipl.-Ing. (FH) Michael Brenk (Vorsitzender), Dipl.-Ing. (FH) Dipl.-Inf. (FH) Jens Heyen This e-mail may contain confidential and/or legally protected information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this email is strictly forbidden. Thank you! -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Source List Compilation Depending on Configuration
On 07/21/2014 04:01 PM, Jörg Kreuzberger wrote: ok, then it worked. i got no warning on the policies, maybe i would have then detected it further. Can i enable them globally? With cmake_minimum_required(VERSION 3.0) the new behaviour is used for the policy which is to ignore the property without warning. I think to get a warning you would have had to require an older version while using CMake 3.0 which I guess only makes this detectable when migrating an existing project from an older version after already having upgraded to 3.0. Nils -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake