jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.09k stars 1.83k forks source link

CMake build has targets that cannot be disabled #1158

Closed prybicki closed 1 year ago

prybicki commented 1 year ago

I am using yaml-cpp in my project using FetchContent. I noticed that Makefile is polluted with targets such as:

# Target rules for targets named ContinuousMemCheck

# Build rule for target.
ContinuousMemCheck: cmake_check_build_system
        $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 ContinuousMemCheck
.PHONY : ContinuousMemCheck

# fast build rule for target.
ContinuousMemCheck/fast:
        $(MAKE) $(MAKESILENT) -f CMakeFiles/ContinuousMemCheck.dir/build.make CMakeFiles/ContinuousMemCheck.dir/build
.PHONY : ContinuousMemCheck/fast

This causes CMake-based IDE such as CLion to show irrelevant targets:

image

I have attempted to silence this down by:

set(YAML_CPP_BUILD_TESTS OFF CACHE INTERNAL "Disable yaml-cpp artifacts")
set(YAML_CPP_BUILD_CONTRIB OFF CACHE INTERNAL "Disable yaml-cpp artifacts")
set(YAML_CPP_BUILD_TOOLS OFF CACHE INTERNAL "Disable yaml-cpp artifacts")
set(YAML_CPP_INSTALL OFF CACHE INTERNAL "Disable yaml-cpp artifacts")
set(YAML_CPP_FORMAT_SOURCE OFF CACHE INTERNAL "Disable yaml-cpp artifacts")

This works partially - e.g. yaml-cpp-parse disappears as expected, but targets Continuous, Experimental, Nightly* remain. Any ideas on how these targets can be disabled?

sayo9394 commented 1 year ago

I've had this issue in a separate project when I updated CMake on my machine. You should be able to prevent those from being created by doing set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) in your CMake, before calling enable_testing().

prybicki commented 1 year ago

Thanks, @sayo9394, it worked for me. Adding it just before enable_testing() did not work, but putting it in just after project(...) and before including dependencies (find_package(...) and add_subdirectory(...)) worked perfectly.