# Code

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

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

**Page:** 43

---

## [Basic CMake command question - set(+qca\_fw)](https://discourse.cmake.org/t/basic-cmake-command-question-set-qca-fw/6484)

<div class="topic-metadata">

**Author:** [@Paul](https://discourse.cmake.org/u/Paul)\
**Replies:** 2\
**Last updated:** [September 14, 2022, 7:55am UTC](https://discourse.cmake.org/t/basic-cmake-command-question-set-qca-fw/6484 "2022-09-14T07:55:49Z")

</div>

I am trying to build QGIS from GitHUb source for windows, using QtCreator and CMake. The FindQCA.cmake includes: set(\_qca\_fw) if(QCA\_LIBRARY MATCHES “/qca.\*\\.framework”) string(REGEX REPLACE “^(./qca.\\.framework).\*$”…

---

## [Custom Toolchain - how to prevent library filename extension stripping](https://discourse.cmake.org/t/custom-toolchain-how-to-prevent-library-filename-extension-stripping/6443)

<div class="topic-metadata">

**Author:** [@bradlit](https://discourse.cmake.org/u/bradlit)\
**Replies:** 5\
**Last updated:** [September 12, 2022, 4:19pm UTC](https://discourse.cmake.org/t/custom-toolchain-how-to-prevent-library-filename-extension-stripping/6443 "2022-09-12T16:19:02Z")

</div>

I am trying to use CMake with the MSVC compiler/linker via a custom toolchain. Everything works good until a project tries to specify custom link libraries, like this: CMakeLists.txt: target\_link\_libraries(Simulator P…

---

## [Build same lib with identical names in subninjas](https://discourse.cmake.org/t/build-same-lib-with-identical-names-in-subninjas/6296)

<div class="topic-metadata">

**Author:** [@neuschwander\_lmi](https://discourse.cmake.org/u/neuschwander_lmi)\
**Replies:** 2\
**Last updated:** [September 12, 2022, 9:22am UTC](https://discourse.cmake.org/t/build-same-lib-with-identical-names-in-subninjas/6296 "2022-09-12T09:22:26Z")

</div>

I am trying to create a build containing several cmake projects. Splitting the “whole” project into multiple cmake projects is necessary to support different C++ toolchains in one build. We use the ninja generator and h…

---

## [\[BUG\] postrm run when install](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434)

<div class="topic-metadata">

**Author:** [@alice](https://discourse.cmake.org/u/alice)\
**Replies:** 7\
**Last updated:** [September 11, 2022, 9:18pm UTC](https://discourse.cmake.org/t/bug-postrm-run-when-install/6434 "2022-09-11T21:18:01Z")

</div>

I want to let postrm run when uninstalling. But it run on installing, so my folder test be remove. set(DEBIAN\_PRERM prerm.in) configure\_file(${CMAKE\_CURRENT\_SOURCE\_DIR}/cmake/deb/linux/${DEBIAN\_PRERM} …

---

## [Selecting quality CMake code example(s)](https://discourse.cmake.org/t/selecting-quality-cmake-code-example-s/6289)

<div class="topic-metadata">

**Author:** [@EricGT](https://discourse.cmake.org/u/EricGT)\
**Replies:** 4\
**Last updated:** [September 8, 2022, 7:55am UTC](https://discourse.cmake.org/t/selecting-quality-cmake-code-example-s/6289 "2022-09-08T07:55:39Z")

</div>

In a related question a suggestion was made to create list of quality CMake code examples. One GitHub repository that while large seems to meet the criteria is GitHub query for just the CMake code. As I am new to us…

---

## [Match dot in regex](https://discourse.cmake.org/t/match-dot-in-regex/6420)

<div class="topic-metadata">

**Author:** [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Replies:** 3\
**Last updated:** [September 6, 2022, 1:11pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420 "2022-09-06T13:11:04Z")

</div>

I’m having some issue getting CMake to match a literal dot in a regex expression. The following regex works, but doesn’t match a dot: file(STRINGS "${INPUT\_FILE}" VERSION\_BRANCH\_FRIENDLY REGEX "^\[ \\t\]\*#define\[ \\t\]+VERSI…

---

## [Generate a compile\_commands.json for a specific target](https://discourse.cmake.org/t/generate-a-compile-commands-json-for-a-specific-target/6389)

<div class="topic-metadata">

**Author:** [@itavero](https://discourse.cmake.org/u/itavero)\
**Replies:** 5\
**Last updated:** [September 6, 2022, 6:50am UTC](https://discourse.cmake.org/t/generate-a-compile-commands-json-for-a-specific-target/6389 "2022-09-06T06:50:44Z")

</div>

For running PC Lint Plus, we currently use the compile\_commands.json. This works, but had some caveats when it comes to excluding supplied SDKs and such from our analysis, as they would be included in the JSON as well. …

---

## [Configuration error when fetching two dependencies when there is a dependency between them](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225)

<div class="topic-metadata">

**Author:** [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Replies:** 6\
**Last updated:** [September 6, 2022, 2:59am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225 "2022-09-06T02:59:59Z")

</div>

I was hoping to pull in both zeromq and azmq (asio binding) for a personal project. I’m using CMake 3.23 on Windows 10 with Visual Studio 2019 MSVC. In my project CMake I do this: FetchContent\_Declare( zeromq …

---

## [Marking headers as SYSTEM does not suppress warnings on Windows.](https://discourse.cmake.org/t/marking-headers-as-system-does-not-suppress-warnings-on-windows/6415)

<div class="topic-metadata">

**Author:** [@rokoDev](https://discourse.cmake.org/u/rokoDev)\
**Replies:** 1\
**Last updated:** [September 5, 2022, 9:28pm UTC](https://discourse.cmake.org/t/marking-headers-as-system-does-not-suppress-warnings-on-windows/6415 "2022-09-05T21:28:02Z")

</div>

Hi :slight\_smile: I need to compile unit tests for simple project with some warnings turned on. But I want to suppress this warnings from being arisen in an external INTERFACE library(actually this is my fork from Boos…

---

## [Two questions](https://discourse.cmake.org/t/two-questions/6413)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 1\
**Last updated:** [September 5, 2022, 8:14pm UTC](https://discourse.cmake.org/t/two-questions/6413 "2022-09-05T20:14:46Z")

</div>

How do I print the values of include\_directories() inside a CMakeLists.txt file? I’ve been trying with get\_property with no success. How do I pass down the directories specified in include\_directories down to a subdire…

---

## [Having cmake to generate list files as per source file](https://discourse.cmake.org/t/having-cmake-to-generate-list-files-as-per-source-file/6191)

<div class="topic-metadata">

**Author:** [@fruitCoder123](https://discourse.cmake.org/u/fruitCoder123)\
**Replies:** 3\
**Last updated:** [September 4, 2022, 7:40pm UTC](https://discourse.cmake.org/t/having-cmake-to-generate-list-files-as-per-source-file/6191 "2022-09-04T19:40:47Z")

</div>

GCC offers an assembler option to generate list files: -Wa,-adhln=\<path/file.lst\> I know my way around in cmake but I am pulling my hair how to get this in. My struggle is because it is per source file that I like to h…

---

## [swig generated code not finding libraries on macOS 12. rpath issue?](https://discourse.cmake.org/t/swig-generated-code-not-finding-libraries-on-macos-12-rpath-issue/6384)

<div class="topic-metadata">

**Author:** [@snarkhunter](https://discourse.cmake.org/u/snarkhunter)\
**Replies:** 2\
**Last updated:** [September 2, 2022, 4:05pm UTC](https://discourse.cmake.org/t/swig-generated-code-not-finding-libraries-on-macos-12-rpath-issue/6384 "2022-09-02T16:05:55Z")

</div>

Hi – My project contains swig files that create libraries that need to link to external libraries. Some of the external libraries are obtained via pkgconfig, and pkg\_check\_modules places their (nonstandard) full paths …

---

## [append headers using target\_include\_directories() after target\_compile\_options()](https://discourse.cmake.org/t/append-headers-using-target-include-directories-after-target-compile-options/6388)

<div class="topic-metadata">

**Author:** [@Khushal\_Khanna](https://discourse.cmake.org/u/Khushal_Khanna)\
**Replies:** 1\
**Last updated:** [September 2, 2022, 2:05pm UTC](https://discourse.cmake.org/t/append-headers-using-target-include-directories-after-target-compile-options/6388 "2022-09-02T14:05:17Z")

</div>

Hello all, I have some compiler settings that require me to append headers after compile\_options in generated .rsp files. In current case, .rsp file → headers compiler\_options required case → compiler options headers …

---

## [About the behaviour of CTEST\_CUSTOM\_PRE\_TEST](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298)

<div class="topic-metadata">

**Author:** [@Bicen\_Zhu](https://discourse.cmake.org/u/Bicen_Zhu)\
**Replies:** 2\
**Last updated:** [September 2, 2022, 3:03am UTC](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298 "2022-09-02T03:03:36Z")

</div>

Hello, Have a problem when using CTEST\_CUSTOM\_PRE\_TEST to start a daemon. After the daemon started, ctest still wait it exit For example I have a python daemon, when I run it by command python3 myDaemon.py, it returns …

---

## [Manually-specified variables were not used by the project:](https://discourse.cmake.org/t/manually-specified-variables-were-not-used-by-the-project/6321)

<div class="topic-metadata">

**Author:** [@TorstenRobitzki](https://discourse.cmake.org/u/TorstenRobitzki)\
**Replies:** 4\
**Last updated:** [August 30, 2022, 2:01pm UTC](https://discourse.cmake.org/t/manually-specified-variables-were-not-used-by-the-project/6321 "2022-08-30T14:01:50Z")

</div>

Hello, I have the need to pass a binary option to my build process. I pass the option as cache variable: cmake ... -DMY\_OPTION=1 Within one of the CMakeLists.txt, I ask for the existence of this parameter: if (DEFINE…

---

## [Adding dependency to generated files to a single source file?](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372)

<div class="topic-metadata">

**Author:** [@Naville](https://discourse.cmake.org/u/Naville)\
**Replies:** 3\
**Last updated:** [August 29, 2022, 12:52pm UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372 "2022-08-29T12:52:11Z")

</div>

Hi: In my use case, I have commands at configure time that generates .cpp.inc files from input files, something like : configure\_file( "${CMAKE\_CURRENT\_LIST\_DIR}/Input.cpp.in" "${CMAKE\_CURRENT\_BINARY\_DI…

---

## [Creating reliable C++/WinRT builds with CMake?](https://discourse.cmake.org/t/creating-reliable-c-winrt-builds-with-cmake/3375)

<div class="topic-metadata">

**Author:** [@tague](https://discourse.cmake.org/u/tague)\
**Replies:** 6\
**Last updated:** [August 29, 2022, 5:21am UTC](https://discourse.cmake.org/t/creating-reliable-c-winrt-builds-with-cmake/3375 "2022-08-29T05:21:44Z")

</div>

Hi, I’ve been working on a project that’s half-using CMake at the moment - a ‘core’ library is built using CMake, and then include\_external\_msproject is used to include a Visual Studio project that builds a C++/WinRT li…

---

## [How to create different filters for the same files in different projects?](https://discourse.cmake.org/t/how-to-create-different-filters-for-the-same-files-in-different-projects/6360)

<div class="topic-metadata">

**Author:** [@Kulagin](https://discourse.cmake.org/u/Kulagin)\
**Replies:** 2\
**Last updated:** [August 28, 2022, 11:59am UTC](https://discourse.cmake.org/t/how-to-create-different-filters-for-the-same-files-in-different-projects/6360 "2022-08-28T11:59:44Z")

</div>

Solution to quickly reproduce the problem: I have this file structure: My Solution(dir) +-- CMakeLists.txt +-- MainProject(dir) +-- File1.cpp +-- File1.h …

---

## [Correct setup for building a compiler then its stdlib](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363)

<div class="topic-metadata">

**Author:** [@asdf2](https://discourse.cmake.org/u/asdf2)\
**Replies:** 2\
**Last updated:** [August 27, 2022, 11:44pm UTC](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363 "2022-08-27T23:44:48Z")

</div>

I need to build a Fortran compiler written in C++ then its libraries written in Fortran. I would like said libraries to be compiled with my just built compiler. The problem is that the compiler binary doesn’t exist while…

---

## [example: GPG sign CMake / CPack](https://discourse.cmake.org/t/example-gpg-sign-cmake-cpack/6359)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 0\
**Last updated:** [August 26, 2022, 11:15pm UTC](https://discourse.cmake.org/t/example-gpg-sign-cmake-cpack/6359 "2022-08-26T23:15:08Z")

</div>

I made a minimal CMake example project for signing CMake-built project binaries as well as signing CPack source and binary packages:

---

## [Matlab Apple Silicon beta](https://discourse.cmake.org/t/matlab-apple-silicon-beta/6356)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 2\
**Last updated:** [August 26, 2022, 11:04pm UTC](https://discourse.cmake.org/t/matlab-apple-silicon-beta/6356 "2022-08-26T23:04:38Z")

</div>

Mathworks has an Apple Silicon beta for Matlab. They’ve mentioned also possible upcoming ARM64 support for other operating systems. For now, to test Matlab for Apple Silicon, I made this small patch to CMake’s factory Fi…

---

## [Project with Native & Cross-compile Targets](https://discourse.cmake.org/t/project-with-native-cross-compile-targets/6343)

<div class="topic-metadata">

**Author:** [@sampsont](https://discourse.cmake.org/u/sampsont)\
**Replies:** 1\
**Last updated:** [August 25, 2022, 11:00pm UTC](https://discourse.cmake.org/t/project-with-native-cross-compile-targets/6343 "2022-08-25T23:00:32Z")

</div>

My C++ VS Code project has multiple native executables & multiple cross-compiled executables. Some of the executables are compiled native and cross-compiled. All executables use the same library. Is it possible to do …

---

## [how to jump to the right directory path in the xcode project which generated by cmake used 'source\_group'?](https://discourse.cmake.org/t/how-to-jump-to-the-right-directory-path-in-the-xcode-project-which-generated-by-cmake-used-source-group/6334)

<div class="topic-metadata">

**Author:** [@Princekin](https://discourse.cmake.org/u/Princekin)\
**Replies:** 1\
**Last updated:** [August 25, 2022, 10:53pm UTC](https://discourse.cmake.org/t/how-to-jump-to-the-right-directory-path-in-the-xcode-project-which-generated-by-cmake-used-source-group/6334 "2022-08-25T22:53:54Z")

</div>

Hi: I used the CMake to build an iOS XCode project, I have a multiple level source code, so I use ‘source\_group’ to organize them, here is my CMake code file(GLOB\_RECURSE MODULE\_DEMO\_DIR\_FILES "${MODULE\_DEMO\_DIR}/…

---

## [Is there a way to detect whether cmake is being run as a sudo or root user?](https://discourse.cmake.org/t/is-there-a-way-to-detect-whether-cmake-is-being-run-as-a-sudo-or-root-user/6340)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 2\
**Last updated:** [August 25, 2022, 3:26pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-detect-whether-cmake-is-being-run-as-a-sudo-or-root-user/6340 "2022-08-25T15:26:49Z")

</div>

I would like to detect whether the CMakeLists.txt file is run with sudo priveleges, so that an application for example on macOS can be installed to the /Application directory while if it is not, it installed into CMAKE\_I…

---

## [Poco C++ lib used for native & cross compile](https://discourse.cmake.org/t/poco-c-lib-used-for-native-cross-compile/6338)

<div class="topic-metadata">

**Author:** [@sampsont](https://discourse.cmake.org/u/sampsont)\
**Replies:** 0\
**Last updated:** [August 25, 2022, 1:48pm UTC](https://discourse.cmake.org/t/poco-c-lib-used-for-native-cross-compile/6338 "2022-08-25T13:48:16Z")

</div>

I’m trying to get a C++ project going in VS Code with cmake. There are several executables. Some are native Linux, some are cross compiled for Power PC. Some are both. All use the Poco llibrary. The Poco library nee…

---

## [How to prevent CMake linking system libraries?](https://discourse.cmake.org/t/how-to-prevent-cmake-linking-system-libraries/6328)

<div class="topic-metadata">

**Author:** [@Kulagin](https://discourse.cmake.org/u/Kulagin)\
**Replies:** 4\
**Last updated:** [August 24, 2022, 5:44pm UTC](https://discourse.cmake.org/t/how-to-prevent-cmake-linking-system-libraries/6328 "2022-08-24T17:44:21Z")

</div>

I’ll use CMake’s example project as an example. So I have this: cmake\_minimum\_required(VERSION 3.10) # set the project name project(Tutorial) # add the executable add\_executable(Tutorial tutorial.h) set\_target\_proper…

---

## [Doing a version of tutorial using zlib. Questions about provided CMakeLists.txt](https://discourse.cmake.org/t/doing-a-version-of-tutorial-using-zlib-questions-about-provided-cmakelists-txt/6329)

<div class="topic-metadata">

**Author:** [@EricGT](https://discourse.cmake.org/u/EricGT)\
**Replies:** 1\
**Last updated:** [August 24, 2022, 1:32pm UTC](https://discourse.cmake.org/t/doing-a-version-of-tutorial-using-zlib-questions-about-provided-cmakelists-txt/6329 "2022-08-24T13:32:43Z")

</div>

Having completed the CMake tutorial decided to do it again but with a different dance partner, instead of a simple square root function will be using zlib (Home page, GitHub, Wikipedia) The code on GitHub provides a CMa…

---

## [executable target not relinking when custom target updated](https://discourse.cmake.org/t/executable-target-not-relinking-when-custom-target-updated/6286)

<div class="topic-metadata">

**Author:** [@marksibly](https://discourse.cmake.org/u/marksibly)\
**Replies:** 7\
**Last updated:** [August 23, 2022, 11:54am UTC](https://discourse.cmake.org/t/executable-target-not-relinking-when-custom-target-updated/6286 "2022-08-23T11:54:01Z")

</div>

Hi, I’m trying to write some cmake that will copy a bunch of files in a source directory to a destination directory and relink the destination app, but only if one of the files in the source directory has been modified.…

---

## [Feature to disable empty parameters resolving into unset function arguments](https://discourse.cmake.org/t/feature-to-disable-empty-parameters-resolving-into-unset-function-arguments/6085)

<div class="topic-metadata">

**Author:** [@gabyx](https://discourse.cmake.org/u/gabyx)\
**Replies:** 6\
**Last updated:** [August 22, 2022, 7:44am UTC](https://discourse.cmake.org/t/feature-to-disable-empty-parameters-resolving-into-unset-function-arguments/6085 "2022-08-22T07:44:07Z")

</div>

I would love to see some progression in CMake syntaxt such that it gets more safe and better to use. Such as to disable set(A ${var}) which accidentially unsets variable A if var is empty. Instead the the set should al…

---

## [Link external static lib along with dynamic libs to the executable](https://discourse.cmake.org/t/link-external-static-lib-along-with-dynamic-libs-to-the-executable/6309)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 4\
**Last updated:** [August 21, 2022, 10:44am UTC](https://discourse.cmake.org/t/link-external-static-lib-along-with-dynamic-libs-to-the-executable/6309 "2022-08-21T10:44:51Z")

</div>

Hi, Can’t understand why linker gives me error: licensecc\_static.lib(licensecc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT\_StaticRelease' d oesn't match value 'MD\_DynamicRelease' in Main.obj…

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

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