# Code

**URL:** https://discourse.cmake.org/c/code/11.md?page=1

[Latest](https://discourse.cmake.org/latest.md) · [Categories](https://discourse.cmake.org/categories.md) · [Tags](https://discourse.cmake.org/tags.md)

**Page:** 2

---

## [How to force that CMAKE\_TOOLCHAIN\_FILE is an absolute file path?](https://discourse.cmake.org/t/how-to-force-that-cmake-toolchain-file-is-an-absolute-file-path/15670)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 3\
**Last updated:** [May 27, 2026, 7:50pm UTC](https://discourse.cmake.org/t/how-to-force-that-cmake-toolchain-file-is-an-absolute-file-path/15670 "2026-05-27T19:50:38Z")

</div>

I use this code to check if the installed cmake config package is usable: if(BEMAN\_SCOPE\_INSTALL\_CONFIG\_FILE\_PACKAGE) # test if the targets are usable from the install directory add\_test( NAME install-to…

---

## [using external Libraries](https://discourse.cmake.org/t/using-external-libraries/15665)

<div class="topic-metadata">

**Author:** [@pedahl](https://discourse.cmake.org/u/pedahl)\
**Replies:** 1\
**Last updated:** [May 27, 2026, 1:45pm UTC](https://discourse.cmake.org/t/using-external-libraries/15665 "2026-05-27T13:45:27Z")

</div>

Hi, i have a project with a lot of external lib (Windows; dll files). I have build for every Library (most of the libraries have many dll) a Config.cmake file, with a component for every .dll and in the projects and su…

---

## [find\_package() / How to make coexist different versions of Boost ?](https://discourse.cmake.org/t/find-package-how-to-make-coexist-different-versions-of-boost/15643)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 2\
**Last updated:** [May 11, 2026, 6:20am UTC](https://discourse.cmake.org/t/find-package-how-to-make-coexist-different-versions-of-boost/15643 "2026-05-11T06:20:16Z")

</div>

Hello, I am on Windows, and want to be able to choose in my projects among several versions of Boost and toolsets. Due to this variability, it seems I cannot use Boost\_ROOT. How should I structure and declare the Boost…

---

## [Correct way to set required linker-only arguments in toolchain](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647)

<div class="topic-metadata">

**Author:** [@DanShaders](https://discourse.cmake.org/u/DanShaders)\
**Replies:** 2\
**Last updated:** [May 10, 2026, 5:55pm UTC](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647 "2026-05-10T17:55:11Z")

</div>

I have a toolchain file which needs to set -rtlib=compiler-rt as a “required” linker flag (i. e. without it, the toolchain will either not work or silently generate broken code). As far as I can tell, I have a couple opt…

---

## [Experimental SBOM: Statically linked dependencies show up as "Shared"](https://discourse.cmake.org/t/experimental-sbom-statically-linked-dependencies-show-up-as-shared/15648)

<div class="topic-metadata">

**Author:** [@Mythra](https://discourse.cmake.org/u/Mythra)\
**Replies:** 0\
**Last updated:** [May 9, 2026, 7:02pm UTC](https://discourse.cmake.org/t/experimental-sbom-statically-linked-dependencies-show-up-as-shared/15648 "2026-05-09T19:02:25Z")

</div>

I’m attempting to test out the new experimental SBOM generation feature, and it seems I have statically linked libraries showing up as “shared” libraries in the generated SPDX. I know this feature is experimental, but be…

---

## [How to get macOS/iOS framework root directory at install time?](https://discourse.cmake.org/t/how-to-get-macos-ios-framework-root-directory-at-install-time/15640)

<div class="topic-metadata">

**Author:** [@emaschino](https://discourse.cmake.org/u/emaschino)\
**Replies:** 1\
**Last updated:** [May 7, 2026, 3:39pm UTC](https://discourse.cmake.org/t/how-to-get-macos-ios-framework-root-directory-at-install-time/15640 "2026-05-07T15:39:13Z")

</div>

Hi, Let’s have a cross-platform command-line test application TestApp. This app depends on OpenCV, built as a dynamic framework on Apple. To install the app and runtime dependencies, I have: install(TARGETS TestApp …

---

## [How can I link the graphviz library into my project which is a plugin library for the kate texteditor ?](https://discourse.cmake.org/t/how-can-i-link-the-graphviz-library-into-my-project-which-is-a-plugin-library-for-the-kate-texteditor/15639)

<div class="topic-metadata">

**Author:** [@David](https://discourse.cmake.org/u/David)\
**Replies:** 2\
**Last updated:** [May 4, 2026, 1:42pm UTC](https://discourse.cmake.org/t/how-can-i-link-the-graphviz-library-into-my-project-which-is-a-plugin-library-for-the-kate-texteditor/15639 "2026-05-04T13:42:02Z")

</div>

Hello, How can I link the graphviz library into my project which is a plugin library for the kate texteditor ? This doesn’t work: -lgvc -lcgraph -lcdt SET(GCC\_COVERAGE\_LINK\_FLAGS “-lgvc -lcgraph -lcdt”) SET(CMAKE\_CXX\_…

---

## [Beginner: Difficulty understanding CMake impact on include statements](https://discourse.cmake.org/t/beginner-difficulty-understanding-cmake-impact-on-include-statements/15404)

<div class="topic-metadata">

**Author:** [@zlime](https://discourse.cmake.org/u/zlime)\
**Replies:** 6\
**Last updated:** [April 29, 2026, 2:29am UTC](https://discourse.cmake.org/t/beginner-difficulty-understanding-cmake-impact-on-include-statements/15404 "2026-04-29T02:29:05Z")

</div>

Greetings! This is my first post. I am new to writing CMake, and am currently updating a legacy build system. Assume a directory structure like this: A |-CMakeLists.txt |-B | |-CMakeLists.txt | |-some\_class\_in\_B.h | |-s…

---

## [How to set Release mode directly in CMakeLists.txt / CMakePresets.json? "Visual Studio 18 2026", vcpkg, case example with library "google/benchmark"](https://discourse.cmake.org/t/how-to-set-release-mode-directly-in-cmakelists-txt-cmakepresets-json-visual-studio-18-2026-vcpkg-case-example-with-library-google-benchmark/15635)

<div class="topic-metadata">

**Author:** [@codev](https://discourse.cmake.org/u/codev)\
**Replies:** 2\
**Last updated:** [April 28, 2026, 10:04pm UTC](https://discourse.cmake.org/t/how-to-set-release-mode-directly-in-cmakelists-txt-cmakepresets-json-visual-studio-18-2026-vcpkg-case-example-with-library-google-benchmark/15635 "2026-04-28T22:04:22Z")

</div>

What would be the way to specify the compilation in Release mode when working with CMake, ideally in “CMakeLists.txt”, but if not then in “CMakePresets.json”. Looking for a solution mainly without commands because this …

---

## [NSIS CPack generator forcibly overwrites $INSTDIR to $DOCUMENTS for per-user JustMe installs](https://discourse.cmake.org/t/nsis-cpack-generator-forcibly-overwrites-instdir-to-documents-for-per-user-justme-installs/15632)

<div class="topic-metadata">

**Author:** [@Nyoma\_Diamond](https://discourse.cmake.org/u/Nyoma_Diamond)\
**Replies:** 0\
**Last updated:** [April 27, 2026, 2:17pm UTC](https://discourse.cmake.org/t/nsis-cpack-generator-forcibly-overwrites-instdir-to-documents-for-per-user-justme-installs/15632 "2026-04-27T14:17:10Z")

</div>

Hiya I’ve run into an issue with using the NSIS generator for CPack where it’s not possible to change the default install location for per-user JustMe installs. Specifically, if you wanted to change the default per-user…

---

## [Hybrid CUDA runtime linking](https://discourse.cmake.org/t/hybrid-cuda-runtime-linking/15607)

<div class="topic-metadata">

**Author:** [@Krabbys](https://discourse.cmake.org/u/Krabbys)\
**Replies:** 0\
**Last updated:** [April 19, 2026, 7:42pm UTC](https://discourse.cmake.org/t/hybrid-cuda-runtime-linking/15607 "2026-04-19T19:42:14Z")

</div>

Hello, since CUDA Toolkit version 13.2 linking with the flag -cudart=shared is deprecated on Windows and has been replaced with -cudart=hybrid. From the nvidia docs: How can I set the flag with CMake? Before I would …

---

## [Change in string / regex behavior with cmake 4.3](https://discourse.cmake.org/t/change-in-string-regex-behavior-with-cmake-4-3/15597)

<div class="topic-metadata">

**Author:** [@opoplawski](https://discourse.cmake.org/u/opoplawski)\
**Replies:** 2\
**Last updated:** [April 15, 2026, 1:13am UTC](https://discourse.cmake.org/t/change-in-string-regex-behavior-with-cmake-4-3/15597 "2026-04-15T01:13:53Z")

</div>

A package I’m building has: FILE(STRINGS "${\_H5\_I\_PUB\_ABS\_PATH}" \_h5\_i\_pub\_contents) FOREACH(\_line IN LISTS \_h5\_i\_pub\_contents) SET(\_match) STRING(REGEX MATCH "^\[ \\t\]\*typedef .\*hid\_t.\*" \_matc…

---

## [\_autogen "targets" setting the folder property](https://discourse.cmake.org/t/autogen-targets-setting-the-folder-property/15598)

<div class="topic-metadata">

**Author:** [@scottaronbloom](https://discourse.cmake.org/u/scottaronbloom)\
**Replies:** 2\
**Last updated:** [April 9, 2026, 11:51pm UTC](https://discourse.cmake.org/t/autogen-targets-setting-the-folder-property/15598 "2026-04-09T23:51:43Z")

</div>

Running CMake 4.3 + Qt 6.11 and Im running into a problem with folders. I already have a function that starts at the CMAKE\_SOURCE\_DIR finds every subdirectory via the SUBDIRECTORIES property, and sets the folder propert…

---

## [Issues with transitive usage of C++ Modules](https://discourse.cmake.org/t/issues-with-transitive-usage-of-c-modules/15586)

<div class="topic-metadata">

**Author:** [@Nukular1](https://discourse.cmake.org/u/Nukular1)\
**Replies:** 1\
**Last updated:** [April 8, 2026, 8:36pm UTC](https://discourse.cmake.org/t/issues-with-transitive-usage-of-c-modules/15586 "2026-04-08T20:36:16Z")

</div>

Hi, I’ve been experimenting with the current C++20 modules implementation lately in CMake 4.3 and ran into some issues when consuming modules transitively, across multiple intermediate (imported) library targets. It’s v…

---

## [How to make message logs prettier, more coherent](https://discourse.cmake.org/t/how-to-make-message-logs-prettier-more-coherent/15596)

<div class="topic-metadata">

**Author:** [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Replies:** 1\
**Last updated:** [April 7, 2026, 2:19pm UTC](https://discourse.cmake.org/t/how-to-make-message-logs-prettier-more-coherent/15596 "2026-04-07T14:19:02Z")

</div>

Hi all I have outputs from my build that look like this build\] C:/msc\_file\_explorer/msc\_file\_explorer/tusb\_config/tusb\_config.h:54:9: warning: “CFG\_TUSB\_DEBUG” redefined \[build\] 54 | #define CFG\_TUSB\_DEBUG 2 \[bu…

---

## [Intellisense not detecting standard libraries in Visual Studio](https://discourse.cmake.org/t/intellisense-not-detecting-standard-libraries-in-visual-studio/15571)

<div class="topic-metadata">

**Author:** [@shrink\_tubing](https://discourse.cmake.org/u/shrink_tubing)\
**Replies:** 5\
**Last updated:** [April 5, 2026, 6:05pm UTC](https://discourse.cmake.org/t/intellisense-not-detecting-standard-libraries-in-visual-studio/15571 "2026-04-05T18:05:54Z")

</div>

Hi, Frequently when opening a cmake project in visual studio there’s a bug where intellisense cannot recognize some of the C++ standard libraries. I have found a workaround, if I intentionally break my CMakePresets.json…

---

## [Why is my variable at the top most cmakelist not propogating to an add\_subdirectory](https://discourse.cmake.org/t/why-is-my-variable-at-the-top-most-cmakelist-not-propogating-to-an-add-subdirectory/15590)

<div class="topic-metadata">

**Author:** [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Replies:** 2\
**Last updated:** [April 3, 2026, 2:47pm UTC](https://discourse.cmake.org/t/why-is-my-variable-at-the-top-most-cmakelist-not-propogating-to-an-add-subdirectory/15590 "2026-04-03T14:47:32Z")

</div>

Hi all In my top most CMakeList.txt, I have defined a a varible as \\ set(PICO\_SDK\_PATH "H:/pico\_sdk" CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) and have called an add\_subdirectory(Pico-PIO-USB) and have de…

---

## [WINDOWS\_EXPORT\_ALL\_SYMBOLS Exports symbol "\_\_"](https://discourse.cmake.org/t/windows-export-all-symbols-exports-symbol/9797)

<div class="topic-metadata">

**Author:** [@YusakuGodai](https://discourse.cmake.org/u/YusakuGodai)\
**Replies:** 6\
**Last updated:** [March 25, 2026, 1:19pm UTC](https://discourse.cmake.org/t/windows-export-all-symbols-exports-symbol/9797 "2026-03-25T13:19:25Z")

</div>

I’m using CMake’s WINDOWS\_EXPORT\_ALL\_SYMBOLS property on a long existing codebase that has historically been a static library but I’m hoping to convert it quickly into a DLL (even if just temporarily). This option seems …

---

## [Unable to build Eigen & OpenXLSX on windows](https://discourse.cmake.org/t/unable-to-build-eigen-openxlsx-on-windows/10868)

<div class="topic-metadata">

**Author:** [@Shepard](https://discourse.cmake.org/u/Shepard)\
**Replies:** 2\
**Last updated:** [March 19, 2026, 11:27am UTC](https://discourse.cmake.org/t/unable-to-build-eigen-openxlsx-on-windows/10868 "2026-03-19T11:27:22Z")

</div>

Well, I’m working on a C++ project where I am using linear algebra from Eigen. This is how I fetch the Eigen library from my root CmakeLists.txt: message(\[STATUS\] "Fetching eigen.") block(SCOPE\_FOR VARIABLES) set(E…

---

## [Having difficulty compiling with import std; support; cmake can't build std.cppm](https://discourse.cmake.org/t/having-difficulty-compiling-with-import-std-support-cmake-cant-build-std-cppm/15557)

<div class="topic-metadata">

**Author:** [@sebjames](https://discourse.cmake.org/u/sebjames)\
**Replies:** 10\
**Last updated:** [March 15, 2026, 8:41am UTC](https://discourse.cmake.org/t/having-difficulty-compiling-with-import-std-support-cmake-cant-build-std-cppm/15557 "2026-03-15T08:41:15Z")

</div>

Hi there, I’m looking for some help with a cmake-directed build of a C++ modules project containing import std; I’ve followed along with: https://www.kitware.com/import-std-in-cmake-3-30/ The sample provided there co…

---

## [add\_subdirectory() and target\_link\_libraries() ordering](https://discourse.cmake.org/t/add-subdirectory-and-target-link-libraries-ordering/15539)

<div class="topic-metadata">

**Author:** [@Diltsman](https://discourse.cmake.org/u/Diltsman)\
**Replies:** 7\
**Last updated:** [March 13, 2026, 5:40pm UTC](https://discourse.cmake.org/t/add-subdirectory-and-target-link-libraries-ordering/15539 "2026-03-13T17:40:24Z")

</div>

When writing a CMakeLists.txt file, I have always called target\_link\_libraries() with a list of targets that I am generating in other directories, then I call add\_subdirectory() to add the files that create the targets. …

---

## [Forcing a locally installed Boost to be used instead of the system-level one](https://discourse.cmake.org/t/forcing-a-locally-installed-boost-to-be-used-instead-of-the-system-level-one/15549)

<div class="topic-metadata">

**Author:** [@rwan](https://discourse.cmake.org/u/rwan)\
**Replies:** 12\
**Last updated:** [March 11, 2026, 11:44pm UTC](https://discourse.cmake.org/t/forcing-a-locally-installed-boost-to-be-used-instead-of-the-system-level-one/15549 "2026-03-11T23:44:01Z")

</div>

Hi all, I have been trying to get Boost working with CMake. What I did almost a year ago is detailed here: CMake with Boost and policy CMP0167 . And that still works, thankfully. :slight\_smile: There is just one pr…

---

## [Correctly link libraries with specific soname on linux](https://discourse.cmake.org/t/correctly-link-libraries-with-specific-soname-on-linux/15552)

<div class="topic-metadata">

**Author:** [@nickvdbroeck](https://discourse.cmake.org/u/nickvdbroeck)\
**Replies:** 1\
**Last updated:** [March 11, 2026, 1:56pm UTC](https://discourse.cmake.org/t/correctly-link-libraries-with-specific-soname-on-linux/15552 "2026-03-11T13:56:35Z")

</div>

My project uses other libraries on linux x86\_64. The other libraries are available as precompiled library files. Meaning I have a folder with 34 .so files. Most of these have full version numbers. For example: \`libgentl.…

---

## [INTERFACE library target and CXX\_MODULES file set](https://discourse.cmake.org/t/interface-library-target-and-cxx-modules-file-set/15550)

<div class="topic-metadata">

**Author:** [@matwey](https://discourse.cmake.org/u/matwey)\
**Replies:** 0\
**Last updated:** [March 10, 2026, 8:47am UTC](https://discourse.cmake.org/t/interface-library-target-and-cxx-modules-file-set/15550 "2026-03-10T08:47:01Z")

</div>

Hello, I am completely confused with correct usage of C++ modules and INTERFACE targets. Let me please first describe what I currently have and what I want to achieve. I have a project consisting multiple firmwares for…

---

## [Code injection at the end of the processing of each CMakeLists.txt file](https://discourse.cmake.org/t/code-injection-at-the-end-of-the-processing-of-each-cmakelists-txt-file/15541)

<div class="topic-metadata">

**Author:** [@nappl](https://discourse.cmake.org/u/nappl)\
**Replies:** 2\
**Last updated:** [March 9, 2026, 9:46am UTC](https://discourse.cmake.org/t/code-injection-at-the-end-of-the-processing-of-each-cmakelists-txt-file/15541 "2026-03-09T09:46:32Z")

</div>

Hi, We have a bit of a weird use-case where we occasionally need to inject code at the end of the processing of each CMakeLists.txt file. This extra CMake code is very bespoke and most of it we do not have any control o…

---

## [How best to handle installation of public headers in ${CMAKE\_INSTALL\_INCLUDEDIR} and a subdirectory thereof](https://discourse.cmake.org/t/how-best-to-handle-installation-of-public-headers-in-cmake-install-includedir-and-a-subdirectory-thereof/15525)

<div class="topic-metadata">

**Author:** [@MarkCallow](https://discourse.cmake.org/u/MarkCallow)\
**Replies:** 5\
**Last updated:** [March 5, 2026, 9:14am UTC](https://discourse.cmake.org/t/how-best-to-handle-installation-of-public-headers-in-cmake-install-includedir-and-a-subdirectory-thereof/15525 "2026-03-05T09:14:00Z")

</div>

I have a library with two public header files that need to be installed: one in ${CMAKE\_INSTALL\_INCLUDEDIR} and one in ${CMAKE\_INSTALL\_INCLUDEDIR}/SUBDIR. If I do set\_target\_properties(mylib PROPERTIES PUBLI…

---

## [Trouble with RPATH when building netcdf for Fedora](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532)

<div class="topic-metadata">

**Author:** [@opoplawski](https://discourse.cmake.org/u/opoplawski)\
**Replies:** 2\
**Last updated:** [March 4, 2026, 12:30am UTC](https://discourse.cmake.org/t/trouble-with-rpath-when-building-netcdf-for-fedora/15532 "2026-03-04T00:30:26Z")

</div>

I package netcdf for Fedora. I’m working on switching to cmake for building the project and having trouble with RPATHs ending up in installed files. Fedora forbids rpath in installed files. I get the following message…

---

## [How can I be sure that a C++20 module is not re-compiled after a non-module code change?](https://discourse.cmake.org/t/how-can-i-be-sure-that-a-c-20-module-is-not-re-compiled-after-a-non-module-code-change/15535)

<div class="topic-metadata">

**Author:** [@sebjames](https://discourse.cmake.org/u/sebjames)\
**Replies:** 11\
**Last updated:** [March 2, 2026, 6:38pm UTC](https://discourse.cmake.org/t/how-can-i-be-sure-that-a-c-20-module-is-not-re-compiled-after-a-non-module-code-change/15535 "2026-03-02T18:38:44Z")

</div>

Hi Cmakers, This is a question about compiling C++ code with modules. I’ve built an example that is based on some existing C++ code I have. The class is called sm::range . I have made a CMakeLists to compile an executa…

---

## [Problem with linking on static libraries](https://discourse.cmake.org/t/problem-with-linking-on-static-libraries/10665)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 4\
**Last updated:** [February 25, 2026, 8:11pm UTC](https://discourse.cmake.org/t/problem-with-linking-on-static-libraries/10665 "2026-02-25T20:11:07Z")

</div>

Hello, I have a simple library project, which consumes an other library, provided as a CMake installation configuration (throught a ZIP and a call to FetchContent). The question is at the end. Here is the files struct…

---

## [How to set policy version globally for \`cmake\_install.cmake\`](https://discourse.cmake.org/t/how-to-set-policy-version-globally-for-cmake-install-cmake/15528)

<div class="topic-metadata">

**Author:** [@huangqinjin](https://discourse.cmake.org/u/huangqinjin)\
**Replies:** 0\
**Last updated:** [February 24, 2026, 5:21pm UTC](https://discourse.cmake.org/t/how-to-set-policy-version-globally-for-cmake-install-cmake/15528 "2026-02-24T17:21:03Z")

</div>

I use if(PATH\_EQUAL) inside install(CODE) for custom install logic. But it trigger the error about Policy CMP0139 is not set. How the enable it globally for cmake\_install.cmake? Why does cmake\_install.cmake not use sam…

[Previous page](https://discourse.cmake.org/c/code/11.md)

[Next page](https://discourse.cmake.org/c/code/11.md?page=2)
