# Code

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

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

**Page:** 20

---

## [Getting a list of all source files for the running clang-format](https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217)

<div class="topic-metadata">

**Author:** [@gracicot](https://discourse.cmake.org/u/gracicot)\
**Replies:** 1\
**Last updated:** [July 10, 2024, 9:34pm UTC](https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217 "2024-07-10T21:34:33Z")

</div>

I’m creating a custom target to run clang-format on all the source file of a target. Here’s what I got: add\_custom\_target(format-fix COMMAND clang-format -style=file -i $\<TARGET\_PROPERTY:mylib,SOURCES\> COMMAND\_…

---

## [Linking a prebuilt static library](https://discourse.cmake.org/t/linking-a-prebuilt-static-library/11199)

<div class="topic-metadata">

**Author:** [@Shackster](https://discourse.cmake.org/u/Shackster)\
**Replies:** 5\
**Last updated:** [July 10, 2024, 11:59am UTC](https://discourse.cmake.org/t/linking-a-prebuilt-static-library/11199 "2024-07-10T11:59:14Z")

</div>

I am trying to link a static library to my main executable but I keep receiving the following error: main.obj : error LNK2019: unresolved external symbol “void \_\_cdecl HelloWorld(void)” (?HelloWorld@@ YAXXZ) referenced…

---

## [Linking to shared library built within my project works under linux but not Windows](https://discourse.cmake.org/t/linking-to-shared-library-built-within-my-project-works-under-linux-but-not-windows/8522)

<div class="topic-metadata">

**Author:** [@RichS](https://discourse.cmake.org/u/RichS)\
**Replies:** 6\
**Last updated:** [July 9, 2024, 1:31pm UTC](https://discourse.cmake.org/t/linking-to-shared-library-built-within-my-project-works-under-linux-but-not-windows/8522 "2024-07-09T13:31:03Z")

</div>

I have fairly complex code called Xyce that builds statically under mac/linux and windows with CMake just fine. When I switch to building with shared libraries, the main target “Xyce” will depend on the dynamic library …

---

## [How Consuming Installed C++20 Modules the portable way](https://discourse.cmake.org/t/how-consuming-installed-c-20-modules-the-portable-way/11188)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 0\
**Last updated:** [July 7, 2024, 8:17pm UTC](https://discourse.cmake.org/t/how-consuming-installed-c-20-modules-the-portable-way/11188 "2024-07-07T20:17:13Z")

</div>

If I compile a C++20 module with gcc-14, it is not possible to use it with clang-18! see too consuming-installed-c-20-modules From https://anarthal.github.io/cppblog/modules2#cmake I used this workaround: cmake\_minim…

---

## [Generator expression in RUNTIME\_DEPENDENCY\_SET DIRECTORIES](https://discourse.cmake.org/t/generator-expression-in-runtime-dependency-set-directories/9612)

<div class="topic-metadata">

**Author:** [@jrath](https://discourse.cmake.org/u/jrath)\
**Replies:** 4\
**Last updated:** [July 3, 2024, 5:56pm UTC](https://discourse.cmake.org/t/generator-expression-in-runtime-dependency-set-directories/9612 "2024-07-03T17:56:38Z")

</div>

Hi, I try to work around a shared library with a bad RUNPATH on linux. The RUNPATH does not exist on my local host but is included in the library delivery that I get for the moment. This leads to a “file Could not resol…

---

## [find\_library unable to find library even with HINTS/PATHS](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851)

<div class="topic-metadata">

**Author:** [@zwimer](https://discourse.cmake.org/u/zwimer)\
**Replies:** 6\
**Last updated:** [July 3, 2024, 7:49am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851 "2024-07-03T07:49:27Z")

</div>

I am trying to use cmake 3.22.1 to find the Z3 shared library. To start, here is where my Z3 library is located: ls /usr/lib64 | grep z3 …

---

## [How to use fixup\_bundle properly?](https://discourse.cmake.org/t/how-to-use-fixup-bundle-properly/11128)

<div class="topic-metadata">

**Author:** [@ikspress](https://discourse.cmake.org/u/ikspress)\
**Replies:** 8\
**Last updated:** [July 1, 2024, 9:13am UTC](https://discourse.cmake.org/t/how-to-use-fixup-bundle-properly/11128 "2024-07-01T09:13:26Z")

</div>

I’m a new to CMake, please forgive me if my post bother you. I attempted to write a CMake project with BundleUtilities, but there some doubts that bother me. My project install directory like this: . ├── bin │ ├── my…

---

## [Generator expression in ExternalProject\_Add() / CMAKE\_ARGS](https://discourse.cmake.org/t/generator-expression-in-externalproject-add-cmake-args/11111)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 2\
**Last updated:** [June 28, 2024, 9:27am UTC](https://discourse.cmake.org/t/generator-expression-in-externalproject-add-cmake-args/11111 "2024-06-28T09:27:07Z")

</div>

Hello, When using the ExternalProject\_Add(), I try to use a generator expression with the CMAKE\_ARGS argument (the … contains actually some variables): ExternalProject\_Add(${APP\_NAME}\_${module}\_${require\_module\_PLATFOR…

---

## [Tutorial Step 10: missing header 'mathfunctions\_export.h'](https://discourse.cmake.org/t/tutorial-step-10-missing-header-mathfunctions-export-h/11092)

<div class="topic-metadata">

**Author:** [@codefrog](https://discourse.cmake.org/u/codefrog)\
**Replies:** 13\
**Last updated:** [June 26, 2024, 2:06pm UTC](https://discourse.cmake.org/t/tutorial-step-10-missing-header-mathfunctions-export-h/11092 "2024-06-26T14:06:19Z")

</div>

I’m just run through Step 10 of the Tutorial, and am trying to use the GenerateExportHeader module. However, when I build, I get the error: fatal error: mathfunctions\_export.h: No such file or directory 10 | #includ…

---

## [Installing dll dependencies using RUNTIME\_DEPENDENCY\_SET and $\<TARGET\_RUNTIME\_DLL\_DIRS:${target}\> bug?](https://discourse.cmake.org/t/installing-dll-dependencies-using-runtime-dependency-set-and-target-runtime-dll-dirs-target-bug/10959)

<div class="topic-metadata">

**Author:** [@octopus42](https://discourse.cmake.org/u/octopus42)\
**Replies:** 4\
**Last updated:** [June 25, 2024, 11:10am UTC](https://discourse.cmake.org/t/installing-dll-dependencies-using-runtime-dependency-set-and-target-runtime-dll-dirs-target-bug/10959 "2024-06-25T11:10:11Z")

</div>

I think I found an issue with how the cmake\_install.cmake is generated or I’m using it wrong. Using the latest, 3.29.4, and attempting to create an install routine to bundle runtime dlls, for a product; dlls are for thi…

---

## [Builds ok with Visual Studio but fails with nmake](https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078)

<div class="topic-metadata">

**Author:** [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)\
**Replies:** 1\
**Last updated:** [June 24, 2024, 7:58am UTC](https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078 "2024-06-24T07:58:23Z")

</div>

I have a fortran project that has a target that involves compiling a number of modules using the Intel compiler. CMAKE\_Fortran\_MODULE\_DIRECTORY is set to a common include directory for the target. However, I need the mo…

---

## [Help with pkg\_check\_modules](https://discourse.cmake.org/t/help-with-pkg-check-modules/11075)

<div class="topic-metadata">

**Author:** [@wearyhacker](https://discourse.cmake.org/u/wearyhacker)\
**Replies:** 9\
**Last updated:** [June 23, 2024, 12:52pm UTC](https://discourse.cmake.org/t/help-with-pkg-check-modules/11075 "2024-06-23T12:52:09Z")

</div>

I am trying to use pkg\_check\_modules to locate the sndfile library module on Linux. The library has an entry in the pkg-config database and the log shows that the sndfile module has been found. Found PkgConfig: /usr/bin…

---

## [Conventions for Linking Implicit Dependencies of an embedded Multi-Language Static Library?](https://discourse.cmake.org/t/conventions-for-linking-implicit-dependencies-of-an-embedded-multi-language-static-library/11073)

<div class="topic-metadata">

**Author:** [@mabruzzo](https://discourse.cmake.org/u/mabruzzo)\
**Replies:** 0\
**Last updated:** [June 21, 2024, 2:53pm UTC](https://discourse.cmake.org/t/conventions-for-linking-implicit-dependencies-of-an-embedded-multi-language-static-library/11073 "2024-06-21T14:53:36Z")

</div>

I wanted to ask if there is any prevailing wisdom (or existing conventions) for linking language-specific runtime dependencies of a multi-language library. To be more concrete: I recently ported a small scientific lib…

---

## [CMake to invoke cc1 and as directly](https://discourse.cmake.org/t/cmake-to-invoke-cc1-and-as-directly/11071)

<div class="topic-metadata">

**Author:** [@chnarius](https://discourse.cmake.org/u/chnarius)\
**Replies:** 0\
**Last updated:** [June 21, 2024, 11:01am UTC](https://discourse.cmake.org/t/cmake-to-invoke-cc1-and-as-directly/11071 "2024-06-21T11:01:15Z")

</div>

hello Guys, I am trying to write CMakeLists.txt to build an execute binary using cc1.exe, as.exe and ld.exe (there is no gcc.exe in the prebuilt toolchain :joy: :joy:). That means I need to do the compiling/assembly/lin…

---

## [Unsupported platform error message](https://discourse.cmake.org/t/unsupported-platform-error-message/11057)

<div class="topic-metadata">

**Author:** [@Eya](https://discourse.cmake.org/u/Eya)\
**Replies:** 2\
**Last updated:** [June 20, 2024, 8:12am UTC](https://discourse.cmake.org/t/unsupported-platform-error-message/11057 "2024-06-20T08:12:43Z")

</div>

This is the CMakeCache file. For build in directory: /Users/rosendjip/Documents/Perso/Courses/Programming/WxWidgets/hello\_world It was generated by CMake: /opt/homebrew/Cellar/cmake/3.29.6/bin/cmake You can edit this fil…

---

## [Dependency A-\>B-\>C](https://discourse.cmake.org/t/dependency-a-b-c/11061)

<div class="topic-metadata">

**Author:** [@helloworld](https://discourse.cmake.org/u/helloworld)\
**Replies:** 0\
**Last updated:** [June 19, 2024, 11:42pm UTC](https://discourse.cmake.org/t/dependency-a-b-c/11061 "2024-06-19T23:42:17Z")

</div>

Hello, I am reading about target\_link\_libraries and the PUBLIC contract. I have this specific situation: project/ ├── CMakeLists.txt (1) ├── dir1/ │ ├── subdir1/ │ │ └── CMakeLists.txt (2) │ └── src/ │ …

---

## [Is there a way to download and include just a header from Boost?](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 4\
**Last updated:** [June 19, 2024, 2:38pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054 "2024-06-19T14:38:33Z")

</div>

I am using boost::dynamic\_bitset in one of my projects. Is there a way to tell CMake to just download that header and have it available, without 1) having to download the whole of Boost, and 2) having to compile anythin…

---

## [.NETStandard compilation with CMake](https://discourse.cmake.org/t/netstandard-compilation-with-cmake/11052)

<div class="topic-metadata">

**Author:** [@Sameer\_Joshi](https://discourse.cmake.org/u/Sameer_Joshi)\
**Replies:** 4\
**Last updated:** [June 19, 2024, 1:32pm UTC](https://discourse.cmake.org/t/netstandard-compilation-with-cmake/11052 "2024-06-19T13:32:06Z")

</div>

I have an existing C# project which is targetted for .net48 and .netstandard2.0. It works fine when I compile it separately. I had to work on moving this project to CMake based project and I am encountering issues of the…

---

## [netcoreapp3.1 project with CMake](https://discourse.cmake.org/t/netcoreapp3-1-project-with-cmake/2917)

<div class="topic-metadata">

**Author:** [@pifopi](https://discourse.cmake.org/u/pifopi)\
**Replies:** 2\
**Last updated:** [June 18, 2024, 5:17pm UTC](https://discourse.cmake.org/t/netcoreapp3-1-project-with-cmake/2917 "2024-06-18T17:17:27Z")

</div>

Hello everyone ! I’m creating this post today because I’m wondering how to generate a netcoreapp3.1 project with CMake. I have seen some examples online (for net framework 4.7.2) mentionning this set(CMAKE\_DOTNET\_TARG…

---

## [CMake + CUDA + Clang fails](https://discourse.cmake.org/t/cmake-cuda-clang-fails/8657)

<div class="topic-metadata">

**Author:** [@ptal](https://discourse.cmake.org/u/ptal)\
**Replies:** 10\
**Last updated:** [June 18, 2024, 5:52am UTC](https://discourse.cmake.org/t/cmake-cuda-clang-fails/8657 "2024-06-18T05:52:27Z")

</div>

Hello, I’m trying to compile this project with Clang instead of NVCC. I am clueless why it is not working and could not find a lot of information online. I’m running CMake 3.26.4, Clang 15.0.7 and CUDA 12.1. Here is w…

---

## [How to create pkgconfig file](https://discourse.cmake.org/t/how-to-create-pkgconfig-file/10337)

<div class="topic-metadata">

**Author:** [@Peter\_Featherstone](https://discourse.cmake.org/u/Peter_Featherstone)\
**Replies:** 34\
**Last updated:** [June 17, 2024, 7:02pm UTC](https://discourse.cmake.org/t/how-to-create-pkgconfig-file/10337 "2024-06-17T19:02:00Z")

</div>

I am trying to generate a pkg-config (.pc) file in cmake for my library. This requires finding the public compile flags and linker flags. I’m currently using get\_target\_property(MYTARGET\_LINK\_LIBRARIES my\_target INTE…

---

## [SDL static compillation](https://discourse.cmake.org/t/sdl-static-compillation/11021)

<div class="topic-metadata">

**Author:** [@boyaroslav](https://discourse.cmake.org/u/boyaroslav)\
**Replies:** 8\
**Last updated:** [June 17, 2024, 11:44am UTC](https://discourse.cmake.org/t/sdl-static-compillation/11021 "2024-06-17T11:44:45Z")

</div>

Hello! I want to compile my project with SDL2, SDL2\_image, SDL2\_ttf, SDL2\_mixer, but I cant find how to create cmake file for it. Ive been searching for it for a really long time. Please help me!

---

## [How to compile a program with setuid?](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983)

<div class="topic-metadata">

**Author:** [@ogogon](https://discourse.cmake.org/u/ogogon)\
**Replies:** 4\
**Last updated:** [June 17, 2024, 7:53am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983 "2024-06-17T07:53:24Z")

</div>

Colleagues, please tell me how to solve my problem - I want the program have set setuid after compilation. Right now I’m using a very simple CMakeLists.txt: set (HEADERS ...) set (SOURCES ...) add\_executable myprog ${…

---

## [CMake for C# project with nuget package references](https://discourse.cmake.org/t/cmake-for-c-project-with-nuget-package-references/11028)

<div class="topic-metadata">

**Author:** [@Sameer\_Joshi](https://discourse.cmake.org/u/Sameer_Joshi)\
**Replies:** 2\
**Last updated:** [June 17, 2024, 4:32am UTC](https://discourse.cmake.org/t/cmake-for-c-project-with-nuget-package-references/11028 "2024-06-17T04:32:25Z")

</div>

Hi All, I am looking for generating a CMakeLists.txt file for my C# csproj project which is .netstandard 2.0 based. It has project references and nuget package references. How can I add those package references in the…

---

## [Error: @4,9: Invalid "include" field in CMake Preset](https://discourse.cmake.org/t/error-4-9-invalid-include-field-in-cmake-preset/10554)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 12\
**Last updated:** [June 16, 2024, 7:21pm UTC](https://discourse.cmake.org/t/error-4-9-invalid-include-field-in-cmake-preset/10554 "2024-06-16T19:21:14Z")

</div>

${hostSystemName} The name of the host operating system. Contains the same value as CMAKE\_HOST\_SYSTEM\_NAME. This is allowed in preset files specifying version 3 or above. I am wondering this fails: { "version": 7, …

---

## [add\_custom\_command, problem with quotes and spaces](https://discourse.cmake.org/t/add-custom-command-problem-with-quotes-and-spaces/11014)

<div class="topic-metadata">

**Author:** [@Dennis\_Ferron](https://discourse.cmake.org/u/Dennis_Ferron)\
**Replies:** 4\
**Last updated:** [June 14, 2024, 11:46pm UTC](https://discourse.cmake.org/t/add-custom-command-problem-with-quotes-and-spaces/11014 "2024-06-14T23:46:26Z")

</div>

If I build up the COMMAND for add\_custom\_command in a variable, and that variable’s value has spaces in it (as it might if the string combines args like “x y”, or “-o outfile.txt”), then the content of that variable gets…

---

## [First-class support for modulemap in FRAMEWORK targets](https://discourse.cmake.org/t/first-class-support-for-modulemap-in-framework-targets/11013)

<div class="topic-metadata">

**Author:** [@JoeM](https://discourse.cmake.org/u/JoeM)\
**Replies:** 2\
**Last updated:** [June 13, 2024, 9:09pm UTC](https://discourse.cmake.org/t/first-class-support-for-modulemap-in-framework-targets/11013 "2024-06-13T21:09:21Z")

</div>

Setting the FRAMEWORK property on a library target builds a framework bundle on Apple platforms. The support for (as example) PUBLIC\_HEADERS generating the Headers symlink and similar properties is really nice. To use t…

---

## [Debug & Release builds in Xcode](https://discourse.cmake.org/t/debug-release-builds-in-xcode/10965)

<div class="topic-metadata">

**Author:** [@jasonaylward](https://discourse.cmake.org/u/jasonaylward)\
**Replies:** 2\
**Last updated:** [June 13, 2024, 6:53pm UTC](https://discourse.cmake.org/t/debug-release-builds-in-xcode/10965 "2024-06-13T18:53:41Z")

</div>

Is there a way to get the Build Configurations to work in Xcode when you have a multi-config project? I can use cmake --build ./build --config Release but if I build Debug or Release from the Xcode schemes, they both ju…

---

## [Where is documentation for ZERO\_CHECK and INSTALL targets ?](https://discourse.cmake.org/t/where-is-documentation-for-zero-check-and-install-targets/11010)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 0\
**Last updated:** [June 13, 2024, 9:39am UTC](https://discourse.cmake.org/t/where-is-documentation-for-zero-check-and-install-targets/11010 "2024-06-13T09:39:36Z")

</div>

Hello, I use Visual Studio generator, and it produces four targets (-\> 4 projects in VS), including ZERO\_CHECK and INSTALL. There is nothing about these points the the generator documentation. With a know search engine…

---

## [How to set a macro to all target\_link\_libraries with target\_compile\_definitions](https://discourse.cmake.org/t/how-to-set-a-macro-to-all-target-link-libraries-with-target-compile-definitions/11000)

<div class="topic-metadata">

**Author:** [@pbizimis](https://discourse.cmake.org/u/pbizimis)\
**Replies:** 2\
**Last updated:** [June 12, 2024, 12:23pm UTC](https://discourse.cmake.org/t/how-to-set-a-macro-to-all-target-link-libraries-with-target-compile-definitions/11000 "2024-06-12T12:23:31Z")

</div>

Hey everyone, I cannot get a preprocessor macro from CMake to the whole project. I have a simple project structure (GitHub - pbizimis/keyboard): Project/ ├─ CMakeLists.txt (1) ├─ src/ │ ├─ CMakeLists.txt (2) │ ├─ ma…

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

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