From 1cb8a5a8a54148ca64464aa121e176c5b3f5950c Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Mon, 23 Dec 2024 11:47:34 +0100 Subject: [PATCH] feat: URI keyword also sets EXCLUDE_FROM AND SYSTEM --- cmake/CPM.cmake | 2 +- test/integration/test_simple.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 188980dd..65291a36 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -626,7 +626,7 @@ function(CPMAddPackage) list(REMOVE_AT ARGN 0 1) # remove "URI gh:<...>@version#tag" cpm_parse_add_package_single_arg("${ARGV1}" ARGV0) - set(ARGN "${ARGV0};${ARGN}") + set(ARGN "${ARGV0};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;${ARGN}") endif() cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") diff --git a/test/integration/test_simple.rb b/test/integration/test_simple.rb index d7acd6e2..14bed174 100644 --- a/test/integration/test_simple.rb +++ b/test/integration/test_simple.rb @@ -110,12 +110,42 @@ def test_update_single_package # * using-adder - for this project # ...and notably no test for adder, which must be disabled from the option override from above assert_equal ['simple', 'using-adder'], exes + } + update_with_option_on_and_build_with_uri_shorthand_syntax_and_exclude_from_override = -> { + prj.create_lists_from_default_template package: <<~PACK + CPMAddPackage( + URI gh:cpm-cmake/testpack-adder@1.0.0 + OPTIONS "ADDER_BUILD_TESTS ON" + EXCLUDE_FROM_ALL NO + ) + PACK + assert_success prj.configure + assert_success prj.build + + exe_dir = File.join(prj.bin_dir, 'bin') + assert File.directory? exe_dir + exes = Dir[exe_dir + '/**/*'].filter { + # on multi-configuration generators (like Visual Studio) the executables will be in bin/ + # also filter-out other artifacts like .pdb or .dsym + !File.directory?(_1) && File.stat(_1).executable? + }.map { + # remove .exe extension if any (there will be one on Windows) + File.basename(_1, '.exe') + }.sort + + # we should end up with two executables + # * simple - the simple example from adder + # * using-adder - for this project + # ...and notably no test for adder, which must be disabled from the option override from above + assert_equal ['simple', 'test-adding', 'using-adder'], exes } + create_with_commit_sha.() update_to_version_1.() update_with_option_off_and_build.() update_with_option_off_and_build_with_uri_shorthand_syntax.() + update_with_option_on_and_build_with_uri_shorthand_syntax_and_exclude_from_override.() end end