[CMake] Removing compiler options

Angeliki Chrysochou angeliki.chrysochou at gmail.com
Wed Dec 17 05:59:04 EST 2014


Hi Robert,

A solution could be to create a custom build type with specific flags by
appending "_<build type name>" to CMAKE_CXX_FLAGS. In that way one could
specify different flags for different build types and then set them as
default for the project they wish to build. This could work like this for
example, assuming I want my build type name to be "CustomRel":

# set default build type and available options

if(NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE CustomRel CACHE STRING "Choose the type of build,
options are: None CustomRel Debug." FORCE)
   SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None CustomRel
Debug)
endif()

# set default flags for build type

set(CMAKE_CXX_FLAGS_CUSTOMREL "-O2 -Werror" CACHE STRING "Flags used by the
C++ compiler." FORCE)
set(CMAKE_C_FLAGS_CUSTOMREL "-O2 -Wall -Wpointer-arith" CACHE STRING "Flags
used by the C compiler." FORCE)

Cheers!
Angeliki


On Wed, Dec 17, 2014 at 8:30 AM, J Decker <d3ck0r at gmail.com> wrote:
>
>     string( REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT
> ${CMAKE_CXX_FLAGS_INIT} )
>     string( REPLACE "/EHsc" "" CMAKE_C_FLAGS_INIT ${CMAKE_C_FLAGS_INIT} )
>     string( REPLACE "/EHs" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_INIT} )
>     string( REPLACE "/EHs" "" CMAKE_C_FLAGS_INIT ${CMAKE_C_FLAGS_INIT} )
>     string( REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG
> ${CMAKE_CXX_FLAGS_DEBUG} )
>     # cannot set CLR for C code anyway
>     #string( REPLACE "/RTC1" "/CLR" CMAKE_C_FLAGS_DEBUG
> ${CMAKE_C_FLAGS_DEBUG} )
>
>
> However; this ends up being a global sort of thing... would be nice to be
> able to edit properties per target...
>
> There's also a     <CLRSupport>true</CLRSupport>    flag in the project
> file that it doesn't look like cmake supports emitting at all... it's the
> setting that's in General Configuration Properties... doesn't look like
> it's required to compile and link as MSIL... but maybe that's where the
> setting to enable adding references is?  ... ya... clearing that removes
> COM and .NET assemblies from the reference add page; just solution targets
> are available...
>
>
>
> On Tue, Dec 16, 2014 at 11:08 PM, Domen Vrankar <domen.vrankar at gmail.com>
> wrote:
>>
>> This was asked a few years ago and I doubt that things have changed
>> since then... http://www.cmake.org/pipermail/cmake/2010-May/036924.html
>> (
>> http://www.cmake.org/cmake/help/v2.8.10/cmake.html#prop_sf%3aCOMPILE_FLAGS
>> ).
>> An alternative would be to use
>> http://www.cmake.org/cmake/help/v3.0/module/ExternalProject.html
>>
>> Regards,
>> Domen
>>
>> 2014-12-17 4:49 GMT+01:00 Robert Dailey <rcdailey.lists at gmail.com>:
>> > I still really need help with this. It's a blocker at this point for
>> > me. Help is greatly appreciated; thanks in advance.
>> >
>> > On Sun, Nov 9, 2014 at 10:02 PM, Robert Dailey <
>> rcdailey.lists at gmail.com> wrote:
>> >> When setting up a CLR project through CMake, it becomes important to
>> >> be able to *remove* compiler options at the project level. For
>> >> example, the following need to be removed (MSVC12):
>> >>
>> >> /RTC1
>> >> /EHsc
>> >>
>> >> There is no "remove_compile_options()" (which would be convenient).
>> >> Any reason why this doesn't exist?
>> >>
>> >> Right now I'm trying to remove these via CMAKE_CXX_FLAGS locally but
>> >> this doesn't work unless I forcefully change the cache. But this is a
>> >> permanent operation that affects *all* projects, which I do not want.
>> >> This is crazy, I'm hoping there is a better way. I'm using CMake 3.1
>> >> RC1. Can anyone help me figure out how to remove compiler options on a
>> >> per-project basis?
>> >>
>> >> Here is what I'm doing:
>> >>
>> >> function( add_clr_library target_name references )
>> >>     set( source_files ${ARGN} )
>> >>
>> >>     set( default_references
>> >>         System
>> >>         System.Core
>> >>         System.Data
>> >>         System.Drawing
>> >>         #System.Xml
>> >>         #WindowsBase
>> >>     )
>> >>
>> >>     if( CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1" )
>> >>         string( REGEX REPLACE "/RTC(su|[1su])" ""
>> >> CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" )
>> >>     endif()
>> >>
>> >>     if( CMAKE_CXX_FLAGS MATCHES "/EHsc" )
>> >>         string( REPLACE "/EHsc" "" CMAKE_CXX_FLAGS
>> "${CMAKE_CXX_FLAGS}" )
>> >>     endif()
>> >>
>> >>     add_library( ${target_name} SHARED ${source_files} )
>> >>
>> >>     list( APPEND references ${default_references} )
>> >>
>> >>     set_target_properties( ${target_name} PROPERTIES
>> >>         VS_DOTNET_REFERENCES "${references}"
>> >>         VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.5"
>> >>         COMPILE_FLAGS "/clr /EHa"
>> >>         DEBUG_POSTFIX "d"
>> >>     )
>> >> endfunction()
>> > --
>> >
>> > 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
>> --
>>
>> 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
>>
>
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141217/497db61f/attachment.html>


More information about the CMake mailing list