# Code

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

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

**Page:** 3

---

## [How to traverse \`target\_link\_libraries\` dependencies in the file api?](https://discourse.cmake.org/t/how-to-traverse-target-link-libraries-dependencies-in-the-file-api/14384)

<div class="topic-metadata">

**Author:** [@Zachary\_Turner](https://discourse.cmake.org/u/Zachary_Turner)\
**Replies:** 4\
**Last updated:** [February 21, 2026, 12:16am UTC](https://discourse.cmake.org/t/how-to-traverse-target-link-libraries-dependencies-in-the-file-api/14384 "2026-02-21T00:16:35Z")

</div>

I’m using cmake 3.26.3. I have three targets A, B, and C. And I have target\_link\_libraries(A PRIVATE B PUBLIC C). I use the file api and traverse to the codemodel object for target A, and it’s dependencies field is com…

---

## [\`SYSTEM\` flag hides header warnings but not sources](https://discourse.cmake.org/t/system-flag-hides-header-warnings-but-not-sources/15517)

<div class="topic-metadata">

**Author:** [@DaAwesomeP](https://discourse.cmake.org/u/DaAwesomeP)\
**Replies:** 1\
**Last updated:** [February 20, 2026, 5:24pm UTC](https://discourse.cmake.org/t/system-flag-hides-header-warnings-but-not-sources/15517 "2026-02-20T17:24:42Z")

</div>

Hi, I’m using add\_subdirectory via CPM to add a library: CPMAddPackage( NAME JUCE GITHUB\_REPOSITORY juce-framework/JUCE SYSTEM YES ) target\_link\_libraries(${PROJECT\_NAME} PRIVATE juce\_osc ) # O…

---

## [Custom targets that use terminal individually, but can be run parallel in batch](https://discourse.cmake.org/t/custom-targets-that-use-terminal-individually-but-can-be-run-parallel-in-batch/14054)

<div class="topic-metadata">

**Author:** [@mahrud](https://discourse.cmake.org/u/mahrud)\
**Replies:** 7\
**Last updated:** [February 20, 2026, 2:36pm UTC](https://discourse.cmake.org/t/custom-targets-that-use-terminal-individually-but-can-be-run-parallel-in-batch/14054 "2026-02-20T14:36:26Z")

</div>

Say I have 10 custom targets build-package-{1..10} that I can run in with an umbrella target build-all. I really appreciate that CMake + Ninja allow me to run these in parallel and have them print their result only when …

---

## [Add settings to visual studio, e.g., an exception or a plugin property](https://discourse.cmake.org/t/add-settings-to-visual-studio-e-g-an-exception-or-a-plugin-property/14374)

<div class="topic-metadata">

**Author:** [@Zohar](https://discourse.cmake.org/u/Zohar)\
**Replies:** 3\
**Last updated:** [February 20, 2026, 2:32pm UTC](https://discourse.cmake.org/t/add-settings-to-visual-studio-e-g-an-exception-or-a-plugin-property/14374 "2026-02-20T14:32:57Z")

</div>

I’d like to add settings to Visual Studio such as: An exception (e.g., std::exception) to the “Exception Settings.” I have a list of them. Set a plugin property: “Child Process Debugging”, enable. Every time I run a c…

---

## [Can I make two separate library packages in one CMakelIsts.txt file?](https://discourse.cmake.org/t/can-i-make-two-separate-library-packages-in-one-cmakelists-txt-file/15168)

<div class="topic-metadata">

**Author:** [@chriskot870](https://discourse.cmake.org/u/chriskot870)\
**Replies:** 2\
**Last updated:** [February 20, 2026, 2:26pm UTC](https://discourse.cmake.org/t/can-i-make-two-separate-library-packages-in-one-cmakelists-txt-file/15168 "2026-02-20T14:26:04Z")

</div>

I am currently creating one library built from two source files. I want to generate both shared library and static library. The static libraries and headers only get loaded when loading a dev version of the package. set…

---

## [Best way to have a library package install a main.cpp and run add\_executable in context of user project when it calls my CMake function?](https://discourse.cmake.org/t/best-way-to-have-a-library-package-install-a-main-cpp-and-run-add-executable-in-context-of-user-project-when-it-calls-my-cmake-function/11200)

<div class="topic-metadata">

**Author:** [@Dennis\_Ferron](https://discourse.cmake.org/u/Dennis_Ferron)\
**Replies:** 3\
**Last updated:** [February 20, 2026, 2:09pm UTC](https://discourse.cmake.org/t/best-way-to-have-a-library-package-install-a-main-cpp-and-run-add-executable-in-context-of-user-project-when-it-calls-my-cmake-function/11200 "2026-02-20T14:09:06Z")

</div>

The ANTLR4 parser project provides a TestRig (Java) class which helps you debug your grammar, but running it from CMake via add\_custom\_command (or similar) only runs it at configure or build time. To run a command from …

---

## [Import std - cmake 3.30 - "config mismatch" error](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908)

<div class="topic-metadata">

**Author:** [@Kelarov](https://discourse.cmake.org/u/Kelarov)\
**Replies:** 3\
**Last updated:** [February 20, 2026, 5:48am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908 "2026-02-20T05:48:14Z")

</div>

Hi all. I am trying to apply what the import std in CMake 3.30 post does to use in a project, but am facing errors. My setup: CMakeLists.txt CMakePresets.json src/CMakeLists.txt src/kk-intro.cppm src/kk-intro.cc src/m…

---

## [Automatically discovering the minimal header install set](https://discourse.cmake.org/t/automatically-discovering-the-minimal-header-install-set/13832)

<div class="topic-metadata">

**Author:** [@sketch34](https://discourse.cmake.org/u/sketch34)\
**Replies:** 3\
**Last updated:** [February 20, 2026, 4:55am UTC](https://discourse.cmake.org/t/automatically-discovering-the-minimal-header-install-set/13832 "2026-02-20T04:55:05Z")

</div>

I have an install component ae\_sdk that produces the client-facing SDK. We want the SDK to contains the minimal set of headers required. Currently we achieve this by compiling a sample SDK project with the gcc -H flag (p…

---

## [Need help with the issue I am facing](https://discourse.cmake.org/t/need-help-with-the-issue-i-am-facing/13845)

<div class="topic-metadata">

**Author:** [@Tanishka](https://discourse.cmake.org/u/Tanishka)\
**Replies:** 3\
**Last updated:** [February 20, 2026, 4:53am UTC](https://discourse.cmake.org/t/need-help-with-the-issue-i-am-facing/13845 "2026-02-20T04:53:29Z")

</div>

I am using cmake with ccache in my code. Although the temporary file is generated by ccache exists on the agent with the same name and in the same path(C:/Users/bamboo.vmBAPrd03TLCWEW/AppData/Local/ccache/tmp/cmd\_args.t…

---

## [set xcode "Library Search Paths" form cmake?](https://discourse.cmake.org/t/set-xcode-library-search-paths-form-cmake/12846)

<div class="topic-metadata">

**Author:** [@shokarta](https://discourse.cmake.org/u/shokarta)\
**Replies:** 4\
**Last updated:** [February 20, 2026, 3:34am UTC](https://discourse.cmake.org/t/set-xcode-library-search-paths-form-cmake/12846 "2026-02-20T03:34:42Z")

</div>

Hello guys, after I configure the project from QT, in xcode I need to manualy go to project BUILD SETTINGS, locate LIBRARY SEARCH PATHS and set some stuff manualy… can this be automated from cmake? I need to set follo…

---

## [Multiple shared libs, alternative implementations of common interface, \*minimal\* cmake/c++ example?](https://discourse.cmake.org/t/multiple-shared-libs-alternative-implementations-of-common-interface-minimal-cmake-c-example/15161)

<div class="topic-metadata">

**Author:** [@dunc](https://discourse.cmake.org/u/dunc)\
**Replies:** 5\
**Last updated:** [February 20, 2026, 3:10am UTC](https://discourse.cmake.org/t/multiple-shared-libs-alternative-implementations-of-common-interface-minimal-cmake-c-example/15161 "2026-02-20T03:10:11Z")

</div>

Hi all, new user here, my name is Jörg, but I usually go as “dunc” online… this is my first post here, and it’s really more of a very generic/basic cmake tutorial question, so you gents might consider it “too basic”. Th…

---

## [Retrieving compile definitions with genex evaluated](https://discourse.cmake.org/t/retrieving-compile-definitions-with-genex-evaluated/9425)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 7\
**Last updated:** [February 20, 2026, 3:04am UTC](https://discourse.cmake.org/t/retrieving-compile-definitions-with-genex-evaluated/9425 "2026-02-20T03:04:27Z")

</div>

I have a build which uses the unifdef tool and hence is dependent on having the compile definitions for built targets available as input to this. Now that I was adding the compile definitions using genexes I’d like to le…

---

## [Find module variables naming conventions](https://discourse.cmake.org/t/find-module-variables-naming-conventions/13266)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 4\
**Last updated:** [February 20, 2026, 3:00am UTC](https://discourse.cmake.org/t/find-module-variables-naming-conventions/13266 "2026-02-20T03:00:33Z")

</div>

Hello, Apologies for asking so many questions lately. This community has been of enormous help so I have another question about find modules. In CMake there is trend to use find modules like this: find\_package(Foobar)…

---

## [CMake not building module partition that builds with command lines](https://discourse.cmake.org/t/cmake-not-building-module-partition-that-builds-with-command-lines/13758)

<div class="topic-metadata">

**Author:** [@rmerriam](https://discourse.cmake.org/u/rmerriam)\
**Replies:** 6\
**Last updated:** [February 19, 2026, 9:53pm UTC](https://discourse.cmake.org/t/cmake-not-building-module-partition-that-builds-with-command-lines/13758 "2026-02-19T21:53:33Z")

</div>

I am encountering this problem with CMake on Ubuntu 24.04, Clang 19, GCC 14 and CLion 2024.3.4. These are examples for talk and book so the partition module needs to be done with an MIU and implementation file. Other non…

---

## [How to correctly generate compile\_commands.json for library dependency using PkgConfig?](https://discourse.cmake.org/t/how-to-correctly-generate-compile-commands-json-for-library-dependency-using-pkgconfig/15135)

<div class="topic-metadata">

**Author:** [@skittishdev](https://discourse.cmake.org/u/skittishdev)\
**Replies:** 3\
**Last updated:** [February 19, 2026, 9:01pm UTC](https://discourse.cmake.org/t/how-to-correctly-generate-compile-commands-json-for-library-dependency-using-pkgconfig/15135 "2026-02-19T21:01:24Z")

</div>

Hi, I am on MacOS, and I use nix as my package manager. I am building a C project, and I’d like to use Criterion for my tests. I am able to build my project and run the tests, but my compile\_commands.json file is not ge…

---

## [Is setting empty-named variable defined behaviour?](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305)

<div class="topic-metadata">

**Author:** [@Angew](https://discourse.cmake.org/u/Angew)\
**Replies:** 2\
**Last updated:** [February 19, 2026, 8:52pm UTC](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305 "2026-02-19T20:52:51Z")

</div>

Hi all. Short version: set("" value PARENT\_SCOPE) currently works, and does nothing. Is that behaviour well-defined and can it be relied on? Long version: I’m simplifying some CMake code in a project and there are se…

---

## [Why \`ARGV\` got \`aa;"bb"\` when I call \`func("aa";"bb")\`?](https://discourse.cmake.org/t/why-argv-got-aa-bb-when-i-call-func-aa-bb/15325)

<div class="topic-metadata">

**Author:** [@dingcurie](https://discourse.cmake.org/u/dingcurie)\
**Replies:** 3\
**Last updated:** [February 19, 2026, 8:49pm UTC](https://discourse.cmake.org/t/why-argv-got-aa-bb-when-i-call-func-aa-bb/15325 "2026-02-19T20:49:20Z")

</div>

Why the following code outputs aa;”bb”, instead of aa;bb or “aa”;”bb”? function(func) message("${ARGV}") endfunction() func("aa";"bb")

---

## [Where can a project install its CMake modules when using CPS](https://discourse.cmake.org/t/where-can-a-project-install-its-cmake-modules-when-using-cps/15515)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 2\
**Last updated:** [February 18, 2026, 9:52pm UTC](https://discourse.cmake.org/t/where-can-a-project-install-its-cmake-modules-when-using-cps/15515 "2026-02-18T21:52:30Z")

</div>

This is a follow-up question to Where can a project install its CMake modules To briefly describe the issue again: Main project provides CMake modules and configuration that extensions (built as separate projects) need…

---

## [Using ccache with Visual Studio generator and ClangCL toolset](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497)

<div class="topic-metadata">

**Author:** [@retif](https://discourse.cmake.org/u/retif)\
**Replies:** 2\
**Last updated:** [February 16, 2026, 11:06am UTC](https://discourse.cmake.org/t/using-ccache-with-visual-studio-generator-and-clangcl-toolset/15497 "2026-02-16T11:06:25Z")

</div>

I am looking at enabling ccache in my projects, and I got it working on/with almost all the platforms/generators that I need. The “Professional CMake” book was a great help with that (big thanks to @craig.scott, as usual)…

---

## [FindMPI fails if suffix is limited to .a and .lib](https://discourse.cmake.org/t/findmpi-fails-if-suffix-is-limited-to-a-and-lib/15500)

<div class="topic-metadata">

**Author:** [@KazuFurutaka](https://discourse.cmake.org/u/KazuFurutaka)\
**Replies:** 2\
**Last updated:** [February 15, 2026, 5:34am UTC](https://discourse.cmake.org/t/findmpi-fails-if-suffix-is-limited-to-a-and-lib/15500 "2026-02-15T05:34:46Z")

</div>

Dear experts. find\_package(MPI) “fails” (resulting in MPI\_FOUND=FALSE) if CMAKE\_FIND\_LIBRARY\_SUFFIXES is set to “.a;.lib” although it finds libmpichfort.a and libmpich.a (as reported in MPI\_Fortran\_LIBRARIES). OS: Linu…

---

## [FetchContent\_Populate() no good documentation - build step](https://discourse.cmake.org/t/fetchcontent-populate-no-good-documentation-build-step/15499)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 2\
**Last updated:** [February 14, 2026, 2:36pm UTC](https://discourse.cmake.org/t/fetchcontent-populate-no-good-documentation-build-step/15499 "2026-02-14T14:36:36Z")

</div>

Hello, I have scoured through this until I almost went blind. https://cmake.org/cmake/help/latest/module/FetchContent.html Have the following section in a cmake file because I need a much newer version of libtool libr…

---

## [PRIVATE vs PUBLIC shared library dependencies and INTERFACE\_LINK\_DIRECTORIES semantics](https://discourse.cmake.org/t/private-vs-public-shared-library-dependencies-and-interface-link-directories-semantics/15458)

<div class="topic-metadata">

**Author:** [@Braden](https://discourse.cmake.org/u/Braden)\
**Replies:** 7\
**Last updated:** [February 14, 2026, 2:23pm UTC](https://discourse.cmake.org/t/private-vs-public-shared-library-dependencies-and-interface-link-directories-semantics/15458 "2026-02-14T14:23:30Z")

</div>

Consider: C –depends-on→ shared-lib-B –depends-on→ shared-lib-A B doesn’t expose any parts of A to C; so, B’s dependency on A is PRIVATE. When C goes to link with B at build time, there are no symbols from A to resolve…

---

## [Overwriting link dependencies - possible?](https://discourse.cmake.org/t/overwriting-link-dependencies-possible/15495)

<div class="topic-metadata">

**Author:** [@ingolf](https://discourse.cmake.org/u/ingolf)\
**Replies:** 8\
**Last updated:** [February 14, 2026, 6:01am UTC](https://discourse.cmake.org/t/overwriting-link-dependencies-possible/15495 "2026-02-14T06:01:33Z")

</div>

Hi, please have a look at the following situation: there is some (static) library named libraryA there is another (static) library named libraryB which has a link time dependency on libraryA (specified via target\_link…

---

## [CMake 3.29 - 4.2.3 CMAKE\_PROJECT\_\_INCLUDE\_BEFORE cannot set variables for project(…)](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505)

<div class="topic-metadata">

**Author:** [@e\_gleba](https://discourse.cmake.org/u/e_gleba)\
**Replies:** 2\
**Last updated:** [February 14, 2026, 5:34am UTC](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505 "2026-02-14T05:34:08Z")

</div>

CMAKE\_PROJECT\_\_INCLUDE\_BEFORE cannot set variables for project(…) Summary CMAKE\_PROJECT\_\<PROJECT-NAME\>\_INCLUDE\_BEFORE fails to provide variables for the parameter of project() (e.g. VERSION or DESCRIPTION). Variables set…

---

## [cmake does not treat Boost as a system library on github runner macos-15-intel](https://discourse.cmake.org/t/cmake-does-not-treat-boost-as-a-system-library-on-github-runner-macos-15-intel/15496)

<div class="topic-metadata">

**Author:** [@ralfkonrad](https://discourse.cmake.org/u/ralfkonrad)\
**Replies:** 4\
**Last updated:** [February 12, 2026, 12:49pm UTC](https://discourse.cmake.org/t/cmake-does-not-treat-boost-as-a-system-library-on-github-runner-macos-15-intel/15496 "2026-02-12T12:49:26Z")

</div>

In the repo GitHub - ralfkonrad/cmake\_missing\_warning I am describing a situation which I would assume to be a bug: While the other GitHub runners suppress a Boost deprecation warning correctly due to target\_include\_di…

---

## [CMake 4.1.2 not propagating include directories to target when linking with PUBLIC (compile\_commands.json)](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432)

<div class="topic-metadata">

**Author:** [@edog](https://discourse.cmake.org/u/edog)\
**Replies:** 2\
**Last updated:** [February 10, 2026, 7:33am UTC](https://discourse.cmake.org/t/cmake-4-1-2-not-propagating-include-directories-to-target-when-linking-with-public-compile-commands-json/15432 "2026-02-10T07:33:34Z")

</div>

For some context I’ve tried this both on WSL2 on windows and an Ubuntu 24 Server VM running on a home server so its a reproducible issue I’m using nix to pull cmake, glog, gcc, and other dependencies CMake 4.1.2 GCC 1…

---

## [Tutorial Step 9 missing rational for FILE\_SET HEADERS in export?](https://discourse.cmake.org/t/tutorial-step-9-missing-rational-for-file-set-headers-in-export/15427)

<div class="topic-metadata">

**Author:** [@codefrog](https://discourse.cmake.org/u/codefrog)\
**Replies:** 2\
**Last updated:** [February 9, 2026, 12:10pm UTC](https://discourse.cmake.org/t/tutorial-step-9-missing-rational-for-file-set-headers-in-export/15427 "2026-02-09T12:10:54Z")

</div>

I’m newly going through the updated Tutorial. It’s much improved. After completing exercise 2 I tried to build but got this error: CMake Error at CMakeLists.txt:49 (install): install TARGETS target MathFunctions is exp…

---

## [Best practice setting package paths for \`find\_dependency\` in \`-config.make\` files?](https://discourse.cmake.org/t/best-practice-setting-package-paths-for-find-dependency-in-config-make-files/15408)

<div class="topic-metadata">

**Author:** [@Peter\_Hill](https://discourse.cmake.org/u/Peter_Hill)\
**Replies:** 4\
**Last updated:** [February 9, 2026, 8:43am UTC](https://discourse.cmake.org/t/best-practice-setting-package-paths-for-find-dependency-in-config-make-files/15408 "2026-02-09T08:43:31Z")

</div>

We have a library which has several dependencies: some optional, some required, some bundled. Our package config file looks something like: include(CMakeFindDependencyMacro) find\_dependency(foo) if (@PROJECT\_HAS\_BAR@)…

---

## [Getting a bad g++ commandline using several configurations. Help wanted.](https://discourse.cmake.org/t/getting-a-bad-g-commandline-using-several-configurations-help-wanted/15401)

<div class="topic-metadata">

**Author:** [@janheckman](https://discourse.cmake.org/u/janheckman)\
**Replies:** 3\
**Last updated:** [February 9, 2026, 5:21am UTC](https://discourse.cmake.org/t/getting-a-bad-g-commandline-using-several-configurations-help-wanted/15401 "2026-02-09T05:21:31Z")

</div>

I get build errors on Linux using g++, during the object phase, like: cc1plus: error: too many filenames given; type ‘cc1plus --help’ for usage cc1plus: fatal error: contournieuw/CMakeFiles/contournieuw.dir/contournieuw…

---

## [CMake adding quotes to ./configure commands?](https://discourse.cmake.org/t/cmake-adding-quotes-to-configure-commands/15383)

<div class="topic-metadata">

**Author:** [@bchapman23](https://discourse.cmake.org/u/bchapman23)\
**Replies:** 1\
**Last updated:** [February 9, 2026, 5:10am UTC](https://discourse.cmake.org/t/cmake-adding-quotes-to-configure-commands/15383 "2026-02-09T05:10:47Z")

</div>

Hello, I am trying to use CMake to build PETSc. However, when using the following configure command set(PETSC\_CONFIG\_COMMAND ./configure \\\[other flags\\\] LDFLAGS="-L${LLVM\_PATH}/lib/clang/17/lib/linux/ -lclang\_rt.b…

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

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