# Code

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

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

**Page:** 32

---

## [Set environment variables for all CMake Presets](https://discourse.cmake.org/t/set-environment-variables-for-all-cmake-presets/7116)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 1\
**Last updated:** [August 15, 2023, 1:57pm UTC](https://discourse.cmake.org/t/set-environment-variables-for-all-cmake-presets/7116 "2023-08-15T13:57:28Z")

</div>

Hi, is it somehow possible to define environment variables for all existing preset. The use case I’m thinking off is the following. Say I have a project with CMakePresets with a lot of presents for different compilers,…

---

## [How to prevent CMake usage of an outdated fortran module](https://discourse.cmake.org/t/how-to-prevent-cmake-usage-of-an-outdated-fortran-module/8710)

<div class="topic-metadata">

**Author:** [@uranix](https://discourse.cmake.org/u/uranix)\
**Replies:** 6\
**Last updated:** [August 10, 2023, 6:18pm UTC](https://discourse.cmake.org/t/how-to-prevent-cmake-usage-of-an-outdated-fortran-module/8710 "2023-08-10T18:18:01Z")

</div>

I’m using CMake to build a moderate-sized Fortran project. I noticed that sometimes when I refactor modules I ran into weird compilation errors that are gone after clean rebuild in a fresh build directory. I’ve managed …

---

## [Platform/Generator specific properties in a condition](https://discourse.cmake.org/t/platform-generator-specific-properties-in-a-condition/8713)

<div class="topic-metadata">

**Author:** [@rehans](https://discourse.cmake.org/u/rehans)\
**Replies:** 1\
**Last updated:** [August 10, 2023, 12:42pm UTC](https://discourse.cmake.org/t/platform-generator-specific-properties-in-a-condition/8713 "2023-08-10T12:42:21Z")

</div>

Often I see cmake code like this: if(APPLE) set(CMAKE\_XCODE\_GENERATE\_SCHEME TRUE) else() set\_property(DIRECTORY ${CMAKE\_CURRENT\_SOURCE\_DIR} PROPERTY VS\_STARTUP\_PROJECTlab) endif() Is it really necessary to do t…

---

## [Hot to make add\_subdirectory() prevent install but still build as part of ALL](https://discourse.cmake.org/t/hot-to-make-add-subdirectory-prevent-install-but-still-build-as-part-of-all/8698)

<div class="topic-metadata">

**Author:** [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Replies:** 3\
**Last updated:** [August 9, 2023, 11:28am UTC](https://discourse.cmake.org/t/hot-to-make-add-subdirectory-prevent-install-but-still-build-as-part-of-all/8698 "2023-08-09T11:28:51Z")

</div>

The “common wisdom” to prevent add\_subdirectory() from running install() rules from inside it is to use add\_subdirectory(dir EXCLUDE\_FROM\_ALL). This works fine, except it also removes all targets from building as part of…

---

## [how to exclude the compile definitions inherited from the linked library](https://discourse.cmake.org/t/how-to-exclude-the-compile-definitions-inherited-from-the-linked-library/8694)

<div class="topic-metadata">

**Author:** [@Malaz99](https://discourse.cmake.org/u/Malaz99)\
**Replies:** 1\
**Last updated:** [August 8, 2023, 1:37pm UTC](https://discourse.cmake.org/t/how-to-exclude-the-compile-definitions-inherited-from-the-linked-library/8694 "2023-08-08T13:37:59Z")

</div>

The find\_package command automatically sets up the necessary preprocessor definitions, and also sets up other configurations for its linked target. I want a way to exclude some compile definitions inherited from the lin…

---

## [Dynamically Changing Targets: A Complex building system generating CMakeLists build files and build types dynamically](https://discourse.cmake.org/t/dynamically-changing-targets-a-complex-building-system-generating-cmakelists-build-files-and-build-types-dynamically/8487)

<div class="topic-metadata">

**Author:** [@thrudprimrose](https://discourse.cmake.org/u/thrudprimrose)\
**Replies:** 1\
**Last updated:** [August 7, 2023, 10:26pm UTC](https://discourse.cmake.org/t/dynamically-changing-targets-a-complex-building-system-generating-cmakelists-build-files-and-build-types-dynamically/8487 "2023-08-07T22:26:09Z")

</div>

I will describe my issue and then provide the code in a public github repository. Even though there is not much code, the structure etc. are also important, and I believe it was the best to do it this way. I am working …

---

## [Get SOURCES of Target](https://discourse.cmake.org/t/get-sources-of-target/4216)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 6\
**Last updated:** [August 7, 2023, 2:51pm UTC](https://discourse.cmake.org/t/get-sources-of-target/4216 "2023-08-07T14:51:17Z")

</div>

Hi, for a function (see Static analyzers as seperate targets) I need all absolute path from source files of a target. This raises a couple of questions: How do I get all sources of a target? → SOURCES Property is poss…

---

## [FetchContent base directory and CMakePresets](https://discourse.cmake.org/t/fetchcontent-base-directory-and-cmakepresets/6722)

<div class="topic-metadata">

**Author:** [@yah-nosh](https://discourse.cmake.org/u/yah-nosh)\
**Replies:** 13\
**Last updated:** [August 6, 2023, 4:08pm UTC](https://discourse.cmake.org/t/fetchcontent-base-directory-and-cmakepresets/6722 "2023-08-06T16:08:03Z")

</div>

I’m using FetchContent to manage third-party dependencies, and I ran into an issue when trying to deduplicate the sub-builds generated for different build configurations. Below is a minimal working example that replicate…

---

## [Header file of package not found.](https://discourse.cmake.org/t/header-file-of-package-not-found/8680)

<div class="topic-metadata">

**Author:** [@LucasMSpereira](https://discourse.cmake.org/u/LucasMSpereira)\
**Replies:** 2\
**Last updated:** [August 5, 2023, 12:10pm UTC](https://discourse.cmake.org/t/header-file-of-package-not-found/8680 "2023-08-05T12:10:03Z")

</div>

On windows 10 (MSVC build toolset without Visual Studio), I’m trying to build my C++ project, which uses one package (for plotting): Matplot++. I cloned it’s repo in my project’s folder. In my project’s main.cpp, I’m ab…

---

## [How to make changes to scripts and patch files used in PATCH\_COMMAND rebuild ExternalProject?](https://discourse.cmake.org/t/how-to-make-changes-to-scripts-and-patch-files-used-in-patch-command-rebuild-externalproject/8666)

<div class="topic-metadata">

**Author:** [@balshetzer](https://discourse.cmake.org/u/balshetzer)\
**Replies:** 4\
**Last updated:** [August 3, 2023, 2:12pm UTC](https://discourse.cmake.org/t/how-to-make-changes-to-scripts-and-patch-files-used-in-patch-command-rebuild-externalproject/8666 "2023-08-03T14:12:00Z")

</div>

I have an ExternalProject\_Add with a PATCH\_COMMAND bash patch\_script.sh that applies various patch files. How can I get the project to be updated when I modify the script or patch files?

---

## [ExternalProject: avoid triggering Git "clean" filter with UPDATE\_COMMAND](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 3\
**Last updated:** [August 3, 2023, 1:49am UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662 "2023-08-03T01:49:12Z")

</div>

Summary: I want to make the ExternalProject “update” step a simple Git command, so that my user-wide Git filter “clean” is not triggered. The default ExternalProject “update” step triggers Git filter “clean”, which in my…

---

## [Copy additional/prebuilt files next to every executable depending on a library target?](https://discourse.cmake.org/t/copy-additional-prebuilt-files-next-to-every-executable-depending-on-a-library-target/8575)

<div class="topic-metadata">

**Author:** [@tbone](https://discourse.cmake.org/u/tbone)\
**Replies:** 5\
**Last updated:** [July 29, 2023, 9:26pm UTC](https://discourse.cmake.org/t/copy-additional-prebuilt-files-next-to-every-executable-depending-on-a-library-target/8575 "2023-07-29T21:26:10Z")

</div>

So I know there’s a couple of questions that sound similar to this topic, but I’ve yet to actually find a good/working solution to this. My project has the following dependency chain: application → core tech → external …

---

## [Detecting scope of added sources](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634)

<div class="topic-metadata">

**Author:** [@mbee](https://discourse.cmake.org/u/mbee)\
**Replies:** 2\
**Last updated:** [July 29, 2023, 9:00pm UTC](https://discourse.cmake.org/t/detecting-scope-of-added-sources/8634 "2023-07-29T21:00:35Z")

</div>

I have the following lines of code: add\_executable( MyExecutable) add\_library(Lib EXCLUDE\_FROM\_ALL) # … much later, conditionally, in deeply nested code and at multiple locations target\_sources(Lib PRIVATE some.cpp) …

---

## [How to get the install destination of files of an imported target?](https://discourse.cmake.org/t/how-to-get-the-install-destination-of-files-of-an-imported-target/8618)

<div class="topic-metadata">

**Author:** [@Wittenborn](https://discourse.cmake.org/u/Wittenborn)\
**Replies:** 2\
**Last updated:** [July 28, 2023, 7:05am UTC](https://discourse.cmake.org/t/how-to-get-the-install-destination-of-files-of-an-imported-target/8618 "2023-07-28T07:05:41Z")

</div>

Let’s assume there is a project A with the following CMakeLists.txt: cmake\_minimum\_required(VERSION 3.27) project(A VERSION 1.0.0 LANGUAGES CXX) set(library\_name ProjectA) add\_library(${library\_name} INTERFACE) add\_li…

---

## [Adding actions to rules in generated Makefile](https://discourse.cmake.org/t/adding-actions-to-rules-in-generated-makefile/8608)

<div class="topic-metadata">

**Author:** [@peterlu](https://discourse.cmake.org/u/peterlu)\
**Replies:** 3\
**Last updated:** [July 27, 2023, 2:52am UTC](https://discourse.cmake.org/t/adding-actions-to-rules-in-generated-makefile/8608 "2023-07-27T02:52:27Z")

</div>

I’d like to know how to modify CMakeLists.rtxt to cause the following to happen in the generated Makefile, to create a dummy file to be used as a flag… all: rm -f build.ok # add thi…

---

## [CMake fails due to missing protobuf-config.cmake while compiling project using Emscripten](https://discourse.cmake.org/t/cmake-fails-due-to-missing-protobuf-config-cmake-while-compiling-project-using-emscripten/8602)

<div class="topic-metadata">

**Author:** [@GTP](https://discourse.cmake.org/u/GTP)\
**Replies:** 1\
**Last updated:** [July 26, 2023, 8:22am UTC](https://discourse.cmake.org/t/cmake-fails-due-to-missing-protobuf-config-cmake-while-compiling-project-using-emscripten/8602 "2023-07-26T08:22:26Z")

</div>

Greetings, I’m trying to compile to WASM a C++ project that has protobuf as a dependency. To this aim, I downloaded the precompiled library from the protobuf-wasm repo’s releases and modified the project’s CMake configu…

---

## [Avoid tests from subprojects being added to my project's list of tests](https://discourse.cmake.org/t/avoid-tests-from-subprojects-being-added-to-my-projects-list-of-tests/8583)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 3\
**Last updated:** [July 24, 2023, 4:47pm UTC](https://discourse.cmake.org/t/avoid-tests-from-subprojects-being-added-to-my-projects-list-of-tests/8583 "2023-07-24T16:47:54Z")

</div>

I have a project where I include Eigen like this: find\_package(Eigen3 CONFIG) if(NOT Eigen3\_FOUND) message(STATUS "Fetching Eigen3") FetchContent\_Declare(Eigen3 GIT\_REPOSITORY https://gitlab.com/libeigen…

---

## [Setting properties for Qt autogen target](https://discourse.cmake.org/t/setting-properties-for-qt-autogen-target/8573)

<div class="topic-metadata">

**Author:** [@brentd](https://discourse.cmake.org/u/brentd)\
**Replies:** 6\
**Last updated:** [July 23, 2023, 10:11pm UTC](https://discourse.cmake.org/t/setting-properties-for-qt-autogen-target/8573 "2023-07-23T22:11:43Z")

</div>

I have a library using Qt and I am using cppcheck. I do not want to run cppcheck on the resulting ‘autogen’ target, but you can’t set the target properties on the autogen target to disable cppcheck because the target is…

---

## [Problems with Step2 of the CMake Tutorial](https://discourse.cmake.org/t/problems-with-step2-of-the-cmake-tutorial/7860)

<div class="topic-metadata">

**Author:** [@Azmuth](https://discourse.cmake.org/u/Azmuth)\
**Replies:** 3\
**Last updated:** [July 23, 2023, 2:41pm UTC](https://discourse.cmake.org/t/problems-with-step2-of-the-cmake-tutorial/7860 "2023-07-23T14:41:37Z")

</div>

I am doing the Step 2 of CMake tutorial (https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Library.html). After I have finished all the steps I have a problem when trying to build my code. The error is: “…

---

## [Cmake adds support for the SylixOS platform](https://discourse.cmake.org/t/cmake-adds-support-for-the-sylixos-platform/8558)

<div class="topic-metadata">

**Author:** [@li57400543](https://discourse.cmake.org/u/li57400543)\
**Replies:** 4\
**Last updated:** [July 21, 2023, 1:43pm UTC](https://discourse.cmake.org/t/cmake-adds-support-for-the-sylixos-platform/8558 "2023-07-21T13:43:52Z")

</div>

Hello, I am a developer from the SylixOS team. When using cmake for cross compilation of SylixOS application software, I found that cmake currently does not support the SylixOS platform. Can I add support? I have made mo…

---

## [How to name package based on target architecture on macOS?](https://discourse.cmake.org/t/how-to-name-package-based-on-target-architecture-on-macos/8560)

<div class="topic-metadata">

**Author:** [@jpfeuffer](https://discourse.cmake.org/u/jpfeuffer)\
**Replies:** 4\
**Last updated:** [July 21, 2023, 12:00pm UTC](https://discourse.cmake.org/t/how-to-name-package-based-on-target-architecture-on-macos/8560 "2023-07-21T12:00:40Z")

</div>

Hi! I want to name my macOS package according to the target architecture(s) that CMake is going to build. How do I do that? Which variables do I need to query? E.g. CMAKE\_OSX\_ARCHITECTURES might not necessarily be set,…

---

## [GTest broken by CMake 3.27, I think](https://discourse.cmake.org/t/gtest-broken-by-cmake-3-27-i-think/8563)

<div class="topic-metadata">

**Author:** [@jwrwseu](https://discourse.cmake.org/u/jwrwseu)\
**Replies:** 1\
**Last updated:** [July 20, 2023, 4:35pm UTC](https://discourse.cmake.org/t/gtest-broken-by-cmake-3-27-i-think/8563 "2023-07-20T16:35:16Z")

</div>

I have been using the GTest instructions to use CMake to get it and build it for the past couple of years: include(FetchContent) FetchContent\_Declare( googletest DOWNLOAD\_EXTRACT\_TIMESTAMP URL …

---

## [Generate two binaries that share CMakeFile but different linker script](https://discourse.cmake.org/t/generate-two-binaries-that-share-cmakefile-but-different-linker-script/8531)

<div class="topic-metadata">

**Author:** [@symon97x](https://discourse.cmake.org/u/symon97x)\
**Replies:** 3\
**Last updated:** [July 19, 2023, 8:32pm UTC](https://discourse.cmake.org/t/generate-two-binaries-that-share-cmakefile-but-different-linker-script/8531 "2023-07-19T20:32:45Z")

</div>

In my embedded project I have a use case in which the CMakelist.txt needs to generate two “quasi identical” binaries that share the same build process, same sources, headers and dependencies, but different linker scripts…

---

## ["TutorialConfig.h: No such file or directory"](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535)

<div class="topic-metadata">

**Author:** [@jaafar-omar](https://discourse.cmake.org/u/jaafar-omar)\
**Replies:** 4\
**Last updated:** [July 18, 2023, 8:53am UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535 "2023-07-18T08:53:45Z")

</div>

I’m currently doing the Cmake tutorial and I’m stuck at Step1 Exercise 3 but I think I have configured the CMakeLists.txt correctly and do the “cmake …build .”. The “TutorialConfig.h” file is inside the Step1\_build direc…

---

## [How to handle multiarch headers?](https://discourse.cmake.org/t/how-to-handle-multiarch-headers/8529)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 1\
**Last updated:** [July 18, 2023, 12:48am UTC](https://discourse.cmake.org/t/how-to-handle-multiarch-headers/8529 "2023-07-18T00:48:36Z")

</div>

GNUInstallDirs can automatically set up CMAKE\_INSTALL\_LIBDIR to point to an architecture-specific directory, e.g. /usr/lib/x86\_64-linux-gnu. It does this based on CMAKE\_LIBRARY\_ARCHITECTURE as well as other factors. In …

---

## [Create symlink to a install result](https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502)

<div class="topic-metadata">

**Author:** [@WeissZucker](https://discourse.cmake.org/u/WeissZucker)\
**Replies:** 1\
**Last updated:** [July 18, 2023, 12:00am UTC](https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502 "2023-07-18T00:00:45Z")

</div>

. ├── build │ └── lib │ └── foo.so └── package ├── fixed │ └── dir │ └── structure │ └── bar.so └── lib └── foo.so I don’t have much experience on writing CMakeLists. I have a project…

---

## [Third party package problem](https://discourse.cmake.org/t/third-party-package-problem/8516)

<div class="topic-metadata">

**Author:** [@Richter\_Tobias](https://discourse.cmake.org/u/Richter_Tobias)\
**Replies:** 1\
**Last updated:** [July 14, 2023, 12:07pm UTC](https://discourse.cmake.org/t/third-party-package-problem/8516 "2023-07-14T12:07:43Z")

</div>

Hi, I try to build a project that depends on a third party sdk, which is available as conan package. However, this package only contains a build for CMAKE\_BUILD\_TYPE “Release”. If I build the project with the CMAKE\_BUIL…

---

## [CMake directory hierarchy question](https://discourse.cmake.org/t/cmake-directory-hierarchy-question/8477)

<div class="topic-metadata">

**Author:** [@marker5a](https://discourse.cmake.org/u/marker5a)\
**Replies:** 1\
**Last updated:** [July 11, 2023, 6:18pm UTC](https://discourse.cmake.org/t/cmake-directory-hierarchy-question/8477 "2023-07-11T18:18:26Z")

</div>

I have a project for an embedded target that contains source code for a bootloader and source code for two sets of user code for two different microcontrollers, call them mcu\_A and mcu\_B. The folder structure is as foll…

---

## [Path declared in INTERFACE\_INCLUDE\_DIRECTORIES imported target seemingly not found](https://discourse.cmake.org/t/path-declared-in-interface-include-directories-imported-target-seemingly-not-found/8475)

<div class="topic-metadata">

**Author:** [@jviotti](https://discourse.cmake.org/u/jviotti)\
**Replies:** 4\
**Last updated:** [July 10, 2023, 9:34pm UTC](https://discourse.cmake.org/t/path-declared-in-interface-include-directories-imported-target-seemingly-not-found/8475 "2023-07-10T21:34:30Z")

</div>

I’m working on a C++ project that exports a bunch of libraries and tries to make use of CMakePackageConfigHelpers to be findable using find\_package. After installation, projects attempting to make use of it, like: cmake…

---

## [Undefined Reference - C GCC](https://discourse.cmake.org/t/undefined-reference-c-gcc/8481)

<div class="topic-metadata">

**Author:** [@Akash\_01](https://discourse.cmake.org/u/Akash_01)\
**Replies:** 1\
**Last updated:** [July 10, 2023, 9:43am UTC](https://discourse.cmake.org/t/undefined-reference-c-gcc/8481 "2023-07-10T09:43:43Z")

</div>

Hai, I was facing Undefined reference when doing the compilation. I could see no error during the project file compilation in linking stage the error occurred as undefined reference cmd.exe /C "cd . && C:\\Programfiles\\…

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

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