# How to install component libraries like boost?

**URL:** https://discourse.cmake.org/t/how-to-install-component-libraries-like-boost/2854
**Category:** Usage
**Created:** [February 26, 2021, 11:12pm UTC](https://discourse.cmake.org/t/how-to-install-component-libraries-like-boost/2854 "2021-02-26T23:12:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 26, 2021, 11:12pm UTC](https://discourse.cmake.org/t/how-to-install-component-libraries-like-boost/2854/1 "2021-02-26T23:12:39Z")

</div>

## 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](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html?highlight=components#adding-components)

This result is this `cmake config package` installed:

```bash
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:

```bash
+ 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](https://github.com/TheLartians/PackageProject.cmake/issues/22)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 27, 2021, 10:44am UTC](https://discourse.cmake.org/t/how-to-install-component-libraries-like-boost/2854/2 "2021-02-27T10:44:38Z")

</div>

It woks, I had to change my `Config.cmake.in` file!

Result in this:

```cmake

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was Config.cmake.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

if(COMPONET_TARGETS_ENABLED)
  set(_supported_components Addition SquareRoot MathFunctions)

  foreach(_comp ${MathFunctions_FIND_COMPONENTS})
    if(NOT _comp IN_LIST _supported_components)
      set(MathFunctions_FOUND False)
      set(MathFunctions_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
    endif()
    include("${CMAKE_CURRENT_LIST_DIR}/MathFunctions${_comp}Targets.cmake")
  endforeach()
else()
  include("${CMAKE_CURRENT_LIST_DIR}/MathFunctionsTargets.cmake")
endif()

```
