[CMake] Project not built when I specify exclude_from_default_build in CMake

Haferburg, Andreas andreas.haferburg at stryker.com
Wed Oct 30 12:16:41 EDT 2019


Hi there

I build an executable A. I have set up another target A_remote that uses a custom launcher for remote debugging with Visual Studio. What I'm trying to achieve is that before the A_remote target is run, another target is run that deploys files to the remote computer. So I add a custom target run_deploy that runs a batch file, and make A_remote depend on it. As run_deploy also copies image files which aren't part of the VS solution, I want it to always run before launching A_remote.

However, when I build the entire solution, I don't want VS to build anything related to remote debugging, which is why I use EXCLUDE_FROM_DEFAULT_BUILD. But when I do that, and build A_remote, VS tells me

1>------ Skipped Build: Project: run_deploy, Configuration: Debug x64 ------
1>Project not selected to build for this solution configuration

Here's a sample CMakeLists.txt.

cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
file(WRITE main.cpp "int main(){return 0;}\n")
file(WRITE deploy.bat "echo Deploying!\n")
add_executable(A main.cpp)
add_executable(A_remote main.cpp)
add_custom_target(run_deploy "${CMAKE_SOURCE_DIR}/deploy.bat")
set_target_properties(run_deploy PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
add_dependencies(A_remote run_deploy)

The documentation https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.html says "Exclude target from Build Solution." This might have been the intention, but the way it is implemented seems to do more than that.

Anyways, how can I achieve that run_deploy is always built when I build A_remote, but not when I build the solution or ALL_BUILD? Is that even possible? Is there a workaround?

Cheers,
Andreas

Follow this link to read our Privacy Statement<https://www.stryker.com/content/stryker/gb/en/legal/global-policy-statement.html/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191030/1c186e3c/attachment.html>


More information about the CMake mailing list