Project not built when I specify exclude_from_default_build in CMake

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Project not built when I specify exclude_from_default_build in CMake

Haferburg, Andreas

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 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?





Follow this link to read our Privacy Statement

Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: