diff --git a/cth_install_utilities.cmake b/cth_install_utilities.cmake index 1685e34..c6b763f 100644 --- a/cth_install_utilities.cmake +++ b/cth_install_utilities.cmake @@ -620,6 +620,11 @@ function(_cth_add_pkg_target) add_executable(${INSTALL_TARGET_NAME} ${PKG_DUMMY_SOURCE}) endif() + # a parent project that adds this project with add_subdirectory() does not install it on every build + if(NOT PROJECT_IS_TOP_LEVEL) + set_target_properties(${INSTALL_TARGET_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() + # --- guard: packaging into the default install prefix is almost never intended --- set(PKG_GUARD_SCRIPT "${CMAKE_BINARY_DIR}/_pkg_prefix_guard.cmake") set(PKG_PREFIX_IS_DEFAULT FALSE) @@ -668,6 +673,8 @@ endfunction() .. note:: After calling this, build the ``${PROJECT_NAME}_package`` target to create the package. + Only the top level project builds it with ``all``, a parent project that adds this project with + ``add_subdirectory()`` does not install it on every build. .. note:: **Consumer usage:** ``find_package(${PROJECT_NAME} CONFIG REQUIRED COMPONENTS ...)`` diff --git a/cth_setup_utilities.cmake b/cth_setup_utilities.cmake index d671a76..ee442d0 100644 --- a/cth_setup_utilities.cmake +++ b/cth_setup_utilities.cmake @@ -1,6 +1,8 @@ # Copyright (c) 2026 Lukas Thomann # Licensed under the MIT License +include(cth_assertions) + #[[.rst: .. command:: cth_set_compiler_specifics @@ -78,4 +80,59 @@ macro(cth_set_latest_c_cpp_standard) set(CMAKE_CXX_EXTENSIONS OFF) message("Set cxx standard to ${CMAKE_CXX_STANDARD}") -endmacro() \ No newline at end of file +endmacro() + +#[=[.rst: +.. command:: cth_add_subdirectory + + .. code-block:: cmake + + cth_add_subdirectory( [