# Code

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

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

**Page:** 27

---

## [Inject a user header file into a library](https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724)

<div class="topic-metadata">

**Author:** [@erincatto](https://discourse.cmake.org/u/erincatto)\
**Replies:** 1\
**Last updated:** [December 26, 2023, 7:04pm UTC](https://discourse.cmake.org/t/inject-a-user-header-file-into-a-library/9724 "2023-12-26T19:04:01Z")

</div>

Is there a good pattern for a user to optionally inject a user header file into my library? This would setup some defines that override default defines and doesn’t require putting these defines into every compilation cal…

---

## [Extract linker args for dependencies](https://discourse.cmake.org/t/extract-linker-args-for-dependencies/9702)

<div class="topic-metadata">

**Author:** [@tgross35](https://discourse.cmake.org/u/tgross35)\
**Replies:** 1\
**Last updated:** [December 24, 2023, 1:30am UTC](https://discourse.cmake.org/t/extract-linker-args-for-dependencies/9702 "2023-12-24T01:30:28Z")

</div>

I have a setup where an external tool (cargo) produces a shared library, but it needs to be able to link dependencies generated by CMake. My current setup looks like this: add\_custom\_target(${target\_name} ALL COMMAND …

---

## [Issues with \`opmi-cxx.pc\`'s ldflags and \`pkg\_check\_modules(... IMPORTED\_TARGET ...)\`](https://discourse.cmake.org/t/issues-with-opmi-cxx-pc-s-ldflags-and-pkg-check-modules-imported-target/9651)

<div class="topic-metadata">

**Author:** [@Someone](https://discourse.cmake.org/u/Someone)\
**Replies:** 2\
**Last updated:** [December 22, 2023, 1:23am UTC](https://discourse.cmake.org/t/issues-with-opmi-cxx-pc-s-ldflags-and-pkg-check-modules-imported-target/9651 "2023-12-22T01:23:17Z")

</div>

Hi! I’ve been looking into linking openmpi using its .pc files (I’ve got a separate question about FindMPI.cmake, but this post is about using the pkg-config information explicitly), and I found myself confused by how cm…

---

## [Piping the output of a script to the STDIN of a compiler](https://discourse.cmake.org/t/piping-the-output-of-a-script-to-the-stdin-of-a-compiler/9614)

<div class="topic-metadata">

**Author:** [@Agent13](https://discourse.cmake.org/u/Agent13)\
**Replies:** 6\
**Last updated:** [December 20, 2023, 12:37am UTC](https://discourse.cmake.org/t/piping-the-output-of-a-script-to-the-stdin-of-a-compiler/9614 "2023-12-20T00:37:18Z")

</div>

Hi, I’m trying to move a project from GNU make to cmake. The old project has some make code shown below which does some “interesting” things. My port strategy is to basically re-implement the make steps within cmake. A…

---

## [Unexpected build of unused target](https://discourse.cmake.org/t/unexpected-build-of-unused-target/9626)

<div class="topic-metadata">

**Author:** [@geertj](https://discourse.cmake.org/u/geertj)\
**Replies:** 4\
**Last updated:** [December 19, 2023, 11:36pm UTC](https://discourse.cmake.org/t/unexpected-build-of-unused-target/9626 "2023-12-19T23:36:22Z")

</div>

Hi, In my project, I have a library called “Library” and a library called “LibraryTest”. They both compile from the same sources. The former is exported, the latter is compiled with address sanitation and linked against…

---

## [Prevent rebuild every time for add\_custom\_target](https://discourse.cmake.org/t/prevent-rebuild-every-time-for-add-custom-target/9556)

<div class="topic-metadata">

**Author:** [@fksun](https://discourse.cmake.org/u/fksun)\
**Replies:** 13\
**Last updated:** [December 19, 2023, 10:38pm UTC](https://discourse.cmake.org/t/prevent-rebuild-every-time-for-add-custom-target/9556 "2023-12-19T22:38:48Z")

</div>

Hello all, When using add\_custom\_target with ALL option, I found that the target is built every time I run ninja. Following the guidelines in https://discourse.cmake.org/t/add-custom-command-rebuilds-every-time/8213 (U…

---

## [CMake : No output of the building process](https://discourse.cmake.org/t/cmake-no-output-of-the-building-process/9658)

<div class="topic-metadata">

**Author:** [@Raphy](https://discourse.cmake.org/u/Raphy)\
**Replies:** 1\
**Last updated:** [December 19, 2023, 12:31pm UTC](https://discourse.cmake.org/t/cmake-no-output-of-the-building-process/9658 "2023-12-19T12:31:25Z")

</div>

With this CMakeLists.txt file: include(FetchContent) FetchContent\_Declare( WebKit2 #URL https://webkitgtk.org/releases/webkitgtk-2.42.3.tar.xz GIT\_REPOSITORY https://github.com/raphael10-collab/webkitgtkIncludable…

---

## [Download Meson and Mesa to local repo and build](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674)

<div class="topic-metadata">

**Author:** [@john](https://discourse.cmake.org/u/john)\
**Replies:** 5\
**Last updated:** [December 19, 2023, 12:13pm UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674 "2023-12-19T12:13:14Z")

</div>

Good afternoon, I am trying to create a repository that will build and install Mesa 3D in a local directory. I have read that Mesa 3D needs to be configured using Meson but I would like both of these downloaded and buil…

---

## [How to propagate a property from a lib to a executable](https://discourse.cmake.org/t/how-to-propagate-a-property-from-a-lib-to-a-executable/9643)

<div class="topic-metadata">

**Author:** [@Jerome\_DESFIEUX](https://discourse.cmake.org/u/Jerome_DESFIEUX)\
**Replies:** 2\
**Last updated:** [December 19, 2023, 9:48am UTC](https://discourse.cmake.org/t/how-to-propagate-a-property-from-a-lib-to-a-executable/9643 "2023-12-19T09:48:16Z")

</div>

I am in a situation where I build libraries which might set some properties, and the I build a executable which will need to agregate all the lib properties to actually use/process them. How can I achieve this ? (one r…

---

## [troubles with find\_package and CMAKE\_PREFIX\_PATH](https://discourse.cmake.org/t/troubles-with-find-package-and-cmake-prefix-path/9414)

<div class="topic-metadata">

**Author:** [@bytecounter](https://discourse.cmake.org/u/bytecounter)\
**Replies:** 19\
**Last updated:** [December 19, 2023, 4:36am UTC](https://discourse.cmake.org/t/troubles-with-find-package-and-cmake-prefix-path/9414 "2023-12-19T04:36:55Z")

</div>

Hello, i have the problem that i’ve build cpython on my own in /home/stuv/build/cpython and i set CMAKE\_PREFIX\_PATH to this path but when i try find\_package( Python3 REQUIRED VERSION 3.13 COMPONENTS Development ) h…

---

## [TARGET\_FILE\_DIR seems to be wrong when only MACOSX\_BUNDLE\_BUNDLE\_NAME is set](https://discourse.cmake.org/t/target-file-dir-seems-to-be-wrong-when-only-macosx-bundle-bundle-name-is-set/9670)

<div class="topic-metadata">

**Author:** [@Martin\_Bonac](https://discourse.cmake.org/u/Martin_Bonac)\
**Replies:** 2\
**Last updated:** [December 19, 2023, 4:12am UTC](https://discourse.cmake.org/t/target-file-dir-seems-to-be-wrong-when-only-macosx-bundle-bundle-name-is-set/9670 "2023-12-19T04:12:34Z")

</div>

TARGET\_FILE\_DIR seems to be using the default target name regardless of what MACOSX\_BUNDLE\_BUNDLE\_NAME is set to. Setting OUTPUT\_NAME in addition to MACOSX\_BUNDLE\_BUNDLE\_NAME is a workaround, but seems redundant, or am I…

---

## [CMake Error: include could not find requested file: WebKitCommon](https://discourse.cmake.org/t/cmake-error-include-could-not-find-requested-file-webkitcommon/9645)

<div class="topic-metadata">

**Author:** [@Raphy](https://discourse.cmake.org/u/Raphy)\
**Replies:** 3\
**Last updated:** [December 19, 2023, 3:49am UTC](https://discourse.cmake.org/t/cmake-error-include-could-not-find-requested-file-webkitcommon/9645 "2023-12-19T03:49:33Z")

</div>

I compiled and installed in Ubuntu 22.04 WebKitGTK : BuildingGtk – WebKit Now I would like to do the same with find\_package and FetchContent in another CmakeLists.txt in order to download it and build it locally: cmake…

---

## [Changes not detected correctly for a ninja build](https://discourse.cmake.org/t/changes-not-detected-correctly-for-a-ninja-build/9639)

<div class="topic-metadata">

**Author:** [@DavidRegan](https://discourse.cmake.org/u/DavidRegan)\
**Replies:** 1\
**Last updated:** [December 19, 2023, 3:41am UTC](https://discourse.cmake.org/t/changes-not-detected-correctly-for-a-ninja-build/9639 "2023-12-19T03:41:03Z")

</div>

Using Windows; mingw64 and Git for Windows I found this repo about creating a version file. If I generate it for Ninja and modify the tags; the configured file is modified but the build stops at that step. If I build a…

---

## [Cmake tensorflow and protofbuf CPP](https://discourse.cmake.org/t/cmake-tensorflow-and-protofbuf-cpp/8569)

<div class="topic-metadata">

**Author:** [@Anhken](https://discourse.cmake.org/u/Anhken)\
**Replies:** 7\
**Last updated:** [December 14, 2023, 10:21am UTC](https://discourse.cmake.org/t/cmake-tensorflow-and-protofbuf-cpp/8569 "2023-12-14T10:21:26Z")

</div>

Hello everybody, I am a newbie trying to use Tensorflow\_cc to predict data from model “.pd” in ML. My example2.cpp is quite simple #include \<tensorflow/core/platform/env.h\> #include \<tensorflow/core/public/session.h\> …

---

## [arm gcc newlib retargetable locking fails because of command line order](https://discourse.cmake.org/t/arm-gcc-newlib-retargetable-locking-fails-because-of-command-line-order/9622)

<div class="topic-metadata">

**Author:** [@DavidRegan](https://discourse.cmake.org/u/DavidRegan)\
**Replies:** 2\
**Last updated:** [December 13, 2023, 10:14pm UTC](https://discourse.cmake.org/t/arm-gcc-newlib-retargetable-locking-fails-because-of-command-line-order/9622 "2023-12-13T22:14:08Z")

</div>

Link step fails with multiple definition error because cmake has created a link command of the form \<CMAKE\_C\_COMPILER\> $FLAGS $LINK\_FLAGS @RSP\_FILE -o $TARGET\_FILE. The $LINK\_FLAGS contain -lc -lm. The problem is that …

---

## [CMake not finding Accelerate framework](https://discourse.cmake.org/t/cmake-not-finding-accelerate-framework/8468)

<div class="topic-metadata">

**Author:** [@samuelpmish](https://discourse.cmake.org/u/samuelpmish)\
**Replies:** 4\
**Last updated:** [December 12, 2023, 8:35pm UTC](https://discourse.cmake.org/t/cmake-not-finding-accelerate-framework/8468 "2023-12-12T20:35:06Z")

</div>

Hi, In a project of mine, some of my dependencies apparently use the Accelerate framework. When linking against them, I get link lines that look like (I’m not sure why the -framework Accelerate is duplicated, but dedupl…

---

## [Add custom font to Xcode (for LaunchScreen)](https://discourse.cmake.org/t/add-custom-font-to-xcode-for-launchscreen/7737)

<div class="topic-metadata">

**Author:** [@paul.masristone](https://discourse.cmake.org/u/paul.masristone)\
**Replies:** 2\
**Last updated:** [December 12, 2023, 8:24pm UTC](https://discourse.cmake.org/t/add-custom-font-to-xcode-for-launchscreen/7737 "2023-12-12T20:24:44Z")

</div>

My app uses a custom font. I want to use this font in the LaunchScreen storyboard too. Anyone know how to do this? I’ve got this far… I created a LaunchScreen storyboard in Xcode, using my custom font, and stored the …

---

## [FindIconv doesn't seem to behave correctly](https://discourse.cmake.org/t/findiconv-doesnt-seem-to-behave-correctly/9606)

<div class="topic-metadata">

**Author:** [@dundargoc](https://discourse.cmake.org/u/dundargoc)\
**Replies:** 6\
**Last updated:** [December 12, 2023, 11:54am UTC](https://discourse.cmake.org/t/findiconv-doesnt-seem-to-behave-correctly/9606 "2023-12-12T11:54:43Z")

</div>

Our project has our own FindIconv.cmake file as we’re using minimum version 3.10. I’m trying to upgrade to version 3.13 and in the process replace the FindIconv.cmake with the builtin FindIconv module. Our FindIconv.cmak…

---

## [Including dynamically generated cmake files](https://discourse.cmake.org/t/including-dynamically-generated-cmake-files/9577)

<div class="topic-metadata">

**Author:** [@GlennCoombs](https://discourse.cmake.org/u/GlennCoombs)\
**Replies:** 5\
**Last updated:** [December 12, 2023, 4:01am UTC](https://discourse.cmake.org/t/including-dynamically-generated-cmake-files/9577 "2023-12-12T04:01:18Z")

</div>

I would like to have my CMakeLists.txt file include a file which is dynamically generated at build time. I can see that the include command can specify the OPTIONAL parameter so that it doesn’t fail on the initial confi…

---

## [BASE\_DIRS in \`target\_sources()\`](https://discourse.cmake.org/t/base-dirs-in-target-sources/9591)

<div class="topic-metadata">

**Author:** [@Kelarov](https://discourse.cmake.org/u/Kelarov)\
**Replies:** 2\
**Last updated:** [December 11, 2023, 5:03pm UTC](https://discourse.cmake.org/t/base-dirs-in-target-sources/9591 "2023-12-11T17:03:07Z")

</div>

Hi all. What would be the correct approach for: Say I have a ./src/utils/utils.ixx, and, in that file, I want to include: ./extern/include/generator.hpp and two windows headers, namely: $ENV{WindowsSdkDir}/Include/$…

---

## [Ninja and ExternalProject\_Add](https://discourse.cmake.org/t/ninja-and-externalproject-add/9590)

<div class="topic-metadata">

**Author:** [@boxerab](https://discourse.cmake.org/u/boxerab)\
**Replies:** 1\
**Last updated:** [December 11, 2023, 3:47pm UTC](https://discourse.cmake.org/t/ninja-and-externalproject-add/9590 "2023-12-11T15:47:16Z")

</div>

Hello! In my project grok, I add libjpeg-turbo dependency via ExternalProject\_Add. Here are the relevant lines: ExternalProject\_Add(libjpeg-turbo CMAKE\_ARGS -DENABLE\_SHA…

---

## [Specifying system-specific environment variables](https://discourse.cmake.org/t/specifying-system-specific-environment-variables/9546)

<div class="topic-metadata">

**Author:** [@Ciobi](https://discourse.cmake.org/u/Ciobi)\
**Replies:** 5\
**Last updated:** [December 11, 2023, 1:29pm UTC](https://discourse.cmake.org/t/specifying-system-specific-environment-variables/9546 "2023-12-11T13:29:37Z")

</div>

Hi, This looks like a very basic question, but I was unable to find a good solution searching this site and others, or asking ChatGPT or Bard. So … I have a QMake-based project for Linux and Windows that I’m trying to …

---

## [A bug with auto moc and object libraries that has been fixed. Or not?](https://discourse.cmake.org/t/a-bug-with-auto-moc-and-object-libraries-that-has-been-fixed-or-not/4582)

<div class="topic-metadata">

**Author:** [@ImplOfAnImpl](https://discourse.cmake.org/u/ImplOfAnImpl)\
**Replies:** 3\
**Last updated:** [December 10, 2023, 10:14pm UTC](https://discourse.cmake.org/t/a-bug-with-auto-moc-and-object-libraries-that-has-been-fixed-or-not/4582 "2023-12-10T22:14:15Z")

</div>

Hi everyone. In the project that I’m working on we’re trying to introduce a trick to improve build parallelization - whenever a library or an application target is about to be created, we instead create an object librar…

---

## [X11 and OpenGL builds on MacOS](https://discourse.cmake.org/t/x11-and-opengl-builds-on-macos/9466)

<div class="topic-metadata">

**Author:** [@rmfritz](https://discourse.cmake.org/u/rmfritz)\
**Replies:** 15\
**Last updated:** [December 10, 2023, 1:59am UTC](https://discourse.cmake.org/t/x11-and-opengl-builds-on-macos/9466 "2023-12-10T01:59:04Z")

</div>

Ok…I’m working with an old software package that still uses X11, and OpenGL via X11 on MacOS. X11 and openGL are deprecated anyway, but meantime we’d like to keep the software going. First problem: FindX11 consistently …

---

## [CMake, Ninja, Fortran, and inconsistent \`Cannot open module file\` errors](https://discourse.cmake.org/t/cmake-ninja-fortran-and-inconsistent-cannot-open-module-file-errors/9276)

<div class="topic-metadata">

**Author:** [@golmschenk](https://discourse.cmake.org/u/golmschenk)\
**Replies:** 10\
**Last updated:** [December 9, 2023, 10:47pm UTC](https://discourse.cmake.org/t/cmake-ninja-fortran-and-inconsistent-cannot-open-module-file-errors/9276 "2023-12-09T22:47:37Z")

</div>

Hello! I’m running into an issue where, for some system configurations, I encounter a Cannot open module file (for a Fortran module file) during the build. From what I can tell, this is occurring because the way I’ve set…

---

## [Help me in creating .d and .o for list of c files in cmake](https://discourse.cmake.org/t/help-me-in-creating-d-and-o-for-list-of-c-files-in-cmake/9562)

<div class="topic-metadata">

**Author:** [@deeptii1410](https://discourse.cmake.org/u/deeptii1410)\
**Replies:** 1\
**Last updated:** [December 6, 2023, 12:58pm UTC](https://discourse.cmake.org/t/help-me-in-creating-d-and-o-for-list-of-c-files-in-cmake/9562 "2023-12-06T12:58:30Z")

</div>

I try to create .d and .o files from c files using minGW makefiles. I have list of header files in different folder path. Confused whether to use include\_directories / target\_include\_directories

---

## [Do I still need FindCUDA ?](https://discourse.cmake.org/t/do-i-still-need-findcuda/1705)

<div class="topic-metadata">

**Author:** [@Psykoangel](https://discourse.cmake.org/u/Psykoangel)\
**Replies:** 5\
**Last updated:** [December 5, 2023, 6:43am UTC](https://discourse.cmake.org/t/do-i-still-need-findcuda/1705 "2023-12-05T06:43:09Z")

</div>

Hello CMake Community ! I just had the opportunity to update one of our Ubuntu 20.04 host at work with the last stable CMake snap (actually version 3.18.1) and have been surprised with an error during the build of our p…

---

## [Namespace concept for CMakeLists.txt](https://discourse.cmake.org/t/namespace-concept-for-cmakelists-txt/9491)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 5\
**Last updated:** [November 30, 2023, 2:57am UTC](https://discourse.cmake.org/t/namespace-concept-for-cmakelists-txt/9491 "2023-11-30T02:57:22Z")

</div>

Hello, I am trying to understand some CMakeLists.txt made in the company where I work, and there are some calls to non-standard functions. They’re actually defined somewhere, in a Git submodule, trough very indirect way…

---

## [How to try\_run MPI code](https://discourse.cmake.org/t/how-to-try-run-mpi-code/9516)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 3\
**Last updated:** [November 29, 2023, 12:36pm UTC](https://discourse.cmake.org/t/how-to-try-run-mpi-code/9516 "2023-11-29T12:36:17Z")

</div>

All, I recently found that Open MPI 5.0.0 has an issue with Intel Fortran and -init=snan (at least for us, see Crash on MPI\_Init with Open MPI 5.0.0, Intel Fortran, and -init=snan · Issue #12113 · open-mpi/ompi · GitHub)…

---

## [Link between "cmake -B" and CMAKE\_CURRENT\_BINARY\_DIR](https://discourse.cmake.org/t/link-between-cmake-b-and-cmake-current-binary-dir/9520)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 3\
**Last updated:** [November 29, 2023, 11:49am UTC](https://discourse.cmake.org/t/link-between-cmake-b-and-cmake-current-binary-dir/9520 "2023-11-29T11:49:48Z")

</div>

Hello, Could you please confirm me that CMAKE\_CURRENT\_BINARY\_DIR is set by cmake -B ? If so, it would be good the documentation mentions explicitly this link (documentation of one of them referring the other one).

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

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