使用cmake将clr支持设置为true

时间:2016-10-19 09:01:25

标签: cmake clr managed-c++

我正在尝试使用cmake生成托管c ++代码。以下是我为

添加的脚本
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/clr") 
 STRING(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
 STRING(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clr")  

它没有将clrsupport设置为true。我们如何做cmake。

-swetha

2 个答案:

答案 0 :(得分:2)

我在我的cmakelist中设置了以下属性,它现在正在运行

target_compile_options(${project_name} PRIVATE /clr)
target_compile_options(${project_name} PRIVATE /fp:precise) # /fp:strict is          
incompatible with /clr

set_property(TARGET ${project_name} PROPERTY VS_GLOBAL_ROOTNAMESPACE ${project_name})

set_property(TARGET ${project_name} PROPERTY VS_GLOBAL_KEYWORD "ManagedCProj")

set_property(TARGET ${project_name} PROPERTY VS_GLOBAL_CLRSupport "true")

set_property(TARGET ${project_name} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.0")

set_property(TARGET ${project_name} PROPERTY VS_DOTNET_REFERENCES "System" "System.Data" "System.Drawing" "System.Windows.Forms" "System.Xml")

# Note: Modification of compiler flags is required for CLR compatibility now that we are using .resx files.
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

答案 1 :(得分:1)

在Visual Studio 2017上,这对我有用:

set_target_properties(${PROJECT_NAME} PROPERTIES COMMON_LANGUAGE_RUNTIME "")

请注意,Visual Studio 2017已删除了值“ pure”和“ safe”,并且上面的空字符串""将为您提供“混合”(本机/托管)dll。