# Code

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

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

**Page:** 76

---

## [Cleaning policy?](https://discourse.cmake.org/t/cleaning-policy/331)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 3\
**Last updated:** [December 6, 2019, 7:59pm UTC](https://discourse.cmake.org/t/cleaning-policy/331 "2019-12-06T19:59:48Z")

</div>

I am about to introduce CMake to our organisation. A question likely to come up is how to ‘clean’ a build directory. My understanding is that CMake doesn’t offer support for ‘clean’. What is the recommendation? Should …

---

## [Running commands on all targets linked against another target](https://discourse.cmake.org/t/running-commands-on-all-targets-linked-against-another-target/326)

<div class="topic-metadata">

**Author:** [@sandercox](https://discourse.cmake.org/u/sandercox)\
**Replies:** 4\
**Last updated:** [December 6, 2019, 11:09am UTC](https://discourse.cmake.org/t/running-commands-on-all-targets-linked-against-another-target/326 "2019-12-06T11:09:32Z")

</div>

I have some binaries that are linked against some libraries most are now set to be interface libs. I’d like to add some extra postbuild commands to these targets that fix rpath stuff on mac os for instance. I can write …

---

## [target\_link\_libraries, build order and build parallelism](https://discourse.cmake.org/t/target-link-libraries-build-order-and-build-parallelism/313)

<div class="topic-metadata">

**Author:** [@rnyberg](https://discourse.cmake.org/u/rnyberg)\
**Replies:** 2\
**Last updated:** [December 5, 2019, 10:22am UTC](https://discourse.cmake.org/t/target-link-libraries-build-order-and-build-parallelism/313 "2019-12-05T10:22:06Z")

</div>

Hi CMake gurus! Given the example CMakeLists.txt file below I have a few questions. Why does building libb first build liba? As I understand it liba should just be propagated as a link time dependency to whatever actu…

---

## [file GET\_RUNTIME\_DEPENDENCIES - cannot access variables](https://discourse.cmake.org/t/file-get-runtime-dependencies-cannot-access-variables/278)

<div class="topic-metadata">

**Author:** [@tgq](https://discourse.cmake.org/u/tgq)\
**Replies:** 7\
**Last updated:** [December 2, 2019, 3:15pm UTC](https://discourse.cmake.org/t/file-get-runtime-dependencies-cannot-access-variables/278 "2019-12-02T15:15:48Z")

</div>

Hello. I am checking out this new feature but it seems like I cannot print out the dependencies. The part of my cmake script is install(CODE "file(GET\_RUNTIME\_DEPENDENCIES RESOLVED\_DEPENDENCIES\_V…

---

## [FindXXX semantic: \_FIND\_REQUIRED and \_FIND\_QUIETLY](https://discourse.cmake.org/t/findxxx-semantic-find-required-and-find-quietly/285)

<div class="topic-metadata">

**Author:** [@serghei](https://discourse.cmake.org/u/serghei)\
**Replies:** 1\
**Last updated:** [December 2, 2019, 12:54pm UTC](https://discourse.cmake.org/t/findxxx-semantic-find-required-and-find-quietly/285 "2019-12-02T12:54:31Z")

</div>

. Sometimes I face the following semantics in the findXXX modules. And to be honestly not quite understand what happens here: include(FindPackageHandleStandardArgs) set(\_pkg ${CMAKE\_FIND\_PACKAGE\_NAME) if(${\_pkg}\_FIND…

---

## [CMAKE\_C\_LINK\_EXECUTABLE not considered for MINGW32](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254)

<div class="topic-metadata">

**Author:** [@rpoisel](https://discourse.cmake.org/u/rpoisel)\
**Replies:** 3\
**Last updated:** [November 26, 2019, 8:22am UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254 "2019-11-26T08:22:29Z")

</div>

Hi, I am trying to specify the CMAKE\_C\_LINK\_EXECUTABLE and the CMAKE\_CXX\_LINK\_EXECUTABLE variables in one of my toolchain files targetting MINGW32. Any value specified for these two variables gets overwritten and there…

---

## [How to use find\_library correctly?](https://discourse.cmake.org/t/how-to-use-find-library-correctly/280)

<div class="topic-metadata">

**Author:** [@matwey](https://discourse.cmake.org/u/matwey)\
**Replies:** 3\
**Last updated:** [November 28, 2019, 2:51pm UTC](https://discourse.cmake.org/t/how-to-use-find-library-correctly/280 "2019-11-28T14:51:20Z")

</div>

Hello, I am trying to reuse existing FindCheck.cmake module in my project. However, it appears that Ubuntu, for instance, provides only static libcheck.a library in the system package. FindCheck.cmake uses find\_library …

---

## [Hard time understanding depencies/action mechanism](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290)

<div class="topic-metadata">

**Author:** [@Phi](https://discourse.cmake.org/u/Phi)\
**Replies:** 2\
**Last updated:** [December 1, 2019, 5:07pm UTC](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290 "2019-12-01T17:07:44Z")

</div>

Hi All, New to cmake, trying to migrate a big project from make to cmake. At the moment I try to understand how dependencies works. I posted this on stackoverflow with very few views and no valid answers, may be posti…

---

## [How to deal with Ninja setting CMAKE\_BUILD\_TYPE to Debug?](https://discourse.cmake.org/t/how-to-deal-with-ninja-setting-cmake-build-type-to-debug/281)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 4\
**Last updated:** [November 28, 2019, 3:20pm UTC](https://discourse.cmake.org/t/how-to-deal-with-ninja-setting-cmake-build-type-to-debug/281 "2019-11-28T15:20:55Z")

</div>

I am running CMake 3.14.5 on Windows with Ninja and MSVC compiler. I am also building the same project on Linux using Ninja. As suggested by CMake and the Default Build Type I set the build type to Release if it has not…

---

## [How does CMAKE\_VS\_WINDOWS\_TARGET\_PLATFORM\_VERSION work?](https://discourse.cmake.org/t/how-does-cmake-vs-windows-target-platform-version-work/260)

<div class="topic-metadata">

**Author:** [@djspringate](https://discourse.cmake.org/u/djspringate)\
**Replies:** 4\
**Last updated:** [November 26, 2019, 6:12pm UTC](https://discourse.cmake.org/t/how-does-cmake-vs-windows-target-platform-version-work/260 "2019-11-26T18:12:06Z")

</div>

CMAKE\_VS\_WINDOWS\_TARGET\_PLATFORM\_VERSION I’m running Windows 10 Home 1903 (OS Build 18362.46). My C:\\Program Files (x86)\\Windows Kits\\10\\Lib folder contains: 10.0.16299.0 10.0.17134.0 10.0.17763.0 No matter what I …

---

## [FindGTest on windows with debug build](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239)

<div class="topic-metadata">

**Author:** [@smallzzy](https://discourse.cmake.org/u/smallzzy)\
**Replies:** 2\
**Last updated:** [November 22, 2019, 11:43pm UTC](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239 "2019-11-22T23:43:15Z")

</div>

I have built the googletest lib on windows with debug mode. It will generate gtestd.lib and gtest\_maind.lib. But find\_package(GTest) will fail to find them because of the suffix “d”. I think the problem lies in the Fi…

---

## [Generate lots of files and folder @ build-time](https://discourse.cmake.org/t/generate-lots-of-files-and-folder-build-time/226)

<div class="topic-metadata">

**Author:** [@Milosz\_Walter](https://discourse.cmake.org/u/Milosz_Walter)\
**Replies:** 2\
**Last updated:** [November 20, 2019, 7:53am UTC](https://discourse.cmake.org/t/generate-lots-of-files-and-folder-build-time/226 "2019-11-20T07:53:45Z")

</div>

Hi All, I’m currently refactoring an old CMake infrastructure which used to generate huge amount of source folders and source files @cmake-config step using several different scripts. I have to move them into the buil…

---

## [Can you combine FetchContent and ExternalProject?](https://discourse.cmake.org/t/can-you-combine-fetchcontent-and-externalproject/228)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 2\
**Last updated:** [November 19, 2019, 5:57pm UTC](https://discourse.cmake.org/t/can-you-combine-fetchcontent-and-externalproject/228 "2019-11-19T17:57:21Z")

</div>

A query for the experts. I’m trying to transition building a set of base libraries currently done with GNU Make to CMake. Now, I’m having fairly good luck with ExternalProject\_Add, but I have only one issue with that: do…

---

## [Project variants?](https://discourse.cmake.org/t/project-variants/205)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 10\
**Last updated:** [November 19, 2019, 10:26am UTC](https://discourse.cmake.org/t/project-variants/205 "2019-11-19T10:26:46Z")

</div>

Hi, I’ve just created my first full-scale CMake project, but I have a lot to learn. My project builds an executable and a set of shared libraries. The build of each shared library is enabled by a CMake option. I’m now …

---

## [How do I add depencies on header file to custom target](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218)

<div class="topic-metadata">

**Author:** [@nickez](https://discourse.cmake.org/u/nickez)\
**Replies:** 2\
**Last updated:** [November 18, 2019, 8:11pm UTC](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218 "2019-11-18T20:11:39Z")

</div>

Hey, How do I add a dependency of a header file to a custom target? Basically I have a header file that contains a few header files. And I want to add all the transitive dependencies to a custom target. It seems like i…

---

## [Using CMake for framework with main() in dynamic library](https://discourse.cmake.org/t/using-cmake-for-framework-with-main-in-dynamic-library/187)

<div class="topic-metadata">

**Author:** [@eof](https://discourse.cmake.org/u/eof)\
**Replies:** 2\
**Last updated:** [November 15, 2019, 6:52pm UTC](https://discourse.cmake.org/t/using-cmake-for-framework-with-main-in-dynamic-library/187 "2019-11-15T18:52:36Z")

</div>

I’m building a framework that needs to use CUDA internally, which is currently annoyingly complicated to use with Bazel, which is the build system I’m very familiar with. For this reason as well as wider compatibility, I…

---

## [Ninja generator, add\_custom\_command and conditional statements](https://discourse.cmake.org/t/ninja-generator-add-custom-command-and-conditional-statements/200)

<div class="topic-metadata">

**Author:** [@UmberGryphon](https://discourse.cmake.org/u/UmberGryphon)\
**Replies:** 6\
**Last updated:** [November 15, 2019, 1:32pm UTC](https://discourse.cmake.org/t/ninja-generator-add-custom-command-and-conditional-statements/200 "2019-11-15T13:32:22Z")

</div>

I am trying to create a command that will copy a data directory from my source directory to my build directory so that it will be grabbed when I package up a build into a zip file. For Windows, my custom command looks l…

---

## [How to specify build output directory path?](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 2\
**Last updated:** [November 14, 2019, 11:28am UTC](https://discourse.cmake.org/t/how-to-specify-build-output-directory-path/202 "2019-11-14T11:28:34Z")

</div>

(Copied from mail list where it is currently unanswered) Hi I am rather confused about how to specify the output directory. I am working on Windows with the Ninja generator and Microsoft toolset. My default build type …

---

## [Mapping CMAKE\_BUILD\_TYPE and CMAKE\_CONFIGURATION\_TYPES between project subdirectories](https://discourse.cmake.org/t/mapping-cmake-build-type-and-cmake-configuration-types-between-project-subdirectories/192)

<div class="topic-metadata">

**Author:** [@phcerdan](https://discourse.cmake.org/u/phcerdan)\
**Replies:** 6\
**Last updated:** [November 14, 2019, 10:53am UTC](https://discourse.cmake.org/t/mapping-cmake-build-type-and-cmake-configuration-types-between-project-subdirectories/192 "2019-11-14T10:53:58Z")

</div>

Better to explain with a use case: ProjectThird uses non-standard CMAKE\_CONFIGURATION\_TYPES, ie: checked, release I want to include ProjectThird into my ProjectOwn, however ProjectOwn has the standard CMAKE\_CONFIGURATI…

---

## [Using generator expression with add\_library](https://discourse.cmake.org/t/using-generator-expression-with-add-library/156)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 2\
**Last updated:** [November 14, 2019, 8:57am UTC](https://discourse.cmake.org/t/using-generator-expression-with-add-library/156 "2019-11-14T08:57:17Z")

</div>

I want to build a shared library for Linux and a static library for Windows. So I have tried: set (\_star\_lib\_name "StdStars") add\_library(${\_star\_lib\_name} $\<$\<CXX\_COMPILER\_ID:GNU\>:SHARED\> …

---

## [Passing escaped strings from macros to functions](https://discourse.cmake.org/t/passing-escaped-strings-from-macros-to-functions/196)

<div class="topic-metadata">

**Author:** [@alcroito](https://discourse.cmake.org/u/alcroito)\
**Replies:** 4\
**Last updated:** [November 13, 2019, 6:46pm UTC](https://discourse.cmake.org/t/passing-escaped-strings-from-macros-to-functions/196 "2019-11-13T18:46:37Z")

</div>

Hi, The following project: cmake\_minimum\_required(VERSION 3.15) project(test\_quoting\_macro\_and\_function) function(my\_func) message("func ARGV: ${ARGV}") endfunction() macro(my\_macro) message("macro ARGV: ${…

---

## [Overwriting option flags CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY, CMAKE\_LIBRARY\_OUTPUT\_DIRECTORY and CMAKE\_ARCHIVE\_OUTPUT\_DIRECTORY](https://discourse.cmake.org/t/overwriting-option-flags-cmake-runtime-output-directory-cmake-library-output-directory-and-cmake-archive-output-directory/194)

<div class="topic-metadata">

**Author:** [@danbr](https://discourse.cmake.org/u/danbr)\
**Replies:** 2\
**Last updated:** [November 13, 2019, 3:33pm UTC](https://discourse.cmake.org/t/overwriting-option-flags-cmake-runtime-output-directory-cmake-library-output-directory-and-cmake-archive-output-directory/194 "2019-11-13T15:33:47Z")

</div>

Hello! I have the following use case: Lets say the project’s top-level CMakeLists.txt file contains the following lines: set(CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY, \[some-path\]) set(CMAKE\_RUNTIME\_LIBRARY\_DIRECTORY, \[some-pat…

---

## [How is target name propogated to external projects?](https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186)

<div class="topic-metadata">

**Author:** [@oscarh](https://discourse.cmake.org/u/oscarh)\
**Replies:** 1\
**Last updated:** [November 12, 2019, 1:06pm UTC](https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186 "2019-11-12T13:06:28Z")

</div>

I don’t see a way to specify the target to build when calling ExternalProject\_Add (Correct me if I’ve missed it). So how does the external project know what target to build when I run “cmake --build” on the top-most proj…

---

## [Linking tests for an INTERFACE library](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185)

<div class="topic-metadata">

**Author:** [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Replies:** 2\
**Last updated:** [November 12, 2019, 8:59am UTC](https://discourse.cmake.org/t/linking-tests-for-an-interface-library/185 "2019-11-12T08:59:21Z")

</div>

I am writing a header-only library - which I believe is best done using an INTERFACE target (there is nothing to be built after all). The library does have some dependencies, however, which I’d like to be visible from th…

---

## [Generate dependency on external projects](https://discourse.cmake.org/t/generate-dependency-on-external-projects/139)

<div class="topic-metadata">

**Author:** [@oscarh](https://discourse.cmake.org/u/oscarh)\
**Replies:** 3\
**Last updated:** [November 10, 2019, 8:08pm UTC](https://discourse.cmake.org/t/generate-dependency-on-external-projects/139 "2019-11-10T20:08:40Z")

</div>

I’m trying to use cmake for cross-compiling. My project also needs a home-made tool to compile target code. So building target code depends on the external tool. I know we can use “export” command to generate a file for…

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