# After update from FindBoost to BoostConfig (policy 0167), how to convert library targets to paths

**URL:** <https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431>\
**Category:** Code\
**Created:** [January 19, 2025, 5:25pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431 "2025-01-19T17:25:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 19, 2025, 5:25pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/1 "2025-01-19T17:25:30Z")

</div>

We changed policy 0167 from OLD to NEW, which means we are now using BoostConfig.cmake from Boost instead of the FindBoost module from CMake.

This has the side effect that `Boost_LIBRARIES` changed from `/usr/lib/x86_64-linux-gnu/libboost_iostreams.so` to `Boost::iostreams`, and similar for all other components.

This breaks a `configure_file` command that we need for deployment to MacOS.

How to convert the target `Boost::iostreams` to the corresponding library path?

I saw the generating expression `$<TARGET_FILE:tgt>`, but couldn’t get it to be expanded in the right moment.

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [January 20, 2025, 2:49pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/2 "2025-01-20T14:49:44Z")

</div>

`$<TARGET_FILE:tgt>` should indeed be the way to go. Of course, as a generator expression, it can only be expanded at generate time — when CMake is done reading all `CMakeLists.txt` files and is working on _generating_ the buildsystem from them. Nevertheless, for all things which are needed at build time or later, this should be workable.

The basic command to look into would be [`file(GENERATE)`](https://cmake.org/cmake/help/latest/command/file.html#generate). This can even be combined with `configure_file()` in a two step configure–generate process. If you share the code and purpose of your configured file, we might be able to provide more detailed advice.

---

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 20, 2025, 3:00pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/3 "2025-01-20T15:00:44Z")

</div>

Thank you, Petr.

Our code is open source; the code line in question is here [1]. But it’s terribly complicated: a C++/Python project to be deployed to macOS. Anyway, the line in question essentially says

```auto
configure(${lib} ${output_directory} COPYONLY)

```

Maybe the `COPYONLY` simplifies things: couldn’t we just _replace_ the statement by a `file(GENERATE ...)` statement?

[1] [cmake/multipython · main · mlz / BornAgain · GitLab](https://jugit.fz-juelich.de/mlz/bornagain/-/tree/main/cmake/multipython?ref_type=heads#L103)

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [January 20, 2025, 3:09pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/4 "2025-01-20T15:09:22Z")

</div>

Yes, that sounds like directly using `file(GENERATE)` might work.

---

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 20, 2025, 5:58pm UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/5 "2025-01-20T17:58:14Z")

</div>

`file(GENERATE OUTPUT "${output_dir}/???" INPUT $<TARGET_FILE:${lib}>)`

- For the OUTPUT argument, how to extract just the file name `libboost_iostreams.dylib` (without preceding directory path) from the target?
- For the INPUT argument, how can this work as the docs do not mention support for generating expressions?

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [January 21, 2025, 10:28am UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431/6 "2025-01-21T10:28:31Z")

</div>

Oh, I thought you were referring to the files inside a configured file, I didn’t realise you were configuring the files themselves.

Would it be OK for you if the copying happened at build time instead of at CMake time? If so, you can use `file(GENERATE)` to create a script which will do the copying (you can use a construct such as `${CMAKE_COMMAND} -E copy ...`), and then run the script as a custom target or custom command.
