The are at least 2 ways to do it.
1) One is to set NO_CHECK_REQUIRED_COMPONENTS_MACRO
It is recommended to set this option here https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html?highlight=components#adding-components
This result is this cmake config package
installed:
Claus-iMac:MathFunctionsComponents$ tree root/
root/
├── include
│ └── MathFunctions
│ ├── Addition.h
│ ├── MathFunctions.h
│ └── SquareRoot.h
└── lib
├── cmake
│ └── MathFunctions
│ ├── MathFunctionsAdditionTargets-debug.cmake
│ ├── MathFunctionsAdditionTargets.cmake
│ ├── MathFunctionsConfig.cmake
│ ├── MathFunctionsConfigVersion.cmake
│ ├── MathFunctionsMathFunctionsTargets-debug.cmake
│ ├── MathFunctionsMathFunctionsTargets.cmake
│ ├── MathFunctionsSquareRootTargets-debug.cmake
│ ├── MathFunctionsSquareRootTargets.cmake
│ ├── MathFunctionsTargets-debug.cmake
│ └── MathFunctionsTargets.cmake
├── libAddition-d.a
├── libMathFunctions-d.a
└── libSquareRoot-d.a
5 directories, 16 files
Claus-iMac:MathFunctionsComponents$
2) The other way is to NOT use NO_CHECK_REQUIRED_COMPONENTS_MACRO
I would prefer to have only one MathFunctionsTargets.cmake
installed like this:
+ cmake -S test -B build/test -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=root -DTEST_INSTALLED_VERSION=1
-- The CXX compiler identification is GNU 10.2.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-10 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
TEST_INSTALLED_VERSION
-- Build files have been written to: /Users/clausklein/Downloads/cmake/Help/guide/importing-exporting/MathFunctionsComponents/build/test
+ cmake --build build/test
[2/2] Linking CXX executable myexe
+ cmake --build build/test --target test
[0/1] Running tests...
Test project /Users/clausklein/Downloads/cmake/Help/guide/importing-exporting/MathFunctionsComponents/build/test
Start 1: myexe
1/1 Test #1: myexe ............................ Passed 0.32 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.32 sec
Claus-iMac:MathFunctionsComponents$ tree root/
root/
├── include
│ └── MathFunctions
│ ├── Addition.h
│ ├── MathFunctions.h
│ └── SquareRoot.h
└── lib
├── cmake
│ └── MathFunctions
│ ├── MathFunctionsConfig.cmake
│ ├── MathFunctionsConfigVersion.cmake
│ ├── MathFunctionsTargets-debug.cmake
│ └── MathFunctionsTargets.cmake
├── libAddition-d.a
├── libMathFunctions-d.a
└── libSquareRoot-d.a
5 directories, 10 files
Claus-iMac:MathFunctionsComponents$
see my result feature request: add support to install a component library like boost · Issue #22 · TheLartians/PackageProject.cmake · GitHub