# Code

**URL:** https://discourse.cmake.org/c/code/11.md

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

---

## [About the Code category](https://discourse.cmake.org/t/about-the-code-category/83)

<div class="topic-metadata">

**Author:** [@kwrobot](https://discourse.cmake.org/u/kwrobot)\
**Replies:** 0\
**Last updated:** [October 21, 2019, 6:21pm UTC](https://discourse.cmake.org/t/about-the-code-category/83 "2019-10-21T18:21:04Z")

</div>

Post for help writing CMake code in your projects or scripts. \[post via email\]

---

## [Will find\_package try multiple FindXxx.cmake modules after one returns Xxx\_Found=FALSE?](https://discourse.cmake.org/t/will-find-package-try-multiple-findxxx-cmake-modules-after-one-returns-xxx-found-false/15849)

<div class="topic-metadata">

**Author:** [@dbear496](https://discourse.cmake.org/u/dbear496)\
**Replies:** 1\
**Last updated:** [September 24, 2026, 1:04am UTC](https://discourse.cmake.org/t/will-find-package-try-multiple-findxxx-cmake-modules-after-one-returns-xxx-found-false/15849 "2026-09-24T01:04:01Z")

</div>

I’m in a situation where my project could have multiple directories in CMAKE\_MODULE\_PATH, and in those directories, there could be multiple Find\<package\>.cmake files for the same package. When find\_package(\<package\>) sea…

---

## [CPS export: giving different interface properties to CPS vs the CMake package from one build](https://discourse.cmake.org/t/cps-export-giving-different-interface-properties-to-cps-vs-the-cmake-package-from-one-build/15843)

<div class="topic-metadata">

**Author:** [@jobor](https://discourse.cmake.org/u/jobor)\
**Replies:** 3\
**Last updated:** [September 22, 2026, 6:29am UTC](https://discourse.cmake.org/t/cps-export-giving-different-interface-properties-to-cps-vs-the-cmake-package-from-one-build/15843 "2026-09-22T06:29:36Z")

</div>

We’re experimenting with making a large project (Qt) generate CPS files with install(PACKAGE\_INFO), alongside the usual Qt6\*Config.cmake package files, using CMake 4.4.3. Our main problem is generator expressions in int…

---

## [Does link scope have any effect for executables?](https://discourse.cmake.org/t/does-link-scope-have-any-effect-for-executables/15835)

<div class="topic-metadata">

**Author:** [@Wallby](https://discourse.cmake.org/u/Wallby)\
**Replies:** 1\
**Last updated:** [September 16, 2026, 10:02pm UTC](https://discourse.cmake.org/t/does-link-scope-have-any-effect-for-executables/15835 "2026-09-16T22:02:05Z")

</div>

I’ve seen people write all of the following: target\_link\_libaries(example someLibrary) target\_link\_libaries(example PRIVATE someLibrary) target\_link\_libaries(example PUBLIC someLibrary) Is there any difference between …

---

## [Ninja Multiconfig, compile\_commmands.db, and clang tools](https://discourse.cmake.org/t/ninja-multiconfig-compile-commmands-db-and-clang-tools/15838)

<div class="topic-metadata">

**Author:** [@Steve\_Downey](https://discourse.cmake.org/u/Steve_Downey)\
**Replies:** 1\
**Last updated:** [September 16, 2026, 7:12pm UTC](https://discourse.cmake.org/t/ninja-multiconfig-compile-commmands-db-and-clang-tools/15838 "2026-09-16T19:12:26Z")

</div>

The compile\_commands.db that is generated with multi config not unreasonably has commands for all of the configurations. This confuses clang tools, like clang-tidy and clangd, that parse the database. Running configure j…

---

## [Wrapping control structures with macros](https://discourse.cmake.org/t/wrapping-control-structures-with-macros/15834)

<div class="topic-metadata">

**Author:** [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)\
**Replies:** 0\
**Last updated:** [September 16, 2026, 8:28am UTC](https://discourse.cmake.org/t/wrapping-control-structures-with-macros/15834 "2026-09-16T08:28:27Z")

</div>

I’m implementing the processor of tests defined in JSON which are then turned into CTest definitions. (Whether this processor runs at configure-time or ctest-time doesn’t matter for now.) As such, there’s a non-negligabl…

---

## [How to prevent FetchContent to patch source packages again?](https://discourse.cmake.org/t/how-to-prevent-fetchcontent-to-patch-source-packages-again/15799)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 15\
**Last updated:** [September 14, 2026, 9:27pm UTC](https://discourse.cmake.org/t/how-to-prevent-fetchcontent-to-patch-source-packages-again/15799 "2026-09-14T21:27:47Z")

</div>

I have this code and it works fine to fetch a boost archive and apply needed patches. I also builds fine with my cmake workflow preset. # ---- Add Boost source tar archive via FetchContent ---- include(FetchContent) set…

---

## [Tutorial Step4 documentation error](https://discourse.cmake.org/t/tutorial-step4-documentation-error/15826)

<div class="topic-metadata">

**Author:** [@lostbits](https://discourse.cmake.org/u/lostbits)\
**Replies:** 3\
**Last updated:** [September 14, 2026, 7:16am UTC](https://discourse.cmake.org/t/tutorial-step4-documentation-error/15826 "2026-09-14T07:16:39Z")

</div>

Am I correct in saying that: Note VendorLib is an INTERFACE library, meaning it has no build requirements (because it has already been built). All of its properties should also be interface properties. and …

---

## [A method of writing that can handle file name changes.](https://discourse.cmake.org/t/a-method-of-writing-that-can-handle-file-name-changes/15825)

<div class="topic-metadata">

**Author:** [@amagi](https://discourse.cmake.org/u/amagi)\
**Replies:** 5\
**Last updated:** [September 12, 2026, 2:54am UTC](https://discourse.cmake.org/t/a-method-of-writing-that-can-handle-file-name-changes/15825 "2026-09-12T02:54:38Z")

</div>

The following code requires a cmake --build build command to build if the filename is changed. However, emptying and regenerating the build directory is cumbersome, so I’ve assigned a single command to a shortcut key for…

---

## [cmake --build succeeds only after make is run](https://discourse.cmake.org/t/cmake-build-succeeds-only-after-make-is-run/15819)

<div class="topic-metadata">

**Author:** [@lostbits](https://discourse.cmake.org/u/lostbits)\
**Replies:** 6\
**Last updated:** [September 2, 2026, 8:57pm UTC](https://discourse.cmake.org/t/cmake-build-succeeds-only-after-make-is-run/15819 "2026-09-02T20:57:38Z")

</div>

Win11 (x64-86) cygiwn v3.7.0 cmake v4.2.1 Mastering Modern CMake pg. 21 cmake --build build only works after a make. project/CMakeLists.txt cmake\_minimum\_Required(VERSION 3.15) project(HelloWorld CXX) …

---

## [Tutorial: Step 4 Questions](https://discourse.cmake.org/t/tutorial-step-4-questions/15816)

<div class="topic-metadata">

**Author:** [@lostbits](https://discourse.cmake.org/u/lostbits)\
**Replies:** 0\
**Last updated:** [August 31, 2026, 7:15pm UTC](https://discourse.cmake.org/t/tutorial-step-4-questions/15816 "2026-08-31T19:15:23Z")

</div>

Some Questions: \[1\] "The full list of target properties .. is in cmake\_properties(7) ..." In the example: add\_library(Example) set\_target\_properties(Example PROPERTIES Key Value Hello …

---

## [Recommended way to enable PDB for Release configuration](https://discourse.cmake.org/t/recommended-way-to-enable-pdb-for-release-configuration/15808)

<div class="topic-metadata">

**Author:** [@dgrabiec](https://discourse.cmake.org/u/dgrabiec)\
**Replies:** 7\
**Last updated:** [August 28, 2026, 1:13pm UTC](https://discourse.cmake.org/t/recommended-way-to-enable-pdb-for-release-configuration/15808 "2026-08-28T13:13:51Z")

</div>

I’m wondering what the canonical way to enable generation of PDB files for a Release build is? Naively I’ve just added this to my toolchain file for the MSVC generators: add\_compile\_options("$\<$\`\<\`CONFIG:Release\`\>\`:/Zi\>…

---

## [GET\_RUNTIME\_DEPENDENCIES has difficulties with windows API sets](https://discourse.cmake.org/t/get-runtime-dependencies-has-difficulties-with-windows-api-sets/1768)

<div class="topic-metadata">

**Author:** [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Replies:** 22\
**Last updated:** [August 26, 2026, 4:59pm UTC](https://discourse.cmake.org/t/get-runtime-dependencies-has-difficulties-with-windows-api-sets/1768 "2026-08-26T16:59:25Z")

</div>

GET\_RUNTIME\_DEPENDENCIES return dlls that do not physically exist and are part of the concept that Microsoft refers to as API sets. Examples: api-ms-win-core-libraryloader-l1-2-1.dll api-ms-win-core-atoms-l1-1-0.dll a…

---

## [cmake --build build doesn't work but make does for tutorial step 1](https://discourse.cmake.org/t/cmake-build-build-doesnt-work-but-make-does-for-tutorial-step-1/15800)

<div class="topic-metadata">

**Author:** [@SlipBits](https://discourse.cmake.org/u/SlipBits)\
**Replies:** 3\
**Last updated:** [August 25, 2026, 11:56am UTC](https://discourse.cmake.org/t/cmake-build-build-doesnt-work-but-make-does-for-tutorial-step-1/15800 "2026-08-25T11:56:06Z")

</div>

Win11 Home (x86-64) cygwin 3.7.0 /usr/bin/cmake 4.2.1 I am totally confused. I am going through the tutorial and at the end of Step 1 Exercise 2 I have created a CMakeLists.txt file which generates a working Makefile…

---

## [INTERFACE IMPORTED header-only library not recognized by target\_include\_directories](https://discourse.cmake.org/t/interface-imported-header-only-library-not-recognized-by-target-include-directories/15785)

<div class="topic-metadata">

**Author:** [@MarkCallow](https://discourse.cmake.org/u/MarkCallow)\
**Replies:** 3\
**Last updated:** [August 25, 2026, 6:20am UTC](https://discourse.cmake.org/t/interface-imported-header-only-library-not-recognized-by-target-include-directories/15785 "2026-08-25T06:20:28Z")

</div>

I am creating an INTERFACE IMPORTED header-only library whose name, Vulkan::Headers, I add in a target\_include\_directories command but target\_include\_directories is treating it as a relative path name. Here are the detai…

---

## [Custom command/target results in MSB8065 warnings in Visual Studio 2022 & 2026](https://discourse.cmake.org/t/custom-command-target-results-in-msb8065-warnings-in-visual-studio-2022-2026/15757)

<div class="topic-metadata">

**Author:** [@MarkCallow](https://discourse.cmake.org/u/MarkCallow)\
**Replies:** 2\
**Last updated:** [July 23, 2026, 2:27pm UTC](https://discourse.cmake.org/t/custom-command-target-results-in-msb8065-warnings-in-visual-studio-2022-2026/15757 "2026-07-23T14:27:29Z")

</div>

I am aware of Custom command results in MSB8065 warnings in Visual Studio 2019. That is a different issue. In that case the custom command OUTPUT is not a real file. In this case it is a real file, actually a directory. …

---

## [Turning CMake Dependency Graphs Into a Reviewable Build Map](https://discourse.cmake.org/t/turning-cmake-dependency-graphs-into-a-reviewable-build-map/15756)

<div class="topic-metadata">

**Author:** [@Martyn\_Foster](https://discourse.cmake.org/u/Martyn_Foster)\
**Replies:** 0\
**Last updated:** [July 23, 2026, 9:29am UTC](https://discourse.cmake.org/t/turning-cmake-dependency-graphs-into-a-reviewable-build-map/15756 "2026-07-23T09:29:47Z")

</div>

Anyone who has inherited a CMake project with a few dozen targets knows the moment: add\_subdirectory calls nest three or four levels deep, target\_link\_libraries chains cross back on themselves, and a configure error abou…

---

## [\_MBCS in 4.2, and policy CMP0204](https://discourse.cmake.org/t/mbcs-in-4-2-and-policy-cmp0204/15738)

<div class="topic-metadata">

**Author:** [@johan556](https://discourse.cmake.org/u/johan556)\
**Replies:** 2\
**Last updated:** [July 22, 2026, 6:29pm UTC](https://discourse.cmake.org/t/mbcs-in-4-2-and-policy-cmp0204/15738 "2026-07-22T18:29:47Z")

</div>

I recently updated one of my projects to use cmake\_minimum\_required(VERSION 4.2). My project sets the defines UNICODE and \_UNICODE globally, so I assumed that the new policy CMP0204 should work without problem for me. I…

---

## [Cpack ingnore or overwite install options from external dependencies](https://discourse.cmake.org/t/cpack-ingnore-or-overwite-install-options-from-external-dependencies/15754)

<div class="topic-metadata">

**Author:** [@nickvdbroeck](https://discourse.cmake.org/u/nickvdbroeck)\
**Replies:** 3\
**Last updated:** [July 22, 2026, 7:32am UTC](https://discourse.cmake.org/t/cpack-ingnore-or-overwite-install-options-from-external-dependencies/15754 "2026-07-22T07:32:55Z")

</div>

I have the following issue: I am building an SDK. It includes an external project (specifically: GitHub - ouster-lidar/ouster-sdk: Cross-platform C++ and Python SDK for Ouster LiDAR sensors. Includes tools for visualiza…

---

## [4.4.0: CMake Error: The warning category "all" is not known.](https://discourse.cmake.org/t/4-4-0-cmake-error-the-warning-category-all-is-not-known/15752)

<div class="topic-metadata">

**Author:** [@wiz](https://discourse.cmake.org/u/wiz)\
**Replies:** 4\
**Last updated:** [July 17, 2026, 9:10pm UTC](https://discourse.cmake.org/t/4-4-0-cmake-error-the-warning-category-all-is-not-known/15752 "2026-07-17T21:10:42Z")

</div>

Hi! After updating CMake in pkgsrc to 4.4.0, dynamips started failing with an error I don’t understand: -- Looking for clock\_gettime in rt CMake Error: The warning category "all" is not known. CMake Error at /opt/pkg/s…

---

## [Where can a project install its CMake modules](https://discourse.cmake.org/t/where-can-a-project-install-its-cmake-modules/15304)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 12\
**Last updated:** [July 13, 2026, 7:05pm UTC](https://discourse.cmake.org/t/where-can-a-project-install-its-cmake-modules/15304 "2026-07-13T19:05:55Z")

</div>

If some project provides its own CMake modules, where would be the best place to install them on the system so other projects can simply use them via include() and find\_package()? Does CMake have any such additional pat…

---

## [Replace Autotools-based build system by CMake.](https://discourse.cmake.org/t/replace-autotools-based-build-system-by-cmake/15745)

<div class="topic-metadata">

**Author:** [@G.W\_Haywood](https://discourse.cmake.org/u/G.W_Haywood)\
**Replies:** 2\
**Last updated:** [July 13, 2026, 5:57pm UTC](https://discourse.cmake.org/t/replace-autotools-based-build-system-by-cmake/15745 "2026-07-13T17:57:21Z")

</div>

Hi there, The subject says what I’m trying to do but I’m not even sure that it’s sane to try to do it. About a year ago, for my sins, I became the maintainer of BackupPC: The project is in reasonable shape but fran…

---

## [Feature Request: Support for deprecating variables](https://discourse.cmake.org/t/feature-request-support-for-deprecating-variables/15529)

<div class="topic-metadata">

**Author:** [@dalg24](https://discourse.cmake.org/u/dalg24)\
**Replies:** 1\
**Last updated:** [July 13, 2026, 8:21am UTC](https://discourse.cmake.org/t/feature-request-support-for-deprecating-variables/15529 "2026-07-13T08:21:52Z")

</div>

It would be nice if we were able to mark a variable that is set as deprecated so that the consumer of that variable is made aware he should not depend on it. Something like set(Foo\_OLD\_AND\_LAME ON DEPRECATED "Use Foo\_N…

---

## [How to install a "generated" directory?](https://discourse.cmake.org/t/how-to-install-a-generated-directory/1267)

<div class="topic-metadata">

**Author:** [@fry](https://discourse.cmake.org/u/fry)\
**Replies:** 6\
**Last updated:** [July 10, 2026, 9:46pm UTC](https://discourse.cmake.org/t/how-to-install-a-generated-directory/1267 "2026-07-10T21:46:34Z")

</div>

I have been trying to get better at CMake (currently reading Professional CMake which is very good IMO) and I am trying to do the right thing in my build: I have this program (which I am calling black-box because I don’…

---

## [Can I mitigate the disk usage caused by building multiple C++ modules executables in a project?](https://discourse.cmake.org/t/can-i-mitigate-the-disk-usage-caused-by-building-multiple-c-modules-executables-in-a-project/15688)

<div class="topic-metadata">

**Author:** [@sebjames](https://discourse.cmake.org/u/sebjames)\
**Replies:** 17\
**Last updated:** [July 1, 2026, 9:10am UTC](https://discourse.cmake.org/t/can-i-mitigate-the-disk-usage-caused-by-building-multiple-c-modules-executables-in-a-project/15688 "2026-07-01T09:10:47Z")

</div>

Hi C++ modules fans, I have a couple of repositories that are now completely C++ modules based, using a cmake/ninja build system. My best example is this maths library: GitHub - sebsjames/maths: C++ modules for scalar,…

---

## [Difference between target\_link\_libraries and adding headers via target\_sources](https://discourse.cmake.org/t/difference-between-target-link-libraries-and-adding-headers-via-target-sources/15730)

<div class="topic-metadata">

**Author:** [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Replies:** 0\
**Last updated:** [June 24, 2026, 2:37pm UTC](https://discourse.cmake.org/t/difference-between-target-link-libraries-and-adding-headers-via-target-sources/15730 "2026-06-24T14:37:13Z")

</div>

Hi all Is target link libraries needed when wanted to add the .c files in a library, and then do target\_sources file sets to specify which header files to use from that(or what the file needs)? Also, if I strictly just …

---

## [Writing a file with generator expressions not working as I expect](https://discourse.cmake.org/t/writing-a-file-with-generator-expressions-not-working-as-i-expect/15715)

<div class="topic-metadata">

**Author:** [@epistax](https://discourse.cmake.org/u/epistax)\
**Replies:** 0\
**Last updated:** [June 16, 2026, 4:09pm UTC](https://discourse.cmake.org/t/writing-a-file-with-generator-expressions-not-working-as-i-expect/15715 "2026-06-16T16:09:47Z")

</div>

I am using an external tool during one phase of the build that requires a file with some data in it. Some of it is working fine. I can give it the C compiler, ar, ranlib. Where I am having trouble is writing out some com…

---

## [Building cmake on OpenVMS](https://discourse.cmake.org/t/building-cmake-on-openvms/15707)

<div class="topic-metadata">

**Author:** [@kosborn](https://discourse.cmake.org/u/kosborn)\
**Replies:** 0\
**Last updated:** [June 11, 2026, 3:26am UTC](https://discourse.cmake.org/t/building-cmake-on-openvms/15707 "2026-06-11T03:26:53Z")

</div>

I am looking to port a number of open source applications to OpenVMS (x86) using GNV (i.e. gnu tools for OpenVMS) and am wanting to use cmake to help. Although OpenVMS is not listed as a supported platform in the README…

---

## [Running postbuild tasks with ninja](https://discourse.cmake.org/t/running-postbuild-tasks-with-ninja/13623)

<div class="topic-metadata">

**Author:** [@noahdav](https://discourse.cmake.org/u/noahdav)\
**Replies:** 4\
**Last updated:** [June 4, 2026, 7:06pm UTC](https://discourse.cmake.org/t/running-postbuild-tasks-with-ninja/13623 "2026-06-04T19:06:03Z")

</div>

Hi, We have been using the visual studio generators and it seems to work for the most part but there are a few issues that we are trying to solve that are not supported with the visual studio generators. We have been l…

---

## [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…

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