Can I get the GUID generated by CMake for a specific vcproj at the time of cmake?

Preamble: I'm trying to integrate my C # csproj with the rest of Cake and the C ++ / CLI code base. I received a recommendation against trying to do this because CMake does not interact well with .NET in Visual Studio, but after implementing some of the settings, I feel like I'm very close.

Part of my setup uses the configure_file command to edit the csproj file during CMake to customize it depending on the type of build (e.g. x86, x64) that happens.

The problem is that I am using ProjectReference tags to reference C ++ / CLI projects:

<ProjectReference Include="..\..\WrapperProject\WrapperProject.vcproj"> <Project>{7BD6E175-CDD1-4F8D-A3B2-0AC862E62C03}</Project> <Name>WrapperProject</Name> </ProjectReference> 

... and the GUIDs cannot remain static, as they change for the project whenever the CMake cache is rebuilt (correct me if I am wrong).

So, what I would like to do is find in CMake time what GUIDs are planned for these projects and edit the vcproj file accordingly.

Google tells me that people can use 'set_property' to set the GUID, for example:

 set_property(CACHE ${target_name}_GUID_CMAKE PROPERTY VALUE ${MY_GUID} ) 

... but I cannot find the getter equivalent. I tried things like this:

get_property (WRAPPER_GUID CACHE INTERNAL PROPERTY WrapperTargetName_GUID_CMAKE)

... no luck. Your help is appreciated!

+4
source share
2 answers

After that, I realized that Fraser noticed that this method does not always work, because I cannot expect the GUIDs to be available on a new CMake launch. So I went along the route that I saw on the CMake mailing list, which should explicitly indicate GUID values.

So in CMakeLists.txt for each C ++ / CLI shell project, I have something like this:

 # Set a global cache variable for this project GUID # The TestAppNet csproj needs this GUID to properly reference this project set_property(GLOBAL PROPERTY Wrapper_GUID "1897F4D1-E929-444E-9343-00F094113772") get_property(projectGUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting project GUID to: ${projectGUID}") set(Wrapper_GUID_CMAKE "${projectGUID}" CACHE INTERNAL "Project GUID") 

And in the CMakeLists.txt project in C #, I have this:

 get_property(CMAKE_WRAPPER_GUID GLOBAL PROPERTY Wrapper_GUID) MESSAGE( STATUS "Setting Wrapper GUID to: ${CMAKE_WRAPPER_GUID}" ) 

... and then CMAKE_WRAPPER_GUID is used as a variable in the .csproj file, which is populated with the configure_file command.

I'm not sure if this is effective, but it seems to work!

+4
source

Your syntax is slightly off. You probably meant:

 get_property(WRAPPER_GUID CACHE WrapperTargetName_GUID_CMAKE PROPERTY VALUE) 

However, this is a rather confusing way to get the value. You can simply:

 set(WRAPPER_GUID ${WrapperTargetName_GUID_CMAKE}) 

Finally, this is not ideal since the GUID is not available until CMake is first launched. So, for the new build tree, you will need to run CMake twice before it is useful.

+2
source

Source: https://habr.com/ru/post/1469290/


All Articles