set clr support to true with cmake

左心房为你撑大大i 提交于 2019-12-24 09:28:56

问题


I am trying generate a managed c++ code with cmake. Below is the script which i have added for

 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")  

It does not set clrsupport to true.How do we do it cmake.

-swetha


回答1:


This does the trick for me, on Visual Studio 2017:

set_target_properties(${PROJECT_NAME} PROPERTIES COMMON_LANGUAGE_RUNTIME "")

Note that the values "pure" and "safe" have been removed with Visual Studio 2017, and the empty string "" as above will get you a "mixed" (native/managed) dll.




回答2:


I set the following property in my cmakelist it is now working

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}")


来源:https://stackoverflow.com/questions/40126734/set-clr-support-to-true-with-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!