# Code

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

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

**Page:** 54

---

## [List variable expanded differently when passed to a command](https://discourse.cmake.org/t/list-variable-expanded-differently-when-passed-to-a-command/4377)

<div class="topic-metadata">

**Author:** [@gpanders](https://discourse.cmake.org/u/gpanders)\
**Replies:** 2\
**Last updated:** [October 31, 2021, 9:58pm UTC](https://discourse.cmake.org/t/list-variable-expanded-differently-when-passed-to-a-command/4377 "2021-10-31T21:58:54Z")

</div>

Hi all. Consider the following snippet: set(implicit\_dirs ${CMAKE\_C\_IMPLICIT\_INCLUDE\_DIRECTORIES}) message(STATUS "implicit\_dirs = ${implicit\_dirs}") add\_custom\_target(my\_custom\_target COMMAND ${CMAKE\_COMMAND} -E…

---

## [Determine flags for linking C++ standard library](https://discourse.cmake.org/t/determine-flags-for-linking-c-standard-library/4373)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 3\
**Last updated:** [October 31, 2021, 11:33am UTC](https://discourse.cmake.org/t/determine-flags-for-linking-c-standard-library/4373 "2021-10-31T11:33:53Z")

</div>

I have posted this question on StackOverflow a few days ago, but received no answer so far. I am trying to use CMake to generate a pkg-config file for a library with a C interface. This library is partially written in …

---

## [Custom command or POST\_BUILD dependent on Release configuration?](https://discourse.cmake.org/t/custom-command-or-post-build-dependent-on-release-configuration/1912)

<div class="topic-metadata">

**Author:** [@ProTur1](https://discourse.cmake.org/u/ProTur1)\
**Replies:** 4\
**Last updated:** [October 29, 2021, 3:34pm UTC](https://discourse.cmake.org/t/custom-command-or-post-build-dependent-on-release-configuration/1912 "2021-10-29T15:34:39Z")

</div>

How can I execute a custom command or POST\_BUILD dependent on VS release configuration? I want to copy an executable to another folder, only if Release in VS has been selected. Generator expressions with custom\_command…

---

## [How to add\_executable(targetB MACOSX\_BUNDLE targetB.cc targetA) ?](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482)

<div class="topic-metadata">

**Author:** [@paulrichards321](https://discourse.cmake.org/u/paulrichards321)\
**Replies:** 3\
**Last updated:** [October 29, 2021, 12:26pm UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482 "2021-10-29T12:26:03Z")

</div>

include(CPack) … set(MACOSX\_BUNDLE TRUE) set(MACOSX\_BUNDLE\_BUNDLE\_NAME targetB) set(MACOSX\_BUNDLE\_ICON\_FILE iconfile.icns) set(MACOSX\_BUNDLE\_STARTUP\_COMMAND targetB) add\_executable(targetA targetA.cc) add\_executab…

---

## [target\_compile\_options: SHELL prefix not working in generator expression](https://discourse.cmake.org/t/target-compile-options-shell-prefix-not-working-in-generator-expression/4351)

<div class="topic-metadata">

**Author:** [@PlatonCM](https://discourse.cmake.org/u/PlatonCM)\
**Replies:** 8\
**Last updated:** [October 28, 2021, 11:23am UTC](https://discourse.cmake.org/t/target-compile-options-shell-prefix-not-working-in-generator-expression/4351 "2021-10-28T11:23:47Z")

</div>

Hi, I’m setting up my first project with CMake and am struggling with compile options specific to the armasm.exe we’re using in the company. The goal is to get the following command line (stripped down) for assembly fil…

---

## [cmake: forcing build type for a specific library fails](https://discourse.cmake.org/t/cmake-forcing-build-type-for-a-specific-library-fails/4332)

<div class="topic-metadata">

**Author:** [@Serbenet](https://discourse.cmake.org/u/Serbenet)\
**Replies:** 9\
**Last updated:** [October 27, 2021, 6:01pm UTC](https://discourse.cmake.org/t/cmake-forcing-build-type-for-a-specific-library-fails/4332 "2021-10-27T18:01:35Z")

</div>

Hi, I have a c++ project made of several executables and libraries. I use cmake for the compilation. Also in debug mode, I add “\_d” as postfix for the libraries (i.e.: libfoo\_d.so). Now, one of those libraries (say lib…

---

## [add\_custom\_command() does not work in each cases but there is no error!](https://discourse.cmake.org/t/add-custom-command-does-not-work-in-each-cases-but-there-is-no-error/4338)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 5\
**Last updated:** [October 27, 2021, 2:40pm UTC](https://discourse.cmake.org/t/add-custom-command-does-not-work-in-each-cases-but-there-is-no-error/4338 "2021-10-27T14:40:05Z")

</div>

I have a CMake Project with following code snipped find\_program(DOT dot REQUIRED) find\_program( IDL\_COMPILER NAMES idl2cpp idl2cpp.sh idl2cpp.cmd HINTS $ENV{OE\_HOME}/host/$ENV{OE\_HOST\_PLATFORM}/bin REQUIRED ) # …

---

## [IMPORTED libraries have unmovable paths on LINUX](https://discourse.cmake.org/t/imported-libraries-have-unmovable-paths-on-linux/4147)

<div class="topic-metadata">

**Author:** [@jkaron](https://discourse.cmake.org/u/jkaron)\
**Replies:** 5\
**Last updated:** [October 26, 2021, 6:37am UTC](https://discourse.cmake.org/t/imported-libraries-have-unmovable-paths-on-linux/4147 "2021-10-26T06:37:17Z")

</div>

Hi Everybody. I am working on a project that has to be compiled for Windows and Linux. Also I have 2 external libraries that are part of the project: boost program\_options - this one I want to be included in the progra…

---

## [Best way to find\_package for subproject?](https://discourse.cmake.org/t/best-way-to-find-package-for-subproject/4320)

<div class="topic-metadata">

**Author:** [@Ronald](https://discourse.cmake.org/u/Ronald)\
**Replies:** 2\
**Last updated:** [October 24, 2021, 1:11am UTC](https://discourse.cmake.org/t/best-way-to-find-package-for-subproject/4320 "2021-10-24T01:11:56Z")

</div>

Project Hierarchy Main CMakeLists.txt App CMakeLists.txt LibA CMakeLists.txt Details Main CMakeLists.txt ... add\_subdirectory(LibA) add\_subdirectory(App) ... App CMakeLists.txt ... find\_package(LibA REQUIRED) ...…

---

## [iOS system framework](https://discourse.cmake.org/t/ios-system-framework/4325)

<div class="topic-metadata">

**Author:** [@sandyDaily](https://discourse.cmake.org/u/sandyDaily)\
**Replies:** 0\
**Last updated:** [October 23, 2021, 1:11am UTC](https://discourse.cmake.org/t/ios-system-framework/4325 "2021-10-23T01:11:01Z")

</div>

Hi, I’m an iOS developer，I’ve been trying to write the iOS framework in Cmake,however, when I compile, I run into iOS system libraries, like UIKit,do I need to introduce UIKit in CMakeList? Or, how do I write this CMakLl…

---

## [Depending on "all"](https://discourse.cmake.org/t/depending-on-all/4318)

<div class="topic-metadata">

**Author:** [@Braden](https://discourse.cmake.org/u/Braden)\
**Replies:** 0\
**Last updated:** [October 22, 2021, 1:52pm UTC](https://discourse.cmake.org/t/depending-on-all/4318 "2021-10-22T13:52:24Z")

</div>

I’ve created an installcheck target. Rather than having this depend on install (which would be affected by the configure-time value of CMAKE\_INSTALL\_PREFIX), it depends on an installcheck-install target that calls cmake\_…

---

## [add\_subdirectory with path outside project produces strange tmp directorys](https://discourse.cmake.org/t/add-subdirectory-with-path-outside-project-produces-strange-tmp-directorys/4309)

<div class="topic-metadata">

**Author:** [@JojoS62](https://discourse.cmake.org/u/JojoS62)\
**Replies:** 12\
**Last updated:** [October 21, 2021, 2:10pm UTC](https://discourse.cmake.org/t/add-subdirectory-with-path-outside-project-produces-strange-tmp-directorys/4309 "2021-10-21T14:10:04Z")

</div>

hello, I have some project with Mbed that uses cmake now. There I have a project structure with shared interface libs that I want to have outside my main project. That build and compiles when I use the add\_subdirectory…

---

## [Dll bundle is not correct when build with Release mode](https://discourse.cmake.org/t/dll-bundle-is-not-correct-when-build-with-release-mode/4295)

<div class="topic-metadata">

**Author:** [@1111](https://discourse.cmake.org/u/1111)\
**Replies:** 1\
**Last updated:** [October 19, 2021, 12:28pm UTC](https://discourse.cmake.org/t/dll-bundle-is-not-correct-when-build-with-release-mode/4295 "2021-10-19T12:28:31Z")

</div>

Hi, I am building my Qt project with Visual Studio Generator using the following command cmake --build . --config Release. But When I run my program, it says the uucrtbased.dll and vcruntime140d.dll were not found? So si…

---

## [Where to set CUDA\_ARCHITECTURES variable?](https://discourse.cmake.org/t/where-to-set-cuda-architectures-variable/4291)

<div class="topic-metadata">

**Author:** [@Sharmin\_Sultana\_Sheu](https://discourse.cmake.org/u/Sharmin_Sultana_Sheu)\
**Replies:** 2\
**Last updated:** [October 18, 2021, 6:41pm UTC](https://discourse.cmake.org/t/where-to-set-cuda-architectures-variable/4291 "2021-10-18T18:41:30Z")

</div>

Hi I am using CMAKE version 3.21.3 And want to set CMake CUDA\_ARCHITECTURES variables with the commands set\_property(TARGET myTarget PROPERTY CUDA\_ARCHITECTURES 35 50 72) target\_link\_libraries(FortranCInterface PUBLI…

---

## [Fail to compile ARM assembly files by CMake](https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300)

<div class="topic-metadata">

**Author:** [@Takao](https://discourse.cmake.org/u/Takao)\
**Replies:** 1\
**Last updated:** [October 18, 2021, 4:08pm UTC](https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300 "2021-10-18T16:08:21Z")

</div>

Hi, I have cross compile environment with arm embedded toolchain(gcc-arm-none-eabi-5\_4-2016q3) on Ubuntu20.04. If I try to compile ARM assembly file by cli, it works fine: \> arm-none-eabi-gcc -x assembler-with-cpp -mcp…

---

## [Link to debug or release binaries](https://discourse.cmake.org/t/link-to-debug-or-release-binaries/4280)

<div class="topic-metadata">

**Author:** [@xhustango](https://discourse.cmake.org/u/xhustango)\
**Replies:** 5\
**Last updated:** [October 18, 2021, 12:22pm UTC](https://discourse.cmake.org/t/link-to-debug-or-release-binaries/4280 "2021-10-18T12:22:01Z")

</div>

Hi there! I am building an app using CMake and wxwidgets. The issue I am facing is that I can’t compile my app in release mode because is using the debug libs. I don’t know how to set the directories to look for in diff…

---

## [Windows libraries, Find modules, and TARGET\_RUNTIME\_DLLS (re-re-revisited)](https://discourse.cmake.org/t/windows-libraries-find-modules-and-target-runtime-dlls-re-re-revisited/4286)

<div class="topic-metadata">

**Author:** [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Replies:** 4\
**Last updated:** [October 16, 2021, 9:24am UTC](https://discourse.cmake.org/t/windows-libraries-find-modules-and-target-runtime-dlls-re-re-revisited/4286 "2021-10-16T09:24:29Z")

</div>

The Windows DLL Question™ has come up numerous times before in one form or another, but it’s cast in a new light by $\<TARGET\_RUNTIME\_DLLS\>, so here’s a fresh take on it. If you’re like me (and roughly 90% of all CMake u…

---

## [Find\_package multiple times](https://discourse.cmake.org/t/find-package-multiple-times/4270)

<div class="topic-metadata">

**Author:** [@Azrael3000](https://discourse.cmake.org/u/Azrael3000)\
**Replies:** 1\
**Last updated:** [October 15, 2021, 11:41pm UTC](https://discourse.cmake.org/t/find-package-multiple-times/4270 "2021-10-15T23:41:23Z")

</div>

I have multiple shared libraries that I want to build and each of them should be linked to a different version of a static library. In my CMakeLists.txt I have a loop over all shared libraries that I want to build and f…

---

## [Register dependencies between \`all\` targets](https://discourse.cmake.org/t/register-dependencies-between-all-targets/4278)

<div class="topic-metadata">

**Author:** [@ingolf](https://discourse.cmake.org/u/ingolf)\
**Replies:** 8\
**Last updated:** [October 15, 2021, 1:54pm UTC](https://discourse.cmake.org/t/register-dependencies-between-all-targets/4278 "2021-10-15T13:54:55Z")

</div>

Hi, my project has the following hierarchy: toplevel +-foo # added with add\_subdirectory(... EXCLUDE\_FROM\_ALL) +-bar # added with add\_subdirectory(...) +-quux # added with add\_subdirectory(... EXCLUDE\_FROM\_ALL) A…

---

## [Difference between Make and Ninja when adding simple language support](https://discourse.cmake.org/t/difference-between-make-and-ninja-when-adding-simple-language-support/4271)

<div class="topic-metadata">

**Author:** [@cerna](https://discourse.cmake.org/u/cerna)\
**Replies:** 0\
**Last updated:** [October 13, 2021, 8:26pm UTC](https://discourse.cmake.org/t/difference-between-make-and-ninja-when-adding-simple-language-support/4271 "2021-10-13T20:26:44Z")

</div>

Hello, I need to add simple language support to CMake for an assembler flavour. (Assembling special firmware for on-chip peripheral hardware.) The assembling process is relatively trivial. It takes a single source file…

---

## [Running cpack after install target and install cpack results?](https://discourse.cmake.org/t/running-cpack-after-install-target-and-install-cpack-results/4253)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 5\
**Last updated:** [October 13, 2021, 8:05pm UTC](https://discourse.cmake.org/t/running-cpack-after-install-target-and-install-cpack-results/4253 "2021-10-13T20:05:34Z")

</div>

All, this is one of those myriad of “CMake post install” issues. Essentially, I’m trying to figure out how I can run cpack after I run make install and then install the bits that cpack just made into the installation di…

---

## [Passing \`option\`s through to \`find\_package\`](https://discourse.cmake.org/t/passing-option-s-through-to-find-package/4255)

<div class="topic-metadata">

**Author:** [@Barry\_Revzin](https://discourse.cmake.org/u/Barry_Revzin)\
**Replies:** 1\
**Last updated:** [October 13, 2021, 11:42am UTC](https://discourse.cmake.org/t/passing-option-s-through-to-find-package/4255 "2021-10-13T11:42:33Z")

</div>

Let’s say I have a project which wants to use spdlog, which depends on fmtlib. The main spdlog CMakeLists.txt has a bunch of options for how to configure it, including SPDLOG\_FMT\_EXTERNAL. Let’s say I: want to clone s…

---

## [Is there a CMAKE\_CXX\_COMPILER\_LAUNCHER but for the linker?](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591)

<div class="topic-metadata">

**Author:** [@Matt\_Rogers](https://discourse.cmake.org/u/Matt_Rogers)\
**Replies:** 6\
**Last updated:** [October 12, 2021, 11:10am UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591 "2021-10-12T11:10:10Z")

</div>

I’m having some trouble finding this information, so sorry if I missed something in the documentation. But I have a project with a separate compiler and linker, and they both require certain environment variables to be …

---

## [Transitive include directories](https://discourse.cmake.org/t/transitive-include-directories/4248)

<div class="topic-metadata">

**Author:** [@JoeM](https://discourse.cmake.org/u/JoeM)\
**Replies:** 3\
**Last updated:** [October 12, 2021, 1:05am UTC](https://discourse.cmake.org/t/transitive-include-directories/4248 "2021-10-12T01:05:48Z")

</div>

I’ve lost something in translation when reading this bit of documentation on Transitive Usage Requirements in cmake-buildsystem(7): Usage requirements are propagated by reading the INTERFACE\_ variants of target propert…

---

## [Library Install based on Usage](https://discourse.cmake.org/t/library-install-based-on-usage/4246)

<div class="topic-metadata">

**Author:** [@VRonin](https://discourse.cmake.org/u/VRonin)\
**Replies:** 1\
**Last updated:** [October 11, 2021, 5:32pm UTC](https://discourse.cmake.org/t/library-install-based-on-usage/4246 "2021-10-11T17:32:37Z")

</div>

Hi All, In my application I use a dynamically linked library as a git submodule (I’m open to use ExternalProject if that helps). The library, however will have it’s own install that looks something like: install(TARGET…

---

## [Order of arguments in commands](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245)

<div class="topic-metadata">

**Author:** [@Panu](https://discourse.cmake.org/u/Panu)\
**Replies:** 3\
**Last updated:** [October 11, 2021, 2:04pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245 "2021-10-11T14:04:03Z")

</div>

Should the arguments be given to commands in the same order as in command documentation? For example, there’s install command in tutorial: install(EXPORT MathFunctionsTargets FILE MathFunctionsTargets.cmake DESTINATI…

---

## [Cannot generate a safe runtime path](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 5\
**Last updated:** [October 10, 2021, 8:51pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196 "2021-10-10T20:51:16Z")

</div>

Hi, during generating I get multiple warnings “Cannot generate a safe runtime search path”, but I don’t quite understand it. CMake Warning at build-analyze/\_deps/cpr-src/cpr/CMakeLists.txt:3 (add\_library): Cannot gen…

---

## [How are duplicates resolved in the CMAKE\_MODULE\_PATH?](https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242)

<div class="topic-metadata">

**Author:** [@jspanchu](https://discourse.cmake.org/u/jspanchu)\
**Replies:** 1\
**Last updated:** [October 10, 2021, 8:50pm UTC](https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242 "2021-10-10T20:50:04Z")

</div>

What happens when CMAKE\_MODULE\_PATH has more than one module with identical file names but different contents? A naive google search for “CMAKE\_MODULE\_PATH duplicates” doesn’t show any helpful results… The documentation…

---

## [Run custom command before some project build in Superbuild](https://discourse.cmake.org/t/run-custom-command-before-some-project-build-in-superbuild/4152)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 14\
**Last updated:** [October 6, 2021, 10:28pm UTC](https://discourse.cmake.org/t/run-custom-command-before-some-project-build-in-superbuild/4152 "2021-10-06T22:28:50Z")

</div>

Hi, The schema of my project is something like: MyProject | FetchContent\_Populate(MyDep) | ExternalProject\_Add(ExternalDep\_1) Ex…

---

## [Is there DEPENDS property for custom targets?](https://discourse.cmake.org/t/is-there-depends-property-for-custom-targets/4207)

<div class="topic-metadata">

**Author:** [@Artalus](https://discourse.cmake.org/u/Artalus)\
**Replies:** 7\
**Last updated:** [October 6, 2021, 12:27pm UTC](https://discourse.cmake.org/t/is-there-depends-property-for-custom-targets/4207 "2021-10-06T12:27:30Z")

</div>

add\_custom\_target() has syntax like this: add\_custom\_target(Name \[ALL\] \[command1 \[args1...\]\] \[COMMAND command2 \[args2...\] ...\] \[DEPENDS depend depend depend ... \] The Docs say: DEP…

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

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