[CMake] Managed C++/CLI, default build flags and configurations

David Hunter davidhunter22 at gmail.com
Tue Jun 7 13:29:27 EDT 2011


Hi,

I have a number of projects which contain mostly sub-directories with
standard C++. I currently build all this stuff on Linux and Windows
and everything is great. However I have a couple of directories in
these projects which contain managed C++/CLI code so that I can expose
the unmanaged C++ functionality to the rest of the Microsoft universe,
obviously these directories build only on Windows. Currently I include
the following snippet of CMake code, which I found on another post, to
"fix" the compiler flags to enable the managed build

# Managed C++ set up

set_target_properties(${TargetName} PROPERTIES COMPILE_FLAGS "/clr")

if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1")
   string(REPLACE "/RTC1" " " 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()

My question is whether there is a better way to do this as the above
seems a bit brittle and manual. For instance is it possible to define
a new build configuration and somehow signal in the CMake input file
that this directory should use it. In general what I want to be able
to do is to indicate that a different set of default compile flags
should be used for a given directory rather than the default.

I am happy to spend time working on this and sharing any results but
would appreciate any pointers from the CMake experts before I start so
I don't go off wasting my time.

David


More information about the CMake mailing list