How to patch CMake generated Visual Studio project files - visual-studio-2010

Is there any way in CMake how to call a command that changes the generated .vcxproj files?
I want to patch some things within the auto generated files.
The problem is !when! to call such a tool within the cmake generation process.

Related

How to commit a project to SVN which has absolute paths from cmake build? [duplicate]

I am able to CMake build this HelloWorld example project using cmakelists.txt file and generate a visual studio project.
project(helloworld LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5)
find_package(Idlpp-cxx REQUIRED)
if (NOT TARGET CycloneDDS-CXX::ddscxx)
find_package(CycloneDDS-CXX REQUIRED)
endif()
# Convenience function, provided by the Idlpp-cxx that generates a CMake
# target for the given IDL file. The function calls Idlcpp-cxx to generate
# source files and compiles them into a library.
idl_ddscxx_generate(ddscxxHelloWorldData_lib "HelloWorldData.idl")
add_executable(ddscxxHelloworldPublisher publisher.cpp)
add_executable(ddscxxHelloworldSubscriber subscriber.cpp)
# Link both executables to idl data type library and ddscxx.
target_link_libraries(ddscxxHelloworldPublisher ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
target_link_libraries(ddscxxHelloworldSubscriber ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
set_property(TARGET ddscxxHelloworldPublisher PROPERTY CXX_STANDARD 11)
set_property(TARGET ddscxxHelloworldSubscriber PROPERTY CXX_STANDARD 11)
I need to create the same project without cmakelists.txt and CMake
How to do this only using visual studio? where to define those commands in CMakelists.txt in visual studio if I create an empty c++ project
I have tried this making an empty project.
I don't know how to idl_ddscxx_generate and target_link_libraries perform in VS....
idl_ddscxx_generate has to run if IDL file has changed
target_link_libraries is required if I added new source files to the project....
Make a new, empty Visual Studio project.
Copy all source files except the CMake files.
Do whatever you do in a Visual Studio project. Add files, targets, dependecies, … If you are not sure, look up what is written in the CMakeLists.txt file.
Delete all CMake files in your original project and copy your Visual Studio project files.
Add these changes (deleted CMake files, added VS project files) to your Subversion repository, maybe do this in a branch that others can test it, report back, and improve the change. Once done, merge the branch.
Probably, add step 0.: Learn how Visual Studio organizes its project. Make a tutorial, take some training.
Remark: Whatever your problem is with CMake, you missed something. But you can find this out later and revert your changes and pick up CMake up again.

Visual Studio project built with cmake displays "File Modification Detected"

The Visual Studio 2019 project, which was built via cmake displays
File Modification Detected
The project ABC has been modified outside the environment
Reload ... Ignore ...
message.
How can I prevent cmake from updating the VS config files, for the project or system wide?
In what section of the cmake build files this behavior is defined (so that I can rebuild the project without this feature)?
No, you cannot prevent this (afaik). Consider the scenario where you add a source file to a target in a CMakeLists.txt file. CMake needs to update the Visual Studio project files it generated which results in project file(s) being overwritten. CMake sets up the solution in a way to ensure such an update on a modification of the cmake files. Visual Studio reacts to the solution/project files being overwritten by displaying the dialog you mentioned.
In general you'll want to click "Reload" which should just update the projects according to the modification in the cmake sources. If for a command line build tool shows up though, you may want to select "Ignore" though, since sometimes the build output is deleted on a reload of projects/the solution and you'll probably want to check the error message.
If you're interested: Overriding the project files happens in the ZERO_CHECK target.
If the dialog is displayed on a build even if you did not modify the cmake files since the last build, you may want to check the console for a warning in the output of cmake though; this may indicate that there may be some issue in your cmake files...

CMake run shell command after building error

I have a Visual Studio 2019 CMake project and i need to run a postbuild script which copys a file (The file is not generated by the build process). What i did so far is add a custom command in CMake with
add_custom_command(TARGET testExec POST_BUILD COMMAND "../postbuild.bat")
The postbuild.bat would copy the file. This works great most of the time but when my build fails due to some compile error, the postbuild script won't be executed.
How can i run the postbuild script even if the build fails ? I know there is a similar question here but sadly no proper solution. If there is a way to configure a postbuild event directly inside a Visual Studio CMake project this would also be suitable, but it seems like this is not possible (because in a cmake project i don't have a project file).
Since The copied file is not generated by the build you can use PRE_BUILD. On Visual Studio Generators, it runs before any other rules are executed within the target.(https://cmake.org/cmake/help/latest/command/add_custom_command.html).
The other solution could be to use add_custom_command(OUTPUT as the file seems independent of the build.

Generate Visual Studio Project File to build a library with qmake syntax and where to find the project file?

I have an old script to create Visual Studio Project Files to build libraries. The syntax is
cd Kernel
cd core
qmake -t vclib
cd ccMigration
qmake -t vclib
cd ..
and so on for all of the different directories.
I understand why we use qmake and vclib, but what I am not sure is what is the use of -t in this line:
qmake -t vclib
Looking at this : http://doc.qt.io/archives/qt-5.5/qmake-platform-notes.html it says:
Creating Visual Studio Project Files This section describes how to
import an existing qmake project into Visual Studio. qmake is able to
take a project file and create a Visual Studio project that contains
all the necessary information required by the development environment.
This is achieved by setting the qmake project template to either vcapp
(for application projects) or vclib (for library projects).
This can also be set using a command line option, for example:
qmake -tp vc
Why do they use -tp and is the old script syntax correct by using -t?
After I run the script it takes about 1/2 seconds and where can I find the project files for Visual Studio?
Finally, When I open the project files how can I build a library using Visual Studio? Can someone point me to a place where I can read some material?
Thank you for all the help!
Edit: I ran the script and it created .vcproj files in the directories that qmake was run. Example: In folder Kernel -> core it created ccCore.vcproj project file. When I open the file in Visual Studio 2017 it wanted me to perform a One-way upgrade that will automatically make functional changes to the project in order to open it. Is this okay?

How to debug cmake target after install

I have a cross-platform project which uses cmake in order to generate Visual Studio solution files. The project has external dependencies (.dlls, resources etc) and the only place where the executable can be run is the installation directory. In that directory I have access all the resources, plugins, translations etc. I can install the project both in debug or release in that directory.
How can I debug a project in the installed location?
There are two problems with this case:
Sometimes I may debug the main application (Main.exe) (a target in cmake project)
Sometimes I may debug some plugins that Main.exe loads when started (I have a different cmake project for the plugins)
Is there a clean way of doing this in Visual C++ without actually create some custom project that is configured to start each time the Main.exe from the installed location? ("C:\Program Files\MainProject\Main.exe" )
Thank you,
Iulian
I managed to do it by 'configuring' with cmake a .user file for the specified project.
The only thing that the user needs to do is to use a template like in this bitbucket project.
In the project you can find a template file.
The cmake script command needed is:
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/scripts/windows/VS201x_Template.vcxproj.user.in"
"${PROJECT_BINARY_DIR}/INSTALL.vcxproj.user"
)
If you need a custom .user file you can always do it manually by saving the generated Visual Studio and creating a template from it similarly to the above example.

Resources