# Code

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

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

**Page:** 60

---

## [How to link static libraries together](https://discourse.cmake.org/t/how-to-link-static-libraries-together/3271)

<div class="topic-metadata">

**Author:** [@serge](https://discourse.cmake.org/u/serge)\
**Replies:** 4\
**Last updated:** [May 9, 2021, 1:37pm UTC](https://discourse.cmake.org/t/how-to-link-static-libraries-together/3271 "2021-05-09T13:37:50Z")

</div>

Hi everyone, another basic question on windows. suppose I have 3 directories, say x, y, z under root. Basically, I want libx and liby to be linked into libz - here is how I do it: Directories x and y are similar with…

---

## [Using Interface as specs with subdirectories](https://discourse.cmake.org/t/using-interface-as-specs-with-subdirectories/3276)

<div class="topic-metadata">

**Author:** [@OD1](https://discourse.cmake.org/u/OD1)\
**Replies:** 8\
**Last updated:** [May 7, 2021, 2:08pm UTC](https://discourse.cmake.org/t/using-interface-as-specs-with-subdirectories/3276 "2021-05-07T14:08:44Z")

</div>

In the interest of clarity and capturing requirements clearly, I’m attempting to use INTERFACE targets as a mechanism to group compiler flags, definitions, and linker options. An example is like so: add\_library(my\_specs…

---

## [configure\_file: generate code dependant on an if clause ?](https://discourse.cmake.org/t/configure-file-generate-code-dependant-on-an-if-clause/3269)

<div class="topic-metadata">

**Author:** [@ProTurm2](https://discourse.cmake.org/u/ProTurm2)\
**Replies:** 4\
**Last updated:** [May 5, 2021, 2:07pm UTC](https://discourse.cmake.org/t/configure-file-generate-code-dependant-on-an-if-clause/3269 "2021-05-05T14:07:12Z")

</div>

Id like to generate a .h file containing code dependent on an if clause set in the input file of the configure\_file. if (VAR) generate this line; else() generate that line; endif() As for now, Im getting in the .h co…

---

## [Special action for special source files](https://discourse.cmake.org/t/special-action-for-special-source-files/3267)

<div class="topic-metadata">

**Author:** [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Replies:** 1\
**Last updated:** [May 5, 2021, 1:54pm UTC](https://discourse.cmake.org/t/special-action-for-special-source-files/3267 "2021-05-05T13:54:36Z")

</div>

I will try to explain my problem abstractly: I have a huge project, that compiles a lot of cpp files. Some of them do need special treatment after the build. (My case: the need to be installed to a special folder and d…

---

## [Defining a Custom URL Scheme in XCode](https://discourse.cmake.org/t/defining-a-custom-url-scheme-in-xcode/3261)

<div class="topic-metadata">

**Author:** [@Guillermo\_Amorin](https://discourse.cmake.org/u/Guillermo_Amorin)\
**Replies:** 2\
**Last updated:** [May 4, 2021, 5:40pm UTC](https://discourse.cmake.org/t/defining-a-custom-url-scheme-in-xcode/3261 "2021-05-04T17:40:55Z")

</div>

In Xcode a URL type is defined to have a custom URL Scheme that opens the application, I wanted to know how to set this configuration from cmake.

---

## [auto increment project versions](https://discourse.cmake.org/t/auto-increment-project-versions/3250)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 2\
**Last updated:** [May 3, 2021, 11:58am UTC](https://discourse.cmake.org/t/auto-increment-project-versions/3250 "2021-05-03T11:58:39Z")

</div>

how can project versions be incremented automatically? project() must be called directly so i cannot generate and include it later. What i can do is set the project version seperately. Do i have to set all variants of C…

---

## [Different between "-DCMAKE\_CXX\_COMPILER=clang++" and "-DCMAKE\_CXX\_COMPILER=clang-12"](https://discourse.cmake.org/t/different-between-dcmake-cxx-compiler-clang-and-dcmake-cxx-compiler-clang-12/3245)

<div class="topic-metadata">

**Author:** [@psionic12](https://discourse.cmake.org/u/psionic12)\
**Replies:** 3\
**Last updated:** [May 2, 2021, 1:51pm UTC](https://discourse.cmake.org/t/different-between-dcmake-cxx-compiler-clang-and-dcmake-cxx-compiler-clang-12/3245 "2021-05-02T13:51:54Z")

</div>

In my environmental, clang and clang++ are all symbolic links to clang-12. And if I use -DCMAKE\_CXX\_COMPILER=clang++, my C++ codes will linked to stdc++ without problem, but if I use -DCMAKE\_CXX\_COMPILER=clang-12, it wil…

---

## [add\_custom\_command() POST\_BUILD generator expression expansion not working](https://discourse.cmake.org/t/add-custom-command-post-build-generator-expression-expansion-not-working/3244)

<div class="topic-metadata">

**Author:** [@sthlm58](https://discourse.cmake.org/u/sthlm58)\
**Replies:** 1\
**Last updated:** [May 2, 2021, 10:40am UTC](https://discourse.cmake.org/t/add-custom-command-post-build-generator-expression-expansion-not-working/3244 "2021-05-02T10:40:11Z")

</div>

I want to run a POST\_BUILD action after the build (but only in the Debug configuration). After reading add\_custom\_command docs and a possible solution (here on Discourse) I understood that I can “wrap” my COMMAND into $\<…

---

## [Executing a custom command on modified files.](https://discourse.cmake.org/t/executing-a-custom-command-on-modified-files/3240)

<div class="topic-metadata">

**Author:** [@JRR](https://discourse.cmake.org/u/JRR)\
**Replies:** 4\
**Last updated:** [April 30, 2021, 5:59pm UTC](https://discourse.cmake.org/t/executing-a-custom-command-on-modified-files/3240 "2021-04-30T17:59:32Z")

</div>

From what I understand compilation works something like: If the first time compile all files else only compile modified files I’d like to do something similar but instead of compile I’d like to run our companies style…

---

## [Installing headers the modern way](https://discourse.cmake.org/t/installing-headers-the-modern-way/2934)

<div class="topic-metadata">

**Author:** [@Braden](https://discourse.cmake.org/u/Braden)\
**Replies:** 6\
**Last updated:** [April 30, 2021, 1:02pm UTC](https://discourse.cmake.org/t/installing-headers-the-modern-way/2934 "2021-04-30T13:02:32Z")

</div>

I find myself doing this: target\_sources(mylib PUBLIC mypublic.h) get\_target\_property(MYLIB\_PUBLIC\_HEADERS mylib INTERFACE\_SOURCES) set\_target\_properties(mylib PROPERTIES PUBLIC\_HEADER "${MYLIB\_PUBLIC\_HEADERS}") install…

---

## [How to find all the include folders for a target for a static analyzer?](https://discourse.cmake.org/t/how-to-find-all-the-include-folders-for-a-target-for-a-static-analyzer/3233)

<div class="topic-metadata">

**Author:** [@JRR](https://discourse.cmake.org/u/JRR)\
**Replies:** 3\
**Last updated:** [April 29, 2021, 7:04pm UTC](https://discourse.cmake.org/t/how-to-find-all-the-include-folders-for-a-target-for-a-static-analyzer/3233 "2021-04-29T19:04:46Z")

</div>

We want to add a the cppcheck static analyzer to a product and it has input arguments such as: cppcheck \<files\> \\ --xml \\ --force \\ --output-file=results\\cppcheck \\ --error-exitcode=1 \\ …

---

## [How to remove quotation marks in the final command output?](https://discourse.cmake.org/t/how-to-remove-quotation-marks-in-the-final-command-output/3226)

<div class="topic-metadata">

**Author:** [@mscofield0](https://discourse.cmake.org/u/mscofield0)\
**Replies:** 2\
**Last updated:** [April 29, 2021, 7:40am UTC](https://discourse.cmake.org/t/how-to-remove-quotation-marks-in-the-final-command-output/3226 "2021-04-29T07:40:24Z")

</div>

So I need to remove the quotation marks from the commands, I don’t see how though… Please help. The error: FAILED: CMakeFiles/ccov-clean cmd.exe /C "cd /D ...\\build\\test && "del \\f ...\\build\\test\\ccov\\binaries.list" &&…

---

## [Support for XDG Spec](https://discourse.cmake.org/t/support-for-xdg-spec/3217)

<div class="topic-metadata">

**Author:** [@tjayrush](https://discourse.cmake.org/u/tjayrush)\
**Replies:** 7\
**Last updated:** [April 28, 2021, 11:23am UTC](https://discourse.cmake.org/t/support-for-xdg-spec/3217 "2021-04-28T11:23:46Z")

</div>

I’m not very good with CMake, so please excuse me if I’m missing something easy. Is there some way to support this spec: XDG Base Directory Specification It’s a specification for handling the $HOME folder on different o…

---

## [how to set variables for install(SCRIPT...)?](https://discourse.cmake.org/t/how-to-set-variables-for-install-script/3185)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 5\
**Last updated:** [April 27, 2021, 8:09pm UTC](https://discourse.cmake.org/t/how-to-set-variables-for-install-script/3185 "2021-04-27T20:09:11Z")

</div>

is it possible to pass a variable for the cmake script when using install(SCRIPT) mode? the following is invalid: install(SCRIPT -DFOO=bar -P foo.cmake) and this generates without error but doesn’t pass FOO to foo.cma…

---

## [is there a way to push linker output(MAP file) to separate log file in cmake](https://discourse.cmake.org/t/is-there-a-way-to-push-linker-output-map-file-to-separate-log-file-in-cmake/3218)

<div class="topic-metadata">

**Author:** [@deepan](https://discourse.cmake.org/u/deepan)\
**Replies:** 1\
**Last updated:** [April 27, 2021, 12:56pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-push-linker-output-map-file-to-separate-log-file-in-cmake/3218 "2021-04-27T12:56:01Z")

</div>

I am working in an embedded project with cmake version 3.18.5. The make file of type ninja. The command ninja \> log.txt is adding all the log information(file name, warning) along with Map file into log.txt . I don’t wan…

---

## [target\_precompile\_headers with MacOs and Objective-C++ (.mm) files](https://discourse.cmake.org/t/target-precompile-headers-with-macos-and-objective-c-mm-files/3205)

<div class="topic-metadata">

**Author:** [@mkloskezynaptiq](https://discourse.cmake.org/u/mkloskezynaptiq)\
**Replies:** 3\
**Last updated:** [April 26, 2021, 3:42pm UTC](https://discourse.cmake.org/t/target-precompile-headers-with-macos-and-objective-c-mm-files/3205 "2021-04-26T15:42:38Z")

</div>

Hello When I use target\_precompile\_headers in my project the compilation of my mm-files fail with the following error: error: Objective-C 1 was disabled in PCH file but is currently enabled. However, when I generate a…

---

## [ExternalProject and CMAKE\_TOOLCHAIN\_FILE](https://discourse.cmake.org/t/externalproject-and-cmake-toolchain-file/3194)

<div class="topic-metadata">

**Author:** [@jano42](https://discourse.cmake.org/u/jano42)\
**Replies:** 5\
**Last updated:** [April 25, 2021, 3:01pm UTC](https://discourse.cmake.org/t/externalproject-and-cmake-toolchain-file/3194 "2021-04-25T15:01:09Z")

</div>

Hello I’m using CMake to build my OpenSource project, for home automation : Yadoms Our software supports many platforms (Windows, linux, mac) and cross compilation (RaspberryPI, Synology NAS,…) We are using “ExternalP…

---

## [PkgConfig's IMPORTED\_TARGET doesn't seem to have a \`\_STATIC\` variant?](https://discourse.cmake.org/t/pkgconfigs-imported-target-doesnt-seem-to-have-a-static-variant/3186)

<div class="topic-metadata">

**Author:** [@morrisonlevi](https://discourse.cmake.org/u/morrisonlevi)\
**Replies:** 2\
**Last updated:** [April 22, 2021, 4:04pm UTC](https://discourse.cmake.org/t/pkgconfigs-imported-target-doesnt-seem-to-have-a-static-variant/3186 "2021-04-22T16:04:59Z")

</div>

Consider something like this: find\_package(PkgConfig REQUIRED) pkg\_check\_modules(UV REQUIRED IMPORTED\_TARGET libuv) There doesn’t seem to be a PkgConfig::UV\_STATIC target that has all the properties from running pkg-co…

---

## [add\_jar and resources - relative path question](https://discourse.cmake.org/t/add-jar-and-resources-relative-path-question/3187)

<div class="topic-metadata">

**Author:** [@Jack\_Smith](https://discourse.cmake.org/u/Jack_Smith)\
**Replies:** 3\
**Last updated:** [April 22, 2021, 3:26pm UTC](https://discourse.cmake.org/t/add-jar-and-resources-relative-path-question/3187 "2021-04-22T15:26:42Z")

</div>

I am using add\_jar with reasonable success, except . . . I want to add graphic resources, which I am able to do ONLY by specifying relative paths (which itself is a little strange); but, that isn’t exactly the problem. …

---

## [Pattern for running tests in-tree and with installed targets?](https://discourse.cmake.org/t/pattern-for-running-tests-in-tree-and-with-installed-targets/3113)

<div class="topic-metadata">

**Author:** [@morrisonlevi](https://discourse.cmake.org/u/morrisonlevi)\
**Replies:** 5\
**Last updated:** [April 21, 2021, 1:00am UTC](https://discourse.cmake.org/t/pattern-for-running-tests-in-tree-and-with-installed-targets/3113 "2021-04-21T01:00:11Z")

</div>

I want to make sure that the targets I export and install are set up correctly. Running the test suite against both the in-tree build and installed version would solve that nicely. Is there a known pattern for this? Some…

---

## [No rule to make target 'install'](https://discourse.cmake.org/t/no-rule-to-make-target-install/3170)

<div class="topic-metadata">

**Author:** [@ardtrkc](https://discourse.cmake.org/u/ardtrkc)\
**Replies:** 6\
**Last updated:** [April 18, 2021, 10:07pm UTC](https://discourse.cmake.org/t/no-rule-to-make-target-install/3170 "2021-04-18T22:07:17Z")

</div>

While compiling the minimal.cpp example of TensorFlow Lite with cmake on Yocto platform, we are having error as follows: Log data follows: | DEBUG: Executing shell function do\_install | NOTE: make -j 4 DESTDIR=/home…

---

## [Generated files not found in symlink folder](https://discourse.cmake.org/t/generated-files-not-found-in-symlink-folder/3144)

<div class="topic-metadata">

**Author:** [@Jph](https://discourse.cmake.org/u/Jph)\
**Replies:** 5\
**Last updated:** [April 18, 2021, 5:00pm UTC](https://discourse.cmake.org/t/generated-files-not-found-in-symlink-folder/3144 "2021-04-18T17:00:39Z")

</div>

Hi there, I am am new to CMake. I followed the below style to create a CMake project to generate source and build. It works fine when build in the real path. However, I also need to run the build in a symlink path. When …

---

## [Composing JSON in CMake (a small set of macros to make it easier...)](https://discourse.cmake.org/t/composing-json-in-cmake-a-small-set-of-macros-to-make-it-easier/3163)

<div class="topic-metadata">

**Author:** [@dchapiesky](https://discourse.cmake.org/u/dchapiesky)\
**Replies:** 0\
**Last updated:** [April 16, 2021, 9:53am UTC](https://discourse.cmake.org/t/composing-json-in-cmake-a-small-set-of-macros-to-make-it-easier/3163 "2021-04-16T09:53:10Z")

</div>

So I was working with string(JSON…SET…) to compose a JSON string and after a while it became increasingly hard to understand just what I had written… especially semicolon separated lists… my brain looks at them as lists …

---

## [how to cleanup random byproducts](https://discourse.cmake.org/t/how-to-cleanup-random-byproducts/3154)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 3\
**Last updated:** [April 15, 2021, 10:53pm UTC](https://discourse.cmake.org/t/how-to-cleanup-random-byproducts/3154 "2021-04-15T22:53:01Z")

</div>

i have several files with a random counter in the filename that i want to remove on clean. add\_custom\_target(foo ALL COMMAND ${CMAKE\_COMMAND} -E touch afile{1..3}.bar BYPRODUCTS \*.bar ) however, CMake doe…

---

## [How to create a custom target that only runs a command for a subset of configurations?](https://discourse.cmake.org/t/how-to-create-a-custom-target-that-only-runs-a-command-for-a-subset-of-configurations/3093)

<div class="topic-metadata">

**Author:** [@Knitschi](https://discourse.cmake.org/u/Knitschi)\
**Replies:** 5\
**Last updated:** [April 16, 2021, 1:31am UTC](https://discourse.cmake.org/t/how-to-create-a-custom-target-that-only-runs-a-command-for-a-subset-of-configurations/3093 "2021-04-16T01:31:51Z")

</div>

CMake 3.20 enables using generator expressions in the add\_custom\_command(OUTPUT) argument. I am now trying to create a custom command that only runs a command for a subset of the available CMAKE\_CONFIGURATION\_TYPES. Aft…

---

## [Managing namelink install target export](https://discourse.cmake.org/t/managing-namelink-install-target-export/3134)

<div class="topic-metadata">

**Author:** [@VRonin](https://discourse.cmake.org/u/VRonin)\
**Replies:** 9\
**Last updated:** [April 16, 2021, 12:54am UTC](https://discourse.cmake.org/t/managing-namelink-install-target-export/3134 "2021-04-16T00:54:47Z")

</div>

Hi Everyone, I have a problem using install(TARGETS EXPORT and install(EXPORT. I have to support CMake 3.2 so I can’t use NAMELINK\_COMPONENT. My simplified code is below, it’s taken mostly from @craig.scott’s book. M…

---

## [Generating linker command line arguments to a file](https://discourse.cmake.org/t/generating-linker-command-line-arguments-to-a-file/3117)

<div class="topic-metadata">

**Author:** [@amp](https://discourse.cmake.org/u/amp)\
**Replies:** 6\
**Last updated:** [April 14, 2021, 1:51pm UTC](https://discourse.cmake.org/t/generating-linker-command-line-arguments-to-a-file/3117 "2021-04-14T13:51:07Z")

</div>

I need to run a non-cmake sub-build (setuptools based in this case) in a cmake project and pass the linker and compiler command lines to that sub-build. My current implementation writes the command line arguments to a fi…

---

## [get\_runtime\_dependencies unresolved libgfortran.so](https://discourse.cmake.org/t/get-runtime-dependencies-unresolved-libgfortran-so/3131)

<div class="topic-metadata">

**Author:** [@grimgort](https://discourse.cmake.org/u/grimgort)\
**Replies:** 3\
**Last updated:** [April 14, 2021, 1:50pm UTC](https://discourse.cmake.org/t/get-runtime-dependencies-unresolved-libgfortran-so/3131 "2021-04-14T13:50:27Z")

</div>

I use the following code to install the depences of the dynamic libraries, but libgfortran remains unresolved although it seems to be well detected by the system.

---

## [Is there a hidden CMAKE variable for the input to a macro/function as a string, not a list, untouched, unadulterated?](https://discourse.cmake.org/t/is-there-a-hidden-cmake-variable-for-the-input-to-a-macro-function-as-a-string-not-a-list-untouched-unadulterated/3140)

<div class="topic-metadata">

**Author:** [@danielmrussell](https://discourse.cmake.org/u/danielmrussell)\
**Replies:** 2\
**Last updated:** [April 13, 2021, 8:11pm UTC](https://discourse.cmake.org/t/is-there-a-hidden-cmake-variable-for-the-input-to-a-macro-function-as-a-string-not-a-list-untouched-unadulterated/3140 "2021-04-13T20:11:13Z")

</div>

Basically I would like to access the full, original, untouched input string to a macro or function, instead of accessing argv# or argn, etc. The reason for this is that I’m implementing a project that aims to sweeten th…

---

## [Failed to build Android application using Qt](https://discourse.cmake.org/t/failed-to-build-android-application-using-qt/3106)

<div class="topic-metadata">

**Author:** [@tangyoha](https://discourse.cmake.org/u/tangyoha)\
**Replies:** 1\
**Last updated:** [April 13, 2021, 10:18am UTC](https://discourse.cmake.org/t/failed-to-build-android-application-using-qt/3106 "2021-04-13T10:18:44Z")

</div>

The Cmake version I use is 3.20.0, I try to compile such a project: cmake\_minimum\_required(VERSION 3.5) project(untitled8 LANGUAGES CXX) set(CMAKE\_INCLUDE\_CURRENT\_DIR ON) set(CMAKE\_AUTOUIC ON) set(CMAKE\_AUTOMOC ON) s…

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

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