# Code

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

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

**Page:** 33

---

## [\`add\_custom\_command\` with target properties at build time](https://discourse.cmake.org/t/add-custom-command-with-target-properties-at-build-time/8464)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 3\
**Last updated:** [July 10, 2023, 12:01am UTC](https://discourse.cmake.org/t/add-custom-command-with-target-properties-at-build-time/8464 "2023-07-10T00:01:09Z")

</div>

I am trying to design an interface for fypp that mimics add\_library, target\_sources and add\_executable. The issue I am currently stuck on is how can I get the target properties, e.g. COMPILE\_DEFINITIONS that would be run…

---

## [Automatically generating intermediate files by intervening compilation process.](https://discourse.cmake.org/t/automatically-generating-intermediate-files-by-intervening-compilation-process/8458)

<div class="topic-metadata">

**Author:** [@insight](https://discourse.cmake.org/u/insight)\
**Replies:** 1\
**Last updated:** [July 4, 2023, 10:03pm UTC](https://discourse.cmake.org/t/automatically-generating-intermediate-files-by-intervening-compilation-process/8458 "2023-07-04T22:03:03Z")

</div>

Hello folks, This is with respect to one of my previous questions (custom command not getting executed while building.) where I have manually changed files to generate intermediate llvm code for analysis and it seems to…

---

## [custom command not getting executed while building.](https://discourse.cmake.org/t/custom-command-not-getting-executed-while-building/8190)

<div class="topic-metadata">

**Author:** [@insight](https://discourse.cmake.org/u/insight)\
**Replies:** 3\
**Last updated:** [July 4, 2023, 9:16pm UTC](https://discourse.cmake.org/t/custom-command-not-getting-executed-while-building/8190 "2023-07-04T21:16:43Z")

</div>

Hello all, I got provided with many CMakeLists files which on building generate a final executable. I am trying to write a custom command which on building should spit out .ll files from the C files, so I can be using t…

---

## [InstallRequiredSystemLibraries fails to detect clang on Windows](https://discourse.cmake.org/t/installrequiredsystemlibraries-fails-to-detect-clang-on-windows/8447)

<div class="topic-metadata">

**Author:** [@andreasxp](https://discourse.cmake.org/u/andreasxp)\
**Replies:** 0\
**Last updated:** [July 2, 2023, 2:21pm UTC](https://discourse.cmake.org/t/installrequiredsystemlibraries-fails-to-detect-clang-on-windows/8447 "2023-07-02T14:21:36Z")

</div>

Clang on Windows (not clang on MinGW) uses the same MSVC libraries as MSVC itself. However, when I included InstallRequiredSystemLibraries, the necessary msvc DLLs were not properly installed. Looking into InstallRequir…

---

## [Handling gcc/g++ '--param' flag](https://discourse.cmake.org/t/handling-gcc-g-param-flag/8408)

<div class="topic-metadata">

**Author:** [@ct\_clmsn](https://discourse.cmake.org/u/ct_clmsn)\
**Replies:** 4\
**Last updated:** [July 1, 2023, 9:49pm UTC](https://discourse.cmake.org/t/handling-gcc-g-param-flag/8408 "2023-07-01T21:49:48Z")

</div>

A project I’m currently working on requires a dependency that has pkg-config support. Cmake currently does everything right with one exception, several of the cxx-flags have a ‘–param’ prefix to indicate specific constr…

---

## [Good way of running custom commands serially](https://discourse.cmake.org/t/good-way-of-running-custom-commands-serially/8412)

<div class="topic-metadata">

**Author:** [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)\
**Replies:** 7\
**Last updated:** [July 1, 2023, 9:48pm UTC](https://discourse.cmake.org/t/good-way-of-running-custom-commands-serially/8412 "2023-07-01T21:48:45Z")

</div>

TL;DR: I add\_custom\_commands that call git clang-format. They are called as part of target (e.g. library) build. The commands don’t create/modify any files but can’t run concurrently. How to enforce only one to run at a …

---

## [How to INSERT/PREPEND an element into a JSON array using string(JSON)?](https://discourse.cmake.org/t/how-to-insert-prepend-an-element-into-a-json-array-using-string-json/8410)

<div class="topic-metadata">

**Author:** [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Replies:** 3\
**Last updated:** [July 1, 2023, 8:53pm UTC](https://discourse.cmake.org/t/how-to-insert-prepend-an-element-into-a-json-array-using-string-json/8410 "2023-07-01T20:53:55Z")

</div>

Suppose that there is a JSON file (called array.json) with the following structure: { "array": \[ { "name" : "element1", "property" : "value1" }, { "name" : "element2", "property" …

---

## [ld: cannot find library (CMake found it earlier?)](https://discourse.cmake.org/t/ld-cannot-find-library-cmake-found-it-earlier/8378)

<div class="topic-metadata">

**Author:** [@tbouvier](https://discourse.cmake.org/u/tbouvier)\
**Replies:** 5\
**Last updated:** [June 26, 2023, 6:36pm UTC](https://discourse.cmake.org/t/ld-cannot-find-library-cmake-found-it-earlier/8378 "2023-06-26T18:36:04Z")

</div>

Hello, I’m trying to compile a shared library I wrote, named neomem. However, when running the following cmake . && make, I get the following output: -- Found pybind11: /mnt/view/chifflot-v100/include (found version "2…

---

## [Inconsistent behavior of Ninja generator on first and subsequent cmake runs for CMAKE\_\<LANG\>\_STANDARD\_LIBRARIES](https://discourse.cmake.org/t/inconsistent-behavior-of-ninja-generator-on-first-and-subsequent-cmake-runs-for-cmake-lang-standard-libraries/8359)

<div class="topic-metadata">

**Author:** [@krolli](https://discourse.cmake.org/u/krolli)\
**Replies:** 5\
**Last updated:** [June 25, 2023, 7:44pm UTC](https://discourse.cmake.org/t/inconsistent-behavior-of-ninja-generator-on-first-and-subsequent-cmake-runs-for-cmake-lang-standard-libraries/8359 "2023-06-25T19:44:58Z")

</div>

Hi, we are writing a custom MSVC toolchain (specifically for Visual Studio 2017) and while doing so, we’ve run into a problem where generated build.ninja file is different on first cmake run compared to subsequent runs. …

---

## [CMAKE\_OSX\_DEPLOYMENT\_TARGET not setting min version? (Xcode, clang)](https://discourse.cmake.org/t/cmake-osx-deployment-target-not-setting-min-version-xcode-clang/8399)

<div class="topic-metadata">

**Author:** [@hsetlik](https://discourse.cmake.org/u/hsetlik)\
**Replies:** 1\
**Last updated:** [June 23, 2023, 9:58pm UTC](https://discourse.cmake.org/t/cmake-osx-deployment-target-not-setting-min-version-xcode-clang/8399 "2023-06-23T21:58:37Z")

</div>

Hi all, I have a GUI macOS app that gets built with CMake and the Xcode generator. The version and architectures are set up like this: set(CMAKE\_OSX\_DEPLOYMENT\_TARGET 10.13) set(CMAKE\_OSX\_ARCHITECTURES arm64 x86\_64) E…

---

## [How to create a dummy build preset](https://discourse.cmake.org/t/how-to-create-a-dummy-build-preset/8398)

<div class="topic-metadata">

**Author:** [@phread](https://discourse.cmake.org/u/phread)\
**Replies:** 1\
**Last updated:** [June 23, 2023, 8:19pm UTC](https://discourse.cmake.org/t/how-to-create-a-dummy-build-preset/8398 "2023-06-23T20:19:40Z")

</div>

I am generating a number of CMakePresets.json files. It would be convenient to be able to generate a no-op build preset. (Rather than discovering that it will not be needed and dealing with the fall-out). note: In the…

---

## [Generator expressions in external projects.](https://discourse.cmake.org/t/generator-expressions-in-external-projects/805)

<div class="topic-metadata">

**Author:** [@karliss](https://discourse.cmake.org/u/karliss)\
**Replies:** 5\
**Last updated:** [June 23, 2023, 5:38am UTC](https://discourse.cmake.org/t/generator-expressions-in-external-projects/805 "2023-06-23T05:38:19Z")

</div>

Most external project commands support generator expressions. INSTALL\_DIR isn’t used by CMake directly but instead used as placeholder in commands which support generator expressions. Documentation doesn’t mention and …

---

## [Xcode schemes: how to choose which build type is assigned to each task?](https://discourse.cmake.org/t/xcode-schemes-how-to-choose-which-build-type-is-assigned-to-each-task/8395)

<div class="topic-metadata">

**Author:** [@zzymyn](https://discourse.cmake.org/u/zzymyn)\
**Replies:** 0\
**Last updated:** [June 23, 2023, 12:43am UTC](https://discourse.cmake.org/t/xcode-schemes-how-to-choose-which-build-type-is-assigned-to-each-task/8395 "2023-06-23T00:43:53Z")

</div>

By default Cmake assigns the Debug build to the Run and Test actions and the Release build to the Profile and Archive actions. Is there a way to change it so it assigned RelWithDebInfo to the Archive action? I see there…

---

## [CPackRPM Installing Unnecessary Files](https://discourse.cmake.org/t/cpackrpm-installing-unnecessary-files/8249)

<div class="topic-metadata">

**Author:** [@krasznaa](https://discourse.cmake.org/u/krasznaa)\
**Replies:** 7\
**Last updated:** [June 20, 2023, 6:24pm UTC](https://discourse.cmake.org/t/cpackrpm-installing-unnecessary-files/8249 "2023-06-20T18:24:54Z")

</div>

Hi, I’ve been trying to understand the following issue for the last several hours, but now it’s time to call in the cavalry… :thinking: In the project that I’m working on at the moment (atlas / atlasexternals · GitLab)…

---

## [How to create stripped dll](https://discourse.cmake.org/t/how-to-create-stripped-dll/8347)

<div class="topic-metadata">

**Author:** [@Akash\_01](https://discourse.cmake.org/u/Akash_01)\
**Replies:** 4\
**Last updated:** [June 20, 2023, 2:22pm UTC](https://discourse.cmake.org/t/how-to-create-stripped-dll/8347 "2023-06-20T14:22:46Z")

</div>

Hi, I was trying to migrate my environment to CMAKE to use GCC compiler with VS. Previously I are using make script. Can any one support me on how to generate the below make command in the CMAKE script. In the below m…

---

## [Caching FetchContent source in a different directory](https://discourse.cmake.org/t/caching-fetchcontent-source-in-a-different-directory/8326)

<div class="topic-metadata">

**Author:** [@dwarwick](https://discourse.cmake.org/u/dwarwick)\
**Replies:** 2\
**Last updated:** [June 19, 2023, 3:01pm UTC](https://discourse.cmake.org/t/caching-fetchcontent-source-in-a-different-directory/8326 "2023-06-19T15:01:53Z")

</div>

We use FetchContent to fetch external dependencies for our project: FetchContent\_Declare(Library GIT\_REPOSITORY https://github.corpname.com/OrgName/library GIT\_TAG aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) FetchContent\_…

---

## [ExternalProject\_Add cache for git repositories](https://discourse.cmake.org/t/externalproject-add-cache-for-git-repositories/4218)

<div class="topic-metadata">

**Author:** [@codeling](https://discourse.cmake.org/u/codeling)\
**Replies:** 3\
**Last updated:** [June 19, 2023, 2:39pm UTC](https://discourse.cmake.org/t/externalproject-add-cache-for-git-repositories/4218 "2023-06-19T14:39:18Z")

</div>

Inspired by this other topic, I added DOWNLOAD\_DIR to our superbuild’s ExternalProject\_Add to avoid re-downloading external libraries’ archive files, which works nicely. The DOWNLOAD\_DIR however only works to provide ca…

---

## [Find \`omp-tools.h\` with FindOpenMP](https://discourse.cmake.org/t/find-omp-tools-h-with-findopenmp/8275)

<div class="topic-metadata">

**Author:** [@parzt](https://discourse.cmake.org/u/parzt)\
**Replies:** 4\
**Last updated:** [June 19, 2023, 9:17am UTC](https://discourse.cmake.org/t/find-omp-tools-h-with-findopenmp/8275 "2023-06-19T09:17:39Z")

</div>

I use the OpenMP tools interface for my project and therefore need to header omp-tools.h. Is there any way to find the include directory which this file using FindOpenMP? If not, would such a feature be possible and sens…

---

## [What is the procedure for accessing code in other subdirectories?](https://discourse.cmake.org/t/what-is-the-procedure-for-accessing-code-in-other-subdirectories/8328)

<div class="topic-metadata">

**Author:** [@texjunky](https://discourse.cmake.org/u/texjunky)\
**Replies:** 3\
**Last updated:** [June 18, 2023, 4:14pm UTC](https://discourse.cmake.org/t/what-is-the-procedure-for-accessing-code-in-other-subdirectories/8328 "2023-06-18T16:14:52Z")

</div>

System g++ on Linux Mint. Sample project My project has lots of files, but attention may be confined to the three below and their related CMakeLists.txt files: containers/Square.cpp equations/DEsolve.cpp branch/cli.cp…

---

## [IMPORTED\_LOCATION is incorrect for OpenSSL::SSL and OpenSSL::Crypto](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040)

<div class="topic-metadata">

**Author:** [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Replies:** 4\
**Last updated:** [June 18, 2023, 1:44pm UTC](https://discourse.cmake.org/t/imported-location-is-incorrect-for-openssl-ssl-and-openssl-crypto/8040 "2023-06-18T13:44:35Z")

</div>

Problem Description I installed OpenSSL using the binaries installer provided by ShiningLight.OpenSSL on Windows. And here is its install location: C:\\Program Files\\OpenSSL-Win64 However, I found that the imported targ…

---

## [Why is manual copying of .dll needed when linking library?](https://discourse.cmake.org/t/why-is-manual-copying-of-dll-needed-when-linking-library/6971)

<div class="topic-metadata">

**Author:** [@willem](https://discourse.cmake.org/u/willem)\
**Replies:** 6\
**Last updated:** [June 17, 2023, 9:59pm UTC](https://discourse.cmake.org/t/why-is-manual-copying-of-dll-needed-when-linking-library/6971 "2023-06-17T21:59:41Z")

</div>

I am trying to figure out how CMake is supposed to work for shared libraries. I create a shared library like so: (in /mdp\_opt/CMakeLists.txt:) add\_library (mdp\_opt SHARED librarycomponent.cpp) Now, a test executable u…

---

## [Why does project() change CMAKE\_TOOLCHAIN\_FILE only on first configure?](https://discourse.cmake.org/t/why-does-project-change-cmake-toolchain-file-only-on-first-configure/8341)

<div class="topic-metadata">

**Author:** [@dstotts\_DMRC](https://discourse.cmake.org/u/dstotts_DMRC)\
**Replies:** 1\
**Last updated:** [June 16, 2023, 6:59am UTC](https://discourse.cmake.org/t/why-does-project-change-cmake-toolchain-file-only-on-first-configure/8341 "2023-06-16T06:59:44Z")

</div>

Consider: # CMakeLists.txt cmake\_minimum\_required(VERSION 3.25) message("Toolchain: ${CMAKE\_TOOLCHAIN\_FILE}") project(ToolchainTest) message("Toolchain: ${CMAKE\_TOOLCHAIN\_FILE}") # toolchain.cmake (empty file) On firs…

---

## [Supressing INTERFACE sources from showing up in downstream VS Sln libraries](https://discourse.cmake.org/t/supressing-interface-sources-from-showing-up-in-downstream-vs-sln-libraries/8329)

<div class="topic-metadata">

**Author:** [@dwarwick](https://discourse.cmake.org/u/dwarwick)\
**Replies:** 1\
**Last updated:** [June 15, 2023, 12:29pm UTC](https://discourse.cmake.org/t/supressing-interface-sources-from-showing-up-in-downstream-vs-sln-libraries/8329 "2023-06-15T12:29:37Z")

</div>

We use a third-party library with a lot of headers which a good amount of libraries in our codebase have a transitive dependency on (unfortunately). However, because the third-party library’s headers are INTERFACE source…

---

## [target\_compile\_definitions with UTF-8 data](https://discourse.cmake.org/t/target-compile-definitions-with-utf-8-data/8287)

<div class="topic-metadata">

**Author:** [@philtherobot](https://discourse.cmake.org/u/philtherobot)\
**Replies:** 4\
**Last updated:** [June 14, 2023, 1:52pm UTC](https://discourse.cmake.org/t/target-compile-definitions-with-utf-8-data/8287 "2023-06-14T13:52:05Z")

</div>

I have to set a compiler definition which contains UTF-8 data. target\_compile\_definitions(${TARGET} PRIVATE OPTIMAL\_REF\_DATA\_PATH="${OPTIMAL\_REF\_DATA\_PATH}") The variable OPTIMAL\_REF\_DATA\_PATH contains UTF-8 da…

---

## [Having issue with Cmake "string sub-command REGEX, mode REPLACE needs at least 6 arguments total to command."](https://discourse.cmake.org/t/having-issue-with-cmake-string-sub-command-regex-mode-replace-needs-at-least-6-arguments-total-to-command/8310)

<div class="topic-metadata">

**Author:** [@kikendo](https://discourse.cmake.org/u/kikendo)\
**Replies:** 2\
**Last updated:** [June 12, 2023, 12:48pm UTC](https://discourse.cmake.org/t/having-issue-with-cmake-string-sub-command-regex-mode-replace-needs-at-least-6-arguments-total-to-command/8310 "2023-06-12T12:48:44Z")

</div>

I have inherited a project for which I can have no help of those who I inherited it from, and am running into a wall that I cannot comprehend. I hope someone here can shed some light to help this absolute noob understand…

---

## [FetchContent in dependency management](https://discourse.cmake.org/t/fetchcontent-in-dependency-management/6038)

<div class="topic-metadata">

**Author:** [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)\
**Replies:** 9\
**Last updated:** [June 9, 2023, 8:00am UTC](https://discourse.cmake.org/t/fetchcontent-in-dependency-management/6038 "2023-06-09T08:00:51Z")

</div>

I would like to ask for some guidance on best practices and suggestions on how to handle deps in CMake. I am developing CMake-based C++ projects for customers that depend on a couple of libraries but wish to provide a cl…

---

## [modern cmake file structure](https://discourse.cmake.org/t/modern-cmake-file-structure/1377)

<div class="topic-metadata">

**Author:** [@kayarre](https://discourse.cmake.org/u/kayarre)\
**Replies:** 3\
**Last updated:** [June 8, 2023, 5:53pm UTC](https://discourse.cmake.org/t/modern-cmake-file-structure/1377 "2023-06-08T17:53:03Z")

</div>

I am trying to convert an existing cmake project to use some of the more modern cmake patterns and generate the correct Config.cmake files to be imported by another project I have the following file structure in the one…

---

## [Per-file #define pattern in CMake (log-level/file-hash,etc)](https://discourse.cmake.org/t/per-file-define-pattern-in-cmake-log-level-file-hash-etc/8281)

<div class="topic-metadata">

**Author:** [@sam](https://discourse.cmake.org/u/sam)\
**Replies:** 1\
**Last updated:** [June 8, 2023, 4:15am UTC](https://discourse.cmake.org/t/per-file-define-pattern-in-cmake-log-level-file-hash-etc/8281 "2023-06-08T04:15:39Z")

</div>

Hi everyone, I lead a team of embedded C software engineers and we’re seeking a more suitable build system than what we have had grow organically over the years. I’ve been reading lots of CMake documentation, and testin…

---

## [CMake failing gcc compiler checks](https://discourse.cmake.org/t/cmake-failing-gcc-compiler-checks/8277)

<div class="topic-metadata">

**Author:** [@Solly](https://discourse.cmake.org/u/Solly)\
**Replies:** 8\
**Last updated:** [June 8, 2023, 4:06am UTC](https://discourse.cmake.org/t/cmake-failing-gcc-compiler-checks/8277 "2023-06-08T04:06:52Z")

</div>

CMake for some reason has stopped working recently. I’m trying to compile DDNet because I like to patch it however am failing. The same error occurs on every project using c(pp) with this error. -- The C compiler identi…

---

## [Macros, target\_link\_library, target\_sources evaluation questions](https://discourse.cmake.org/t/macros-target-link-library-target-sources-evaluation-questions/8279)

<div class="topic-metadata">

**Author:** [@jwm](https://discourse.cmake.org/u/jwm)\
**Replies:** 2\
**Last updated:** [June 7, 2023, 10:08pm UTC](https://discourse.cmake.org/t/macros-target-link-library-target-sources-evaluation-questions/8279 "2023-06-07T22:08:46Z")

</div>

I am developing a set of practices to facilitate commonality in our projects. One of them, to facilitate unit tests, is that for a given executable, all the sources except for “main” should be in a “library” (OBJECT libr…

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

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