# Code

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

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

**Page:** 4

---

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

---

## [collect source lists](https://discourse.cmake.org/t/collect-source-lists/15459)

<div class="topic-metadata">

**Author:** [@JBB\_NOAA](https://discourse.cmake.org/u/JBB_NOAA)\
**Replies:** 3\
**Last updated:** [February 9, 2026, 2:14am UTC](https://discourse.cmake.org/t/collect-source-lists/15459 "2026-02-09T02:14:20Z")

</div>

The documentation for file GLOB says " Note We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generate…

---

## [cmake create full directory path on Linux](https://discourse.cmake.org/t/cmake-create-full-directory-path-on-linux/15492)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 1\
**Last updated:** [February 4, 2026, 9:58pm UTC](https://discourse.cmake.org/t/cmake-create-full-directory-path-on-linux/15492 "2026-02-04T21:58:01Z")

</div>

I’m on Ubuntu 18.04 cmake version 4.2.1 Trying to bring libtool into my project because the version of libtool on 18.04 doesn’t work properly when it comes to dependencies of a plugin you just loaded. ExternalProject\_…

---

## [MacOSX Install Bundle not installing binary](https://discourse.cmake.org/t/macosx-install-bundle-not-installing-binary/15491)

<div class="topic-metadata">

**Author:** [@duncans\_pumpkin](https://discourse.cmake.org/u/duncans_pumpkin)\
**Replies:** 1\
**Last updated:** [February 2, 2026, 9:52pm UTC](https://discourse.cmake.org/t/macosx-install-bundle-not-installing-binary/15491 "2026-02-02T21:52:50Z")

</div>

I have tried for a while to install a macosx bundle and it just does not seem to work at all. Everything builds correctly and the macosx bundle in the build directory is all correct but the install directory is just the…

---

## [Problem in static link of HDF5+OpenMP w/ Intel ifx; \`search\_static\` limited only to GNU toolchain?](https://discourse.cmake.org/t/problem-in-static-link-of-hdf5-openmp-w-intel-ifx-search-static-limited-only-to-gnu-toolchain/15486)

<div class="topic-metadata">

**Author:** [@KazuFurutaka](https://discourse.cmake.org/u/KazuFurutaka)\
**Replies:** 0\
**Last updated:** [January 30, 2026, 2:06am UTC](https://discourse.cmake.org/t/problem-in-static-link-of-hdf5-openmp-w-intel-ifx-search-static-limited-only-to-gnu-toolchain/15486 "2026-01-30T02:06:55Z")

</div>

Dear experienced CMake coders! I’m novice in writing CMake scripts… Now I’m writng a CMakeLists . txt for a Fortran project with HDF5, MPI and OpenMP options (either shared and statically linked). The Fortran compiler…

---

## [Include upstream folders for header-only libraries](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477)

<div class="topic-metadata">

**Author:** [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Replies:** 5\
**Last updated:** [January 26, 2026, 2:49pm UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477 "2026-01-26T14:49:46Z")

</div>

I’m writing two C++ project, the upstream one providing some header-only libraries. I wonder what is the right (i.e. modern-CMake) way to “export” the headers folder from upstream and use it in downstream. I know I can e…

---

## [Cmake not recognising header file for some reason](https://discourse.cmake.org/t/cmake-not-recognising-header-file-for-some-reason/15466)

<div class="topic-metadata">

**Author:** [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Replies:** 1\
**Last updated:** [January 19, 2026, 3:41pm UTC](https://discourse.cmake.org/t/cmake-not-recognising-header-file-for-some-reason/15466 "2026-01-19T15:41:32Z")

</div>

Hi all I am trying to compile my project via cmake and ninja, and I’m receiving this error error: ‘STA\_NODISK’ undeclared (first use in this function) 196 | return tuh\_msc\_mounted(dev\_addr) ? 0 : STA\_NODISK; | …

---

## [CMake and vcpkg on Ubuntu 20.04 - get around 2+ hour build time](https://discourse.cmake.org/t/cmake-and-vcpkg-on-ubuntu-20-04-get-around-2-hour-build-time/15451)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 13\
**Last updated:** [January 17, 2026, 2:56pm UTC](https://discourse.cmake.org/t/cmake-and-vcpkg-on-ubuntu-20-04-get-around-2-hour-build-time/15451 "2026-01-17T14:56:38Z")

</div>

I’m sure there is probably a tutorial I haven’t found. Vcpkg just can’t be this bad. On Windows it seemed okay, but I decided to use vcpkg and cpack to create my packages instead of continuing with shell scripts and old …

---

## [GenerateExportHeader: This macro can only be used with libraries?](https://discourse.cmake.org/t/generateexportheader-this-macro-can-only-be-used-with-libraries/15464)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 1\
**Last updated:** [January 16, 2026, 10:55pm UTC](https://discourse.cmake.org/t/generateexportheader-this-macro-can-only-be-used-with-libraries/15464 "2026-01-16T22:55:34Z")

</div>

CMake Warning at /Users/runner/work/\_temp/-295072365/cmake-4.2.1-macos-universal/CMake.app/Contents/share/cmake-4.2/Modules/GenerateExportHeader.cmake:690 (message): This macro can only be used with libraries Call Stac…

---

## [Persisting fetch content files through a fresh configure](https://discourse.cmake.org/t/persisting-fetch-content-files-through-a-fresh-configure/15460)

<div class="topic-metadata">

**Author:** [@JonnyPtn](https://discourse.cmake.org/u/JonnyPtn)\
**Replies:** 1\
**Last updated:** [January 15, 2026, 7:58pm UTC](https://discourse.cmake.org/t/persisting-fetch-content-files-through-a-fresh-configure/15460 "2026-01-15T19:58:45Z")

</div>

I use FetchContent to build dependency source code as part of my project, and as part of my CI pipeline (and sometimes locally) I do a fresh configure to ensure cmake cache variables from previous runs are cleared withou…

---

## [Including legacy header files of non CMake project in CMake project](https://discourse.cmake.org/t/including-legacy-header-files-of-non-cmake-project-in-cmake-project/15452)

<div class="topic-metadata">

**Author:** [@mc78](https://discourse.cmake.org/u/mc78)\
**Replies:** 3\
**Last updated:** [January 11, 2026, 7:38pm UTC](https://discourse.cmake.org/t/including-legacy-header-files-of-non-cmake-project-in-cmake-project/15452 "2026-01-11T19:38:24Z")

</div>

I would like to add general include\_directories to a toolchain.cmake file. However, as soon I specify those include directories, CMake complains about missing CMakeLists.txt in that directory. I did not specify add\_libr…

---

## [Side effects of cmake\_minimum\_required in dependency provider](https://discourse.cmake.org/t/side-effects-of-cmake-minimum-required-in-dependency-provider/15184)

<div class="topic-metadata">

**Author:** [@georg](https://discourse.cmake.org/u/georg)\
**Replies:** 4\
**Last updated:** [January 8, 2026, 6:41pm UTC](https://discourse.cmake.org/t/side-effects-of-cmake-minimum-required-in-dependency-provider/15184 "2026-01-08T18:41:32Z")

</div>

Hi all, in general all top-level CMakeLists.txt, modules and CMake script files should have a cmake\_minimum\_required statement at the top. I wonder now if there is a good reason to not apply cmake\_minimum\_required also…

---

## [file RENAME not behaving as expected](https://discourse.cmake.org/t/file-rename-not-behaving-as-expected/15443)

<div class="topic-metadata">

**Author:** [@7schroet](https://discourse.cmake.org/u/7schroet)\
**Replies:** 2\
**Last updated:** [January 7, 2026, 11:05am UTC](https://discourse.cmake.org/t/file-rename-not-behaving-as-expected/15443 "2026-01-07T11:05:50Z")

</div>

Hi, the RENAME functionality of the file command is not behaving as expected. I have a small reproducer right here: set(old\_name "file.txt") set(new\_name "new\_file.txt") message("Pre rename:") execute\_process(COMMA…

---

## [Passing lists or strings with semi-colon to add\_custom\_command](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231)

<div class="topic-metadata">

**Author:** [@pboettch](https://discourse.cmake.org/u/pboettch)\
**Replies:** 2\
**Last updated:** [January 3, 2026, 11:47am UTC](https://discourse.cmake.org/t/passing-lists-or-strings-with-semi-colon-to-add-custom-command/15231 "2026-01-03T11:47:01Z")

</div>

What is the correct way (if any) to pass a variable containing a semi-colon ; as an argument to COMMAND for add\_custom\_command() ? I especially would like to pass a CMake List, which is usually represented as a semi-colo…

---

## [FIND\_PACKAGE working at main level, failing on dependencies](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414)

<div class="topic-metadata">

**Author:** [@Joymaker](https://discourse.cmake.org/u/Joymaker)\
**Replies:** 4\
**Last updated:** [January 3, 2026, 7:08am UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414 "2026-01-03T07:08:16Z")

</div>

I’m bringing my CMake world under the Visual Studio umbrella. Lots of things are working, including the finding of packages that I explicitly invoke (whew!). But now I’m having strange problems with FIND\_PACKAGE operatin…

---

## [Wrapping tests discovered by gtest\_discover\_tests into a wrapper.](https://discourse.cmake.org/t/wrapping-tests-discovered-by-gtest-discover-tests-into-a-wrapper/9852)

<div class="topic-metadata">

**Author:** [@solemnPonie0](https://discourse.cmake.org/u/solemnPonie0)\
**Replies:** 8\
**Last updated:** [December 30, 2025, 10:49pm UTC](https://discourse.cmake.org/t/wrapping-tests-discovered-by-gtest-discover-tests-into-a-wrapper/9852 "2025-12-30T22:49:23Z")

</div>

Hello, everyone. So, gtest\_discover\_tests() runs my gtest-test --gtest\_list\_tests, and defines a separate ctest test for each result. Now I want to run those tests wrapped in a script. That is, instead of running gtest…

---

## [Environment variable \<PackageName\>\_ROOT ignored with a cmake minimum required 3.22](https://discourse.cmake.org/t/environment-variable-packagename-root-ignored-with-a-cmake-minimum-required-3-22/13364)

<div class="topic-metadata">

**Author:** [@tpadioleau](https://discourse.cmake.org/u/tpadioleau)\
**Replies:** 1\
**Last updated:** [December 28, 2025, 7:04am UTC](https://discourse.cmake.org/t/environment-variable-packagename-root-ignored-with-a-cmake-minimum-required-3-22/13364 "2025-12-28T07:04:36Z")

</div>

Hello, I recently faced a curious situation. My project has the following structure: my CMakeLists.txt starts with a cmake\_minimum\_required(VERSION 3.22) then calls find\_package(Foo REQUIRED). The file FooConfig.cmake c…

---

## [Why is it disallowed for project preset to inherit user preset?](https://discourse.cmake.org/t/why-is-it-disallowed-for-project-preset-to-inherit-user-preset/4692)

<div class="topic-metadata">

**Author:** [@ixsci](https://discourse.cmake.org/u/ixsci)\
**Replies:** 7\
**Last updated:** [December 22, 2025, 10:16am UTC](https://discourse.cmake.org/t/why-is-it-disallowed-for-project-preset-to-inherit-user-preset/4692 "2025-12-22T10:16:30Z")

</div>

Hi guys, A little bit of context before the question: I’ve been using some routine for quite a while to acknowledge some user specific needs. For example, I need Boost\_DIR to be set on some systems and some other variab…

---

## [Trying to link with tiff](https://discourse.cmake.org/t/trying-to-link-with-tiff/12961)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 3\
**Last updated:** [December 19, 2025, 11:09am UTC](https://discourse.cmake.org/t/trying-to-link-with-tiff/12961 "2025-12-19T11:09:42Z")

</div>

I added: find\_package(Tiff 4.7 REQUIRED) to my top level CMakeLists.txt to supply the link libraries for tiff. But for my pains I got: 1\> \[CMake\] The link interface of target "TIFF::tiff" contains: 1\> \[CMake\] 1\> \[…

---

## [Linking Ada objects into a C++ shared library](https://discourse.cmake.org/t/linking-ada-objects-into-a-c-shared-library/2011)

<div class="topic-metadata">

**Author:** [@helgee](https://discourse.cmake.org/u/helgee)\
**Replies:** 3\
**Last updated:** [December 18, 2025, 3:52pm UTC](https://discourse.cmake.org/t/linking-ada-objects-into-a-c-shared-library/2011 "2025-12-18T15:52:51Z")

</div>

Dear all, I am currently trying to port a gigantic C/C++/Fortran/Ada project to CMake and got stuck. Everything needs to be compiled into a single shared library which then gets dlopened elsewhere. But I am having a pro…

---

## [Error during the adding library for learning](https://discourse.cmake.org/t/error-during-the-adding-library-for-learning/15406)

<div class="topic-metadata">

**Author:** [@dhruv-dhiman122](https://discourse.cmake.org/u/dhruv-dhiman122)\
**Replies:** 3\
**Last updated:** [December 16, 2025, 2:52pm UTC](https://discourse.cmake.org/t/error-during-the-adding-library-for-learning/15406 "2025-12-16T14:52:22Z")

</div>

So i am new to learning CMake language. cmake\_minimum\_required(VERSION 3.31) project(cmake) add\_executable(target\_machine) add\_library(MathFunctions CMake/Help/guide/tutorial/Step1/MathFunctions/Mathfunctions.cxx …

---

## [Packaging static libraries for Fedora](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590)

<div class="topic-metadata">

**Author:** [@opoplawski](https://discourse.cmake.org/u/opoplawski)\
**Replies:** 3\
**Last updated:** [December 14, 2025, 2:50pm UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590 "2025-12-14T14:50:59Z")

</div>

Fedora’s packaging guidelines for static libraries are to put them into a separate -static sub-package that is not required by the main -devel sub-package. However this causes problems for most CMake projects because th…

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

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