简体   繁体   中英

CMake specifying Native Build System Options in CMakeLists.txt(managed C++ Project)

i got stuck with a problem which has to do with a managed c++ Project.

Currently we have a working Build and we are about to use CMake to generate our Solution Files in the future.

In our solution we have some Managed C++ Project and C# Projects. I tried to generate/build the Managed C++ Projects and it works. But there is one key thing that is different which atually breaks the build.

In our working build the managed C++ Project has the Xml Tag <TargetFrameworkVersion> but when I use CMake to configure/generate the Project I end up having <TargetFramework> and this breaks the build ( I confirmed by manually changing the Tag).

I got stuck with this Problem for 2 days and the following things I already tried:

  • I tried setting VS_DOTNET_TARGET_FRAMEWORK_VERSION which actually is deprecated but makes sense because of the name. I ended up having in the Project file.
  • I also tried the newer Variables DOTNET_TARGET_FRAMEWORK, DOTNET_TARGET_FRAMEWORK_VERSION but I ended up again with in the Project file.
  • I thought to myself I could change the Project file after I configure/generate but thats pretty hacky (but works)

There is a second solution which actually works but is not what I really want. I can tell cmake.exe to pass some options to the native MsBuild tool to build the managed C++ target. This works but I would prefer to some how tell the CMakeLists.txt to do this or even better have the right Xml tag when generating the Proect files because we don't want to use the command line when building our projects.

The approach looks like this (Target Name is NotifierLib and .NET Framework Version is 4.7.2)

cmake --build . --target NotifierLib -- /p:TargetFrameworkVersion=v4.7.2

Did anyone came across this exact issue? Or maybe has an idea how to solve this via CMakeLists.txt?

Thanks in advance.

I finally came to a pretty Solution which was there initially.

This post helped my to get on the right Track: How can cmake add custom entry in a project's vcxproj PropertyGroup?

Basically I don't need to iterate over the .xml File myself to edit the Tag. I can tell CMake to set it for me as a global option with:

set_target_properties(NotifierLib PROPERTIES VS_GLOBAL_TargetFrameworkVersion "v4.7.2")

This way the initial <TargetFramework> Tag is still in the .xml File but it does not bother because it is not being used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM