# Code

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

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

**Page:** 8

---

## [How to test for set env variables without getting warnings](https://discourse.cmake.org/t/how-to-test-for-set-env-variables-without-getting-warnings/11401)

<div class="topic-metadata">

**Author:** [@nolange](https://discourse.cmake.org/u/nolange)\
**Replies:** 7\
**Last updated:** [July 25, 2025, 2:08pm UTC](https://discourse.cmake.org/t/how-to-test-for-set-env-variables-without-getting-warnings/11401 "2025-07-25T14:08:18Z")

</div>

I have trouble silencing warnings, the code in question is this: if(CMAKE\_HOST\_WIN32 AND NOT $ENV{ProgramFiles} STREQUAL "") set(\_extra\_path PATHS "$ENV{ProgramFiles}/LLVM/bin") endif() the warning is: CMake Warning…

---

## [Avoiding "TARGET was not created in this directory" errors](https://discourse.cmake.org/t/avoiding-target-was-not-created-in-this-directory-errors/11321)

<div class="topic-metadata">

**Author:** [@tristan](https://discourse.cmake.org/u/tristan)\
**Replies:** 1\
**Last updated:** [July 25, 2025, 2:01pm UTC](https://discourse.cmake.org/t/avoiding-target-was-not-created-in-this-directory-errors/11321 "2025-07-25T14:01:04Z")

</div>

Not sure if this question is best attributed to the ‘Code’ or ‘Development’ group… Because I always separate my projects for libraries and it’s tests. I tend to work around the error: CMake Error at test/CMakeLists.tx…

---

## [TEST\_LAUNCHER documentation](https://discourse.cmake.org/t/test-launcher-documentation/14410)

<div class="topic-metadata">

**Author:** [@Andor\_Rozsnyai](https://discourse.cmake.org/u/Andor_Rozsnyai)\
**Replies:** 1\
**Last updated:** [July 24, 2025, 8:14pm UTC](https://discourse.cmake.org/t/test-launcher-documentation/14410 "2025-07-24T20:14:18Z")

</div>

Hi, I wanted to use launcher for my test, however it was not working, though I checked and followed the documentation. Then in source code of cmake I found the reason, then the (CMAKE\_)TEST\_LAUNCHER only used for the n…

---

## [Reference documentation for FetchContent](https://discourse.cmake.org/t/reference-documentation-for-fetchcontent/11760)

<div class="topic-metadata">

**Author:** [@MickeyKnox](https://discourse.cmake.org/u/MickeyKnox)\
**Replies:** 1\
**Last updated:** [September 24, 2024, 9:08pm UTC](https://discourse.cmake.org/t/reference-documentation-for-fetchcontent/11760 "2024-09-24T21:08:36Z")

</div>

I’ve stumbled upon this code snippet: FetchContent\_Declare( box2d GIT\_REPOSITORY https://github.com/erincatto/box2d.git GIT\_TAG 7b273b12409252d247b89940d29a8aab0386f570 GIT\_SHALLOW TRUE GIT\_PROGRESS …

---

## [install(EXPORT) does not properly take into account of paths containing '..'](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408)

<div class="topic-metadata">

**Author:** [@WildCard65](https://discourse.cmake.org/u/WildCard65)\
**Replies:** 3\
**Last updated:** [July 22, 2025, 1:18pm UTC](https://discourse.cmake.org/t/install-export-does-not-properly-take-into-account-of-paths-containing/14408 "2025-07-22T13:18:10Z")

</div>

The command install(EXPORT) in its current state is vastly incompatible with making packages with non-standard install directories (for example /lib instead of /usr/lib) resulting in extra get\_filename\_component(\_IMPORT\_…

---

## [Parsing data efficiently (JSON or maybe something else?)](https://discourse.cmake.org/t/parsing-data-efficiently-json-or-maybe-something-else/14403)

<div class="topic-metadata">

**Author:** [@epistax](https://discourse.cmake.org/u/epistax)\
**Replies:** 2\
**Last updated:** [July 21, 2025, 7:07pm UTC](https://discourse.cmake.org/t/parsing-data-efficiently-json-or-maybe-something-else/14403 "2025-07-21T19:07:49Z")

</div>

We have a hybrid setup where we are introducing CMake piece by piece on top of an existing complete build environment. The first goal for us is introducing a tight TDD cycle. We’re making some headway using JSON to share…

---

## [FetchContent and cache variables collisions](https://discourse.cmake.org/t/fetchcontent-and-cache-variables-collisions/13236)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 3\
**Last updated:** [July 19, 2025, 4:12pm UTC](https://discourse.cmake.org/t/fetchcontent-and-cache-variables-collisions/13236 "2025-07-19T16:12:09Z")

</div>

Hello, as far as I understand, when using the FetchContent module and populating the fetched package, all the cache variables are combined together with the top level project into a single CMakeCache.txt file. Are in p…

---

## [Using Intentdefinition Compiler using cmake for code generation](https://discourse.cmake.org/t/using-intentdefinition-compiler-using-cmake-for-code-generation/10229)

<div class="topic-metadata">

**Author:** [@Vipul\_Gupta](https://discourse.cmake.org/u/Vipul_Gupta)\
**Replies:** 5\
**Last updated:** [July 19, 2025, 2:06pm UTC](https://discourse.cmake.org/t/using-intentdefinition-compiler-using-cmake-for-code-generation/10229 "2025-07-19T14:06:00Z")

</div>

In Xcode, when we create an intent definition file, a corresponding swift file gets generated for the intent defined in the intent definition file. This happens with the help of IntentDefinition Compiler , which can be s…

---

## [How do you prevent CMake from adding C flags to linker flags when linking with GCC?](https://discourse.cmake.org/t/how-do-you-prevent-cmake-from-adding-c-flags-to-linker-flags-when-linking-with-gcc/11324)

<div class="topic-metadata">

**Author:** [@jwrwseu](https://discourse.cmake.org/u/jwrwseu)\
**Replies:** 1\
**Last updated:** [July 18, 2025, 8:33pm UTC](https://discourse.cmake.org/t/how-do-you-prevent-cmake-from-adding-c-flags-to-linker-flags-when-linking-with-gcc/11324 "2025-07-18T20:33:12Z")

</div>

My toolchain: set(CMAKE\_C\_FLAGS\_INIT -D\_\_ATmega64M1\_\_) list(APPEND CMAKE\_C\_FLAGS\_INIT -mmcu=atmega64m1) list(APPEND CMAKE\_C\_FLAGS\_INIT -x c) list(APPEND CMAKE\_C\_FLAGS\_INIT -funsigned-char) list(APPEND CMAKE\_C\_FLAGS\_INIT…

---

## [Prevent MinGW generator from building "liblib" outputs](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268)

<div class="topic-metadata">

**Author:** [@dlormand](https://discourse.cmake.org/u/dlormand)\
**Replies:** 5\
**Last updated:** [July 18, 2025, 8:21pm UTC](https://discourse.cmake.org/t/prevent-mingw-generator-from-building-liblib-outputs/11268 "2025-07-18T20:21:39Z")

</div>

Environment is Windows. I’ve got an existing project that was modified from Makefiles to CMake. It builds a shared DLL library and a binary that uses it. The previous developer had MS Visual C present, and so the defa…

---

## [How to not install header-sets of private dependencies?](https://discourse.cmake.org/t/how-to-not-install-header-sets-of-private-dependencies/11259)

<div class="topic-metadata">

**Author:** [@pboettch](https://discourse.cmake.org/u/pboettch)\
**Replies:** 9\
**Last updated:** [July 18, 2025, 8:19pm UTC](https://discourse.cmake.org/t/how-to-not-install-header-sets-of-private-dependencies/11259 "2025-07-18T20:19:06Z")

</div>

I modernized my CMakeLists.txt by using generated Projectconfig.cmake-files generated by CMake (exported targets) and, especially by using FILE\_SET for public and private HEADERS. Works very nicely. The only thing I hav…

---

## [Does \`find\_dependency\` also export target?](https://discourse.cmake.org/t/does-find-dependency-also-export-target/14383)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 5\
**Last updated:** [July 17, 2025, 9:16pm UTC](https://discourse.cmake.org/t/does-find-dependency-also-export-target/14383 "2025-07-17T21:16:27Z")

</div>

Hi all, I am playing with these two blocks of CMake code (I replaced some target names with ...). find\_dependency include(CMakeFindDependencyMacro) find\_dependency(nlohmann\_json) export(TARGETS ${MLIR\_EXPORTS} ... FI…

---

## [Configure custom commands and targets (e.g., for generating docs) without compiler checks](https://discourse.cmake.org/t/configure-custom-commands-and-targets-e-g-for-generating-docs-without-compiler-checks/14382)

<div class="topic-metadata">

**Author:** [@DukeOfKirkcaldy](https://discourse.cmake.org/u/DukeOfKirkcaldy)\
**Replies:** 3\
**Last updated:** [July 17, 2025, 9:51am UTC](https://discourse.cmake.org/t/configure-custom-commands-and-targets-e-g-for-generating-docs-without-compiler-checks/14382 "2025-07-17T09:51:55Z")

</div>

Following the documentation I am able to define a custom commands and targets for generating documentation. However, when integrated into my project’s CMakeLists.txt, the configuration stage performs checks that the com…

---

## [importing external projects using fetchContent or find\_package](https://discourse.cmake.org/t/importing-external-projects-using-fetchcontent-or-find-package/14379)

<div class="topic-metadata">

**Author:** [@nickvdbroeck](https://discourse.cmake.org/u/nickvdbroeck)\
**Replies:** 7\
**Last updated:** [July 16, 2025, 8:20pm UTC](https://discourse.cmake.org/t/importing-external-projects-using-fetchcontent-or-find-package/14379 "2025-07-16T20:20:12Z")

</div>

I am trying to wrap my head around the interplay between find\_package and fetchContent. Firstly: I need to support 2 use cases: On my laptop I develop locally in WSL. So I have full internet available and I can use Fe…

---

## [Query available version(s) of package before find\_package()](https://discourse.cmake.org/t/query-available-version-s-of-package-before-find-package/14310)

<div class="topic-metadata">

**Author:** [@dgobbi](https://discourse.cmake.org/u/dgobbi)\
**Replies:** 1\
**Last updated:** [July 16, 2025, 9:33am UTC](https://discourse.cmake.org/t/query-available-version-s-of-package-before-find-package/14310 "2025-07-16T09:33:53Z")

</div>

Let’s say that I want to do something like this: find\_package(pkg REQUIRED COMPONENTS x y z) However, the components that I need depend on what version of pkg I get, because (for example) the maintainers have shuffled …

---

## [The list of include directories is empty by default.](https://discourse.cmake.org/t/the-list-of-include-directories-is-empty-by-default/14360)

<div class="topic-metadata">

**Author:** [@gerogaga](https://discourse.cmake.org/u/gerogaga)\
**Replies:** 1\
**Last updated:** [July 14, 2025, 8:39pm UTC](https://discourse.cmake.org/t/the-list-of-include-directories-is-empty-by-default/14360 "2025-07-14T20:39:22Z")

</div>

I have a file with 2 target\_include\_directories() commands, but outside of the directories specified in them, nothing else gets searched for headers, including system directories, and printing the INCLUDE\_DIRECTORIES dir…

---

## [How to idiomatically add include path flags inside add\_custom\_command?](https://discourse.cmake.org/t/how-to-idiomatically-add-include-path-flags-inside-add-custom-command/13843)

<div class="topic-metadata">

**Author:** [@Time0o](https://discourse.cmake.org/u/Time0o)\
**Replies:** 3\
**Last updated:** [July 12, 2025, 11:58pm UTC](https://discourse.cmake.org/t/how-to-idiomatically-add-include-path-flags-inside-add-custom-command/13843 "2025-07-12T23:58:16Z")

</div>

This is pattern I’ve had to use multiple times and I keep thinking that the “correct” way to do it should be something like: add\_custom\_command( # ... COMMAND ${CMAKE\_COMMAND} -E env my\_compiler some\_file "-I$\<JOIN:…

---

## [Unknown argument --log-level=TRACE with cmake --workflow?](https://discourse.cmake.org/t/unknown-argument-log-level-trace-with-cmake-workflow/14341)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 1\
**Last updated:** [July 10, 2025, 8:23pm UTC](https://discourse.cmake.org/t/unknown-argument-log-level-trace-with-cmake-workflow/14341 "2025-07-10T20:23:40Z")

</div>

How to set the log-level in configure presets? bash-5.2$ make release cmake --workflow --preset release --fresh --log-level=TRACE Unknown argument --log-level=TRACE Usage: cmake --workflow \<options\> Options: --preset \<p…

---

## [GLFW/glfw3.h: No such file or directory](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591)

<div class="topic-metadata">

**Author:** [@Ph\_c\_Th\_ng\_Dinh](https://discourse.cmake.org/u/Ph_c_Th_ng_Dinh)\
**Replies:** 16\
**Last updated:** [July 7, 2025, 10:22pm UTC](https://discourse.cmake.org/t/glfw-glfw3-h-no-such-file-or-directory/11591 "2025-07-07T22:22:20Z")

</div>

I am trying to learn glfw and opengl but I got the error that i mentioned on the title that is no such file or directory. cmake: cmake\_minimum\_required(VERSION 3.30.3) project(cpp) add\_executable(cpp main.cpp) target\_in…

---

## [Add a PRE\_INSTALL option to add\_custom\_command](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 3\
**Last updated:** [July 7, 2025, 12:06pm UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319 "2025-07-07T12:06:01Z")

</div>

Running on macOS (particularly in this case), I need to do some things prior to running the install such as unlocking the keychain (for example), so that the app files I generate can be signed. Now I do this in the POST…

---

## [Cleaning the install directory](https://discourse.cmake.org/t/cleaning-the-install-directory/14318)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 3\
**Last updated:** [July 7, 2025, 10:05am UTC](https://discourse.cmake.org/t/cleaning-the-install-directory/14318 "2025-07-07T10:05:54Z")

</div>

What’s the best way to ensure that the install directory is empty prior to building my project. Ideally I’d like to put this in my top level CMake file, before I do the add\_subirectory stuff The actual command to empty…

---

## [Problem with RPATH setting in executable built as a vcpkg port](https://discourse.cmake.org/t/problem-with-rpath-setting-in-executable-built-as-a-vcpkg-port/14320)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 1\
**Last updated:** [July 6, 2025, 5:49pm UTC](https://discourse.cmake.org/t/problem-with-rpath-setting-in-executable-built-as-a-vcpkg-port/14320 "2025-07-06T17:49:02Z")

</div>

When I try to debug my executable on macOS and a related executable that was build as vcpkg port, I get: dyld\[68115\]: Library not loaded: @rpath/QtXml.framework/Versions/A/QtXml Referenced from: \<877DDE33-BED7-34DF-A3…

---

## [How to consume exported static library](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303)

<div class="topic-metadata">

**Author:** [@thetic](https://discourse.cmake.org/u/thetic)\
**Replies:** 13\
**Last updated:** [July 2, 2025, 10:45am UTC](https://discourse.cmake.org/t/how-to-consume-exported-static-library/14303 "2025-07-02T10:45:00Z")

</div>

I’ve worked thru packaging a static library using the TGZ generator. If I were to host this file somewhere. How would I consume it in another project. I know FetchContent can handle remote archives, but they need to cont…

---

## [How to make a source file compile before any others within a target](https://discourse.cmake.org/t/how-to-make-a-source-file-compile-before-any-others-within-a-target/14231)

<div class="topic-metadata">

**Author:** [@huangqinjin](https://discourse.cmake.org/u/huangqinjin)\
**Replies:** 2\
**Last updated:** [June 29, 2025, 2:34pm UTC](https://discourse.cmake.org/t/how-to-make-a-source-file-compile-before-any-others-within-a-target/14231 "2025-06-29T14:34:55Z")

</div>

I have a target hello with two source files a.cpp and b.cpp. And both contain the #import directive: #import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no\_namespace rename("EOF", "EndOfFile") which will g…

---

## [How to limit maximum CXX\_STANDARD to prevent accidental C++17 or above code](https://discourse.cmake.org/t/how-to-limit-maximum-cxx-standard-to-prevent-accidental-c-17-or-above-code/9862)

<div class="topic-metadata">

**Author:** [@Ryanf55](https://discourse.cmake.org/u/Ryanf55)\
**Replies:** 11\
**Last updated:** [June 25, 2025, 4:02pm UTC](https://discourse.cmake.org/t/how-to-limit-maximum-cxx-standard-to-prevent-accidental-c-17-or-above-code/9862 "2025-06-25T16:02:40Z")

</div>

I have a C++ project built with CMake (an SDK), and a developer team that is used to coding in C++17 on other projects. Project Requirements: Only C++11 or C++14 language features must be used to compile the project. …

---

## [target\_include\_directories() vs headers in target\_sources()](https://discourse.cmake.org/t/target-include-directories-vs-headers-in-target-sources/2625)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 11\
**Last updated:** [June 24, 2025, 9:09pm UTC](https://discourse.cmake.org/t/target-include-directories-vs-headers-in-target-sources/2625 "2025-06-24T21:09:10Z")

</div>

Looking for advice on how to think about when to add directories with headers in them as target\_include\_directories() vs adding every header file by hand using target\_sources(). One thing I’ve noted is that I struggle t…

---

## [OpenSSL iOS build fails on bunch of undefined symbols](https://discourse.cmake.org/t/openssl-ios-build-fails-on-bunch-of-undefined-symbols/14273)

<div class="topic-metadata">

**Author:** [@shokarta](https://discourse.cmake.org/u/shokarta)\
**Replies:** 1\
**Last updated:** [June 24, 2025, 2:32pm UTC](https://discourse.cmake.org/t/openssl-ios-build-fails-on-bunch-of-undefined-symbols/14273 "2025-06-24T14:32:48Z")

</div>

Hello, I have a 3.3.2 version of iOS (well, now I realy only think its iOS version) which I dont remember how i installed, via brew or sudo perhaps (attached package if needs to be confirmed its realy for iOS and noc ma…

---

## [Does target\_link\_libraries(... PRIVATE) deduplicate?](https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275)

<div class="topic-metadata">

**Author:** [@bmcdonnell-fb](https://discourse.cmake.org/u/bmcdonnell-fb)\
**Replies:** 1\
**Last updated:** [June 21, 2025, 10:21pm UTC](https://discourse.cmake.org/t/does-target-link-libraries-private-deduplicate/14275 "2025-06-21T22:21:16Z")

</div>

I have an embedded C application with static libraries, where both the application and lib1 use lib2. (lib2 is not part of lib1’s interface.) If my CMakeLists.txt includes something like this: add\_executable(app app.c)…

---

## [Customize compiler warnings/definitions/includes on a per-source or per-directory basis](https://discourse.cmake.org/t/customize-compiler-warnings-definitions-includes-on-a-per-source-or-per-directory-basis/14278)

<div class="topic-metadata">

**Author:** [@sk\_anduril](https://discourse.cmake.org/u/sk_anduril)\
**Replies:** 0\
**Last updated:** [June 21, 2025, 1:34am UTC](https://discourse.cmake.org/t/customize-compiler-warnings-definitions-includes-on-a-per-source-or-per-directory-basis/14278 "2025-06-21T01:34:34Z")

</div>

I’d like to enhance my CMake build system so that I can “crank up” the warning level (ie, -Wall -Werror) on most of my code, but there are pieces of the source tree (maybe third-party vendor code or old legacy code we do…

---

## [Modifying cmake file to create packageConfig.cmake and friends](https://discourse.cmake.org/t/modifying-cmake-file-to-create-packageconfig-cmake-and-friends/14270)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 5\
**Last updated:** [June 20, 2025, 4:57pm UTC](https://discourse.cmake.org/t/modifying-cmake-file-to-create-packageconfig-cmake-and-friends/14270 "2025-06-20T16:57:01Z")

</div>

I am working to support the use of find\_package with a particular project. I added a file called SmtpMimeConfig.cmake which reads: include(CMakeFindDependencyMacro) # find\_dependency(xxx 2.0) include(${CMAKE\_CURRENT\_LI…

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

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