# Code

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

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

**Page:** 5

---

## [correct usage of cmake\_parse\_arguments: specialization of find\_package use-case](https://discourse.cmake.org/t/correct-usage-of-cmake-parse-arguments-specialization-of-find-package-use-case/15376)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 8\
**Last updated:** [December 12, 2025, 7:41pm UTC](https://discourse.cmake.org/t/correct-usage-of-cmake-parse-arguments-specialization-of-find-package-use-case/15376 "2025-12-12T19:41:45Z")

</div>

Hi, I’m experimenting with a macro find\_package in order to add some custom logic to find\_package. I’d like to use cmake\_parse\_arguments in order to filter the arguments. My first try is like this to get only the compo…

---

## [Protobuf generate relative to package/workdir APPEND\_PATH](https://discourse.cmake.org/t/protobuf-generate-relative-to-package-workdir-append-path/15379)

<div class="topic-metadata">

**Author:** [@rchildre3](https://discourse.cmake.org/u/rchildre3)\
**Replies:** 0\
**Last updated:** [December 9, 2025, 7:39pm UTC](https://discourse.cmake.org/t/protobuf-generate-relative-to-package-workdir-append-path/15379 "2025-12-09T19:39:27Z")

</div>

I am having difficulty with the protobuf\_generate of FindProtobuf.cmake in my project . ├── a │ ├── b │ │ ├── c │ │ │ ├── CMakeLists.txt │ │ │ └── d.proto ├── e │ ├── f │ │ ├── g │ │ │ ├──…

---

## [Question about "reserved" CMake properties](https://discourse.cmake.org/t/question-about-reserved-cmake-properties/6104)

<div class="topic-metadata">

**Author:** [@thorntonryan](https://discourse.cmake.org/u/thorntonryan)\
**Replies:** 9\
**Last updated:** [December 5, 2025, 11:54pm UTC](https://discourse.cmake.org/t/question-about-reserved-cmake-properties/6104 "2025-12-05T23:54:27Z")

</div>

The documentation for EXPORT\_PROPERTIES has this brief mention: Properties starting with INTERFACE\_ or IMPORTED\_ are not allowed as they are reserved for internal CMake use. But there’s seemingly no mention over here…

---

## [Configure clang-tidy when using an arm-none-eabi-gcc/g++ toolchain](https://discourse.cmake.org/t/configure-clang-tidy-when-using-an-arm-none-eabi-gcc-g-toolchain/10862)

<div class="topic-metadata">

**Author:** [@itavero](https://discourse.cmake.org/u/itavero)\
**Replies:** 5\
**Last updated:** [December 5, 2025, 11:27am UTC](https://discourse.cmake.org/t/configure-clang-tidy-when-using-an-arm-none-eabi-gcc-g-toolchain/10862 "2025-12-05T11:27:51Z")

</div>

We are developing embedded firmware for ARM Cortex-M, Xtensa and RISC-V microcontrollers. All come with a GCC based toolchain, for instance arm-none-eabi-gcc (arm-none-eabi-g++). We are using CMake 3.28.1 (or slightly …

---

## [find\_package inside function: scope issue](https://discourse.cmake.org/t/find-package-inside-function-scope-issue/15362)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 3\
**Last updated:** [December 4, 2025, 9:02pm UTC](https://discourse.cmake.org/t/find-package-inside-function-scope-issue/15362 "2025-12-04T21:02:06Z")

</div>

Hi, I’m wrapping some calls to find\_package inside functions. The issue is that the variables set by find\_package are not visible to the parent scope and I don’t know the list of this variables (so I cannot use set with…

---

## [Build error as header file not found](https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357)

<div class="topic-metadata">

**Author:** [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)\
**Replies:** 1\
**Last updated:** [December 3, 2025, 10:12pm UTC](https://discourse.cmake.org/t/build-error-as-header-file-not-found/15357 "2025-12-03T22:12:41Z")

</div>

Hi all I hve a C project for raspberry pico and I’m trying to organise it properly so it looks legible and decent. I am using the tinyusb library and one of the main ones that is important is tusb\_config.h, and after r…

---

## [How to install FILE\_SET CXX\_MODULES in a generic way?](https://discourse.cmake.org/t/how-to-install-file-set-cxx-modules-in-a-generic-way/15356)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 2\
**Last updated:** [December 3, 2025, 9:40am UTC](https://discourse.cmake.org/t/how-to-install-file-set-cxx-modules-in-a-generic-way/15356 "2025-12-03T09:40:09Z")

</div>

With this boost project using FILE\_SET HEADERS or FILE\_SET CXX\_MODULES must be installed if used: # Copyright 2019 Mike Dev # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE\_1\_…

---

## [Change C compilation to two step transformation like .m -\> .bc -\> .o](https://discourse.cmake.org/t/change-c-compilation-to-two-step-transformation-like-m-bc-o/15349)

<div class="topic-metadata">

**Author:** [@mulle-nat](https://discourse.cmake.org/u/mulle-nat)\
**Replies:** 0\
**Last updated:** [November 27, 2025, 10:16am UTC](https://discourse.cmake.org/t/change-c-compilation-to-two-step-transformation-like-m-bc-o/15349 "2025-11-27T10:16:44Z")

</div>

I actually want to write this make like rule in cmake %.o: %.m mulle-clang $(LLVM\_FLAGS) -c -emit-llvm -o $\*.bc $\< emcc $(EMCC\_FLAGS) -c -o $@ $\*.bc This is not trivial it seems. At least I haven’t figured it out…

---

## [On using \`find\_package(Threads)\`](https://discourse.cmake.org/t/on-using-find-package-threads/15346)

<div class="topic-metadata">

**Author:** [@asimplecoder](https://discourse.cmake.org/u/asimplecoder)\
**Replies:** 1\
**Last updated:** [November 26, 2025, 9:16pm UTC](https://discourse.cmake.org/t/on-using-find-package-threads/15346 "2025-11-26T21:16:37Z")

</div>

It is unclear how to properly use the find\_package(Threads). From the original example, linking against the imported target does not seem to set any of the target LINK\_OPTIONS / LINK\_FLAGS. Is this expected and intended…

---

## [Problem with set(CMAKE\_COMPILE\_WARNING\_AS\_ERROR OFF)](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 2\
**Last updated:** [November 25, 2025, 10:17am UTC](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338 "2025-11-25T10:17:03Z")

</div>

CMake version: 3.31.6-msvc6 My top level cmake file says: set(CMAKE\_COMPILE\_WARNING\_AS\_ERROR ON) and a lower level cmake file says: set(CMAKE\_COMPILE\_WARNING\_AS\_ERROR OFF) But, when I try to build the project the lowe…

---

## [protobuf using pkgconfig, how to generate files into a target build tree?](https://discourse.cmake.org/t/protobuf-using-pkgconfig-how-to-generate-files-into-a-target-build-tree/15336)

<div class="topic-metadata">

**Author:** [@MickeJ](https://discourse.cmake.org/u/MickeJ)\
**Replies:** 1\
**Last updated:** [November 22, 2025, 2:28pm UTC](https://discourse.cmake.org/t/protobuf-using-pkgconfig-how-to-generate-files-into-a-target-build-tree/15336 "2025-11-22T14:28:02Z")

</div>

Hi, due to project requirement only pkgconfig third party packages can be used, and cmake find\_package(Protobuf) and protobuf\_generate\_cpp() does not work when using pkgconfig-target defined protobuf. How do i make a ta…

---

## [Escape ; in ExternalProject\_Add()](https://discourse.cmake.org/t/escape-in-externalproject-add/15334)

<div class="topic-metadata">

**Author:** [@pedahl](https://discourse.cmake.org/u/pedahl)\
**Replies:** 0\
**Last updated:** [November 20, 2025, 4:55pm UTC](https://discourse.cmake.org/t/escape-in-externalproject-add/15334 "2025-11-20T16:55:14Z")

</div>

Hi i need to escape “;” on an argument in ExternalProject\_Add() ExternalProject\_Add( ${PROJECT\_NAME} SOURCE\_DIR “${\_myApp\_src\_path}” CONFIGURE\_COMMAND “” BUILD\_COMMAND ${MSBUILD\_EXE} ${\_myApp\_project\_file\_path} /…

---

## [Installing a list of headers dynamically generated at build time with names unknown at configure time](https://discourse.cmake.org/t/installing-a-list-of-headers-dynamically-generated-at-build-time-with-names-unknown-at-configure-time/15327)

<div class="topic-metadata">

**Author:** [@alcroito](https://discourse.cmake.org/u/alcroito)\
**Replies:** 0\
**Last updated:** [November 19, 2025, 3:48pm UTC](https://discourse.cmake.org/t/installing-a-list-of-headers-dynamically-generated-at-build-time-with-names-unknown-at-configure-time/15327 "2025-11-19T15:48:43Z")

</div>

Hi, I’m wondering what’s today’s best way to install a list of generated header files that are not known at configure time. I have an add\_custom\_command that runs a custom tool to parse a yaml file and then generate a …

---

## [cmake issue with clang-scan-deps and macosx](https://discourse.cmake.org/t/cmake-issue-with-clang-scan-deps-and-macosx/15322)

<div class="topic-metadata">

**Author:** [@vbl](https://discourse.cmake.org/u/vbl)\
**Replies:** 0\
**Last updated:** [November 18, 2025, 4:24pm UTC](https://discourse.cmake.org/t/cmake-issue-with-clang-scan-deps-and-macosx/15322 "2025-11-18T16:24:53Z")

</div>

Hello, cmake version 3.31.7 clang version 21.1.5 ninja version 1.13.1 Trying to cmake the following simple C++ coding and the following CMakeLists.txt with my macosx .. #include #include \<memory\_resource\> #include …

---

## [target\_precompile\_headers(PRIVATE) in library project does not work when using library functions in an executable project..](https://discourse.cmake.org/t/target-precompile-headers-private-in-library-project-does-not-work-when-using-library-functions-in-an-executable-project/15313)

<div class="topic-metadata">

**Author:** [@AlephVoid](https://discourse.cmake.org/u/AlephVoid)\
**Replies:** 1\
**Last updated:** [November 17, 2025, 6:55pm UTC](https://discourse.cmake.org/t/target-precompile-headers-private-in-library-project-does-not-work-when-using-library-functions-in-an-executable-project/15313 "2025-11-17T18:55:40Z")

</div>

Related question: Question. There is another problem which seems to stump me, that is it seems that target\_precompile\_headers with PRIVATE keyword(Which is a good practice) does not seem to work in my executable project…

---

## [Providing a dependency package::component only once if package::package (all components) has already provided](https://discourse.cmake.org/t/providing-a-dependency-package-component-only-once-if-package-package-all-components-has-already-provided/15315)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 1\
**Last updated:** [November 17, 2025, 1:50pm UTC](https://discourse.cmake.org/t/providing-a-dependency-package-component-only-once-if-package-package-all-components-has-already-provided/15315 "2025-11-17T13:50:21Z")

</div>

This is a bit an exotic situation which should be clearer with the example of using OpenSSL. I’m making a first library, let say A that uses only one OpenSSL components, for instance OpenSSL::SSL. I’m then making a sec…

---

## [Difficulties using a third-party cmake projects: missing \<package\>\_INCLUDE\_DIR(S) (and other)](https://discourse.cmake.org/t/difficulties-using-a-third-party-cmake-projects-missing-package-include-dir-s-and-other/15298)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 8\
**Last updated:** [November 17, 2025, 10:30am UTC](https://discourse.cmake.org/t/difficulties-using-a-third-party-cmake-projects-missing-package-include-dir-s-and-other/15298 "2025-11-17T10:30:45Z")

</div>

I’m trying to use a library named Alglib which has no CMake support. Such support is provided here: https://github.com/S-Dafarra/alglib-cmake. My issue is that it generates a target Alglib without namespace and, in my o…

---

## [Making a library that's importable with \`find\_package\` but includes targets for sources and pre-built .so](https://discourse.cmake.org/t/making-a-library-thats-importable-with-find-package-but-includes-targets-for-sources-and-pre-built-so/15314)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 0\
**Last updated:** [November 17, 2025, 10:16am UTC](https://discourse.cmake.org/t/making-a-library-thats-importable-with-find-package-but-includes-targets-for-sources-and-pre-built-so/15314 "2025-11-17T10:16:15Z")

</div>

This is, I guess, a long gestation follow-up to a previous post of mine, installing a SHARED IMPORTED library's symlinks and real library file . The situation was that we were trying to package a library and a set of ex…

---

## [How to find\_package(... OPTIONAL) in CMake 3?](https://discourse.cmake.org/t/how-to-find-package-optional-in-cmake-3/15309)

<div class="topic-metadata">

**Author:** [@a\_toldaiev](https://discourse.cmake.org/u/a_toldaiev)\
**Replies:** 3\
**Last updated:** [November 16, 2025, 3:58pm UTC](https://discourse.cmake.org/t/how-to-find-package-optional-in-cmake-3/15309 "2025-11-16T15:58:48Z")

</div>

I would like to check whether Catch2 is installed, and if not then FetchContent it. CMake 4 has the OPTIONAL keyword to try find\_package without throwing a warning. So, you can do something like this: # get Catch2 if(TA…

---

## [Cannot include header files inside the header files in library project (With executable project for testing)](https://discourse.cmake.org/t/cannot-include-header-files-inside-the-header-files-in-library-project-with-executable-project-for-testing/15311)

<div class="topic-metadata">

**Author:** [@AlephVoid](https://discourse.cmake.org/u/AlephVoid)\
**Replies:** 2\
**Last updated:** [November 16, 2025, 1:52pm UTC](https://discourse.cmake.org/t/cannot-include-header-files-inside-the-header-files-in-library-project-with-executable-project-for-testing/15311 "2025-11-16T13:52:47Z")

</div>

I have the problem which stumped me for 3 days. I am creating an C++ library which inside the library codebase includes are more freely defined than on an executable. For example: #include "base\_task.h" Inside library…

---

## [Is it possible to switch compilers for certain parts of a CMakeLists.txt?](https://discourse.cmake.org/t/is-it-possible-to-switch-compilers-for-certain-parts-of-a-cmakelists-txt/15310)

<div class="topic-metadata">

**Author:** [@guest271314](https://discourse.cmake.org/u/guest271314)\
**Replies:** 0\
**Last updated:** [November 16, 2025, 12:46am UTC](https://discourse.cmake.org/t/is-it-possible-to-switch-compilers-for-certain-parts-of-a-cmakelists-txt/15310 "2025-11-16T00:46:40Z")

</div>

I’m trying to target WASM for a library that was not originally written with compilation to WASM as a goal. The existing CMakeLists.txt builds protobuf and executes protoc. WASM doesn’t have subprocess calls or \<sys/wait…

---

## [Correct usage of WINDOWS\_EXPORT\_ALL\_SYMBOLS](https://discourse.cmake.org/t/correct-usage-of-windows-export-all-symbols/15306)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 1\
**Last updated:** [November 14, 2025, 7:37pm UTC](https://discourse.cmake.org/t/correct-usage-of-windows-export-all-symbols/15306 "2025-11-14T19:37:13Z")

</div>

I’m trying to use a library named Alglib which has no CMake support. Such support is provided here: GitHub - S-Dafarra/alglib-cmake: CMake files to download and build ALGLIB, to be used as an external library.. I can bu…

---

## [\`TYPE DOC\` behaviour with and without GNUInstallDirs](https://discourse.cmake.org/t/type-doc-behaviour-with-and-without-gnuinstalldirs/15301)

<div class="topic-metadata">

**Author:** [@Bo98](https://discourse.cmake.org/u/Bo98)\
**Replies:** 0\
**Last updated:** [November 13, 2025, 5:20am UTC](https://discourse.cmake.org/t/type-doc-behaviour-with-and-without-gnuinstalldirs/15301 "2025-11-13T05:20:08Z")

</div>

install accepts multiple TYPE options, each of which will use CMAKE\_INSTALL\_\* variables if available before using the built-in default. Nearly all of the built-in defaults match the defaults offered by GNUInstallDirs and…

---

## [target\_sources() and target\_include\_directories() behaviour](https://discourse.cmake.org/t/target-sources-and-target-include-directories-behaviour/15297)

<div class="topic-metadata">

**Author:** [@moonsun\_interstell](https://discourse.cmake.org/u/moonsun_interstell)\
**Replies:** 3\
**Last updated:** [November 12, 2025, 3:17pm UTC](https://discourse.cmake.org/t/target-sources-and-target-include-directories-behaviour/15297 "2025-11-12T15:17:58Z")

</div>

i am not sure about how cmake retrieves header files. (see cmake code below) my expectation is that it looks only what is defined in target\_include\_directories(). According to the cmake text file and the directory stru…

---

## [import std with gcc-15 (libstdc++)](https://discourse.cmake.org/t/import-std-with-gcc-15-libstdc/15149)

<div class="topic-metadata">

**Author:** [@anarthal](https://discourse.cmake.org/u/anarthal)\
**Replies:** 2\
**Last updated:** [November 9, 2025, 3:42pm UTC](https://discourse.cmake.org/t/import-std-with-gcc-15-libstdc/15149 "2025-11-09T15:42:13Z")

</div>

From version 15, libstdc++ ships with support for the std and std.compat modules (located under /usr/include/c++/15/bits/std.cc and /usr/include/c++/15/bits/std.compat.cc in a standard Ubuntu 25.10 installation). Is ther…

---

## [Exporting library generated by custom command](https://discourse.cmake.org/t/exporting-library-generated-by-custom-command/15285)

<div class="topic-metadata">

**Author:** [@apozharski](https://discourse.cmake.org/u/apozharski)\
**Replies:** 0\
**Last updated:** [November 6, 2025, 7:55am UTC](https://discourse.cmake.org/t/exporting-library-generated-by-custom-command/15285 "2025-11-06T07:55:37Z")

</div>

Hello, I am currently writing a Julia package that is used to ahead-of-time compile some Julia code so it can be used as a C-interface. This uses the new JuliaC.jl package which acts (essentially) as a compiler, taking a…

---

## [Targets from sources generated during build time](https://discourse.cmake.org/t/targets-from-sources-generated-during-build-time/15278)

<div class="topic-metadata">

**Author:** [@egor\_tensin](https://discourse.cmake.org/u/egor_tensin)\
**Replies:** 0\
**Last updated:** [October 30, 2025, 8:40pm UTC](https://discourse.cmake.org/t/targets-from-sources-generated-during-build-time/15278 "2025-10-30T20:40:30Z")

</div>

I have a situation: I have target test with only one source file test.c. I build it with -save-temps, modify the .s (in CMakeFiles/test.dir/) file a bit, and want to create a target test.patched that builds from that pat…

---

## [Help with a baking one binary's hash into another](https://discourse.cmake.org/t/help-with-a-baking-one-binarys-hash-into-another/15276)

<div class="topic-metadata">

**Author:** [@egor\_tensin](https://discourse.cmake.org/u/egor_tensin)\
**Replies:** 3\
**Last updated:** [October 29, 2025, 8:57pm UTC](https://discourse.cmake.org/t/help-with-a-baking-one-binarys-hash-into-another/15276 "2025-10-29T20:57:04Z")

</div>

I have a situation where one binary’s hash needs to be baked into another as a define. So, something like this: add\_executable(app1 app1.c) add\_executable(app2 app2.c) target\_compile\_definitions(app2 -DHASH="APP1\_HASH"…

---

## [CMakeLists.txt for Raspberry Pi Pico Project](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273)

<div class="topic-metadata">

**Author:** [@DJim53](https://discourse.cmake.org/u/DJim53)\
**Replies:** 4\
**Last updated:** [October 29, 2025, 7:39am UTC](https://discourse.cmake.org/t/cmakelists-txt-for-raspberry-pi-pico-project/15273 "2025-10-29T07:39:56Z")

</div>

I would like to perform the initialisation of a PIO in a function in the raik060spilib.c instead of in raik060spicom.c. So I have include “raik060spicom.pio.h” in raik060spilib.h and raik060spilib.c. However, I don’t u…

---

## [Generator expressions in VS\_DOTNET\_REFERENCE\_refname](https://discourse.cmake.org/t/generator-expressions-in-vs-dotnet-reference-refname/15271)

<div class="topic-metadata">

**Author:** [@retif](https://discourse.cmake.org/u/retif)\
**Replies:** 1\
**Last updated:** [October 28, 2025, 8:34pm UTC](https://discourse.cmake.org/t/generator-expressions-in-vs-dotnet-reference-refname/15271 "2025-10-28T20:34:02Z")

</div>

Are generator expressions supported for the VS\_DOTNET\_REFERENCE\_refname target property? This is how I tried to use it: # the \`some\` is a C# library which needs to refer to the DLL from the target \`thing\` set\_target\_pr…

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

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