# Code

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

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

**Page:** 35

---

## [How to connect custom command to a target (add\_library) in a parent directory](https://discourse.cmake.org/t/how-to-connect-custom-command-to-a-target-add-library-in-a-parent-directory/8073)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 12\
**Last updated:** [May 15, 2023, 12:06am UTC](https://discourse.cmake.org/t/how-to-connect-custom-command-to-a-target-add-library-in-a-parent-directory/8073 "2023-05-15T00:06:17Z")

</div>

Hi all, I have a few add\_custom\_commands that generate files (e.g. via flex\_target). Those files are used as input by an add\_library command. The CMake documentation is quite clear in that, for the add\_custom\_command ma…

---

## [CMake does not run moc for a Q\_NAMESPACE in a shared library](https://discourse.cmake.org/t/cmake-does-not-run-moc-for-a-q-namespace-in-a-shared-library/8090)

<div class="topic-metadata">

**Author:** [@AAA](https://discourse.cmake.org/u/AAA)\
**Replies:** 9\
**Last updated:** [May 13, 2023, 10:51pm UTC](https://discourse.cmake.org/t/cmake-does-not-run-moc-for-a-q-namespace-in-a-shared-library/8090 "2023-05-13T22:51:25Z")

</div>

I’m trying to register a namespace in QML from a shared library, but the compilation fails with an unresolved external symbol error: failed (exit code 1120) with the following output: main.cpp.obj : error LNK2019: unres…

---

## [Tutorial Step2](https://discourse.cmake.org/t/tutorial-step2/8094)

<div class="topic-metadata">

**Author:** [@HardoMX](https://discourse.cmake.org/u/HardoMX)\
**Replies:** 4\
**Last updated:** [May 11, 2023, 1:19pm UTC](https://discourse.cmake.org/t/tutorial-step2/8094 "2023-05-11T13:19:44Z")

</div>

Hi everyone, I have just started learnign CMake throught the tutorial. However, I have kinda gotten stuck at step2. This is because the instructions have a TODO instruction, that is completely DIFFERENT from that of th…

---

## [How to tell CMake on windows to use the compiler to call the linker](https://discourse.cmake.org/t/how-to-tell-cmake-on-windows-to-use-the-compiler-to-call-the-linker/8086)

<div class="topic-metadata">

**Author:** [@Febbe](https://discourse.cmake.org/u/Febbe)\
**Replies:** 2\
**Last updated:** [May 10, 2023, 3:39pm UTC](https://discourse.cmake.org/t/how-to-tell-cmake-on-windows-to-use-the-compiler-to-call-the-linker/8086 "2023-05-10T15:39:51Z")

</div>

I have a Toolchain file, which sets my preferred compiler to clang-cl and the linker to lld-link But, when I want to use -fsanitize=address, lld-link does not know the correct location of the sanitzer runtime library. c…

---

## [Differences in set\_property vs set\_tests\_properties for discovered gtest tests](https://discourse.cmake.org/t/differences-in-set-property-vs-set-tests-properties-for-discovered-gtest-tests/8080)

<div class="topic-metadata">

**Author:** [@benschreiber](https://discourse.cmake.org/u/benschreiber)\
**Replies:** 2\
**Last updated:** [May 10, 2023, 11:00am UTC](https://discourse.cmake.org/t/differences-in-set-property-vs-set-tests-properties-for-discovered-gtest-tests/8080 "2023-05-10T11:00:21Z")

</div>

My project builds a gtest binary. I have a set of test lists - text files of test names. If a test name is in list foo, I want to add label foo to that discovered test. I can do this by adding a CTest script to TEST\_INCL…

---

## [CMake C# WPF outputType is "Exe", this is console application](https://discourse.cmake.org/t/cmake-c-wpf-outputtype-is-exe-this-is-console-application/8076)

<div class="topic-metadata">

**Author:** [@Perijahh](https://discourse.cmake.org/u/Perijahh)\
**Replies:** 1\
**Last updated:** [May 9, 2023, 2:12pm UTC](https://discourse.cmake.org/t/cmake-c-wpf-outputtype-is-exe-this-is-console-application/8076 "2023-05-09T14:12:25Z")

</div>

Hi, I have a CMake project with C# and C++ targets. It’s similar to this example here: If you change the .net framework to 4.8 by adding this before the WPF executable is added: set(CMAKE\_DOTNET\_SDK “Microsoft.NET.S…

---

## [Skipping compiler detection for a custom toolchain](https://discourse.cmake.org/t/skipping-compiler-detection-for-a-custom-toolchain/8016)

<div class="topic-metadata">

**Author:** [@Zachary\_Turner](https://discourse.cmake.org/u/Zachary_Turner)\
**Replies:** 8\
**Last updated:** [May 3, 2023, 8:46am UTC](https://discourse.cmake.org/t/skipping-compiler-detection-for-a-custom-toolchain/8016 "2023-05-03T08:46:34Z")

</div>

I’m trying to write a toolchain file for a custom C / C++ toolchain. I’ve tried doing this in my toolchain file: set(CMAKE\_C\_COMPILER /path/to/c/compiler) set(CMAKE\_CXX\_COMPILER /path/to/cxx/compiler) set(…

---

## [public\_dependencies target property?](https://discourse.cmake.org/t/public-dependencies-target-property/8024)

<div class="topic-metadata">

**Author:** [@marksibly](https://discourse.cmake.org/u/marksibly)\
**Replies:** 2\
**Last updated:** [May 3, 2023, 2:39am UTC](https://discourse.cmake.org/t/public-dependencies-target-property/8024 "2023-05-03T02:39:36Z")

</div>

Hi, I’m trying to make sense of this cmake code in the probably vain hope of cleanly it up a bit: The problem is, I can’t find ‘public\_dependencies’ in the cmake docs here: https://cmake.org/cmake/help/latest/manual…

---

## [add a sub directory that is not visible in current directory](https://discourse.cmake.org/t/add-a-sub-directory-that-is-not-visible-in-current-directory/8034)

<div class="topic-metadata">

**Author:** [@hamidrezamaddah](https://discourse.cmake.org/u/hamidrezamaddah)\
**Replies:** 1\
**Last updated:** [May 2, 2023, 1:00pm UTC](https://discourse.cmake.org/t/add-a-sub-directory-that-is-not-visible-in-current-directory/8034 "2023-05-02T13:00:13Z")

</div>

how to add a directory with add\_subdirectory that is not visible in current directory. I don’t want to use absolute address

---

## [file(STRINGS ...) with empty filename does not fail](https://discourse.cmake.org/t/file-strings-with-empty-filename-does-not-fail/8027)

<div class="topic-metadata">

**Author:** [@georg](https://discourse.cmake.org/u/georg)\
**Replies:** 3\
**Last updated:** [May 1, 2023, 8:49pm UTC](https://discourse.cmake.org/t/file-strings-with-empty-filename-does-not-fail/8027 "2023-05-01T20:49:23Z")

</div>

Recently I was hunting down an issue related to a call to file(STRINGS ...) until I realized that I mispelled a variable name: file(STRINGS "${mispelledVarName}" content) As mispelledVarName is not a valid existing var…

---

## [How to compile a storyboard file with dependency tracking](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020)

<div class="topic-metadata">

**Author:** [@TellowKrinkle](https://discourse.cmake.org/u/TellowKrinkle)\
**Replies:** 2\
**Last updated:** [April 30, 2023, 3:42am UTC](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020 "2023-04-30T03:42:58Z")

</div>

I have a macOS bundle target, and would like to compile a Main.storyboard file and have it installed to Target.app/Contents/Resources/Main.storyboardc. Normally for similar compile-and-copy actions, I’d do this: set(in…

---

## [How to tell FetchContent to keep archive directory structure](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012)

<div class="topic-metadata">

**Author:** [@r4stered](https://discourse.cmake.org/u/r4stered)\
**Replies:** 2\
**Last updated:** [April 29, 2023, 11:58am UTC](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012 "2023-04-29T11:58:54Z")

</div>

Hello, I am downloading some header files from a remote URL and unzipping them using FetchContent. This works as expected, except for the fact that the zip files directory structure isn’t being kept the same. For examp…

---

## [\`add\_compile\_options\` isn't adding options that start with \`-l\`](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925)

<div class="topic-metadata">

**Author:** [@Jack](https://discourse.cmake.org/u/Jack)\
**Replies:** 6\
**Last updated:** [April 29, 2023, 12:14am UTC](https://discourse.cmake.org/t/add-compile-options-isnt-adding-options-that-start-with-l/7925 "2023-04-29T00:14:12Z")

</div>

Hi all, I’m attempting to modify a CMake file that is used to build for many platforms. The platform that I am specifically targeting to change is GHS (Green Hills Software). So I modified this: add\_compile\_o…

---

## [Cannot rebuild UWP executables that use custom app manifest](https://discourse.cmake.org/t/cannot-rebuild-uwp-executables-that-use-custom-app-manifest/7984)

<div class="topic-metadata">

**Author:** [@amaarten](https://discourse.cmake.org/u/amaarten)\
**Replies:** 0\
**Last updated:** [April 25, 2023, 8:19pm UTC](https://discourse.cmake.org/t/cannot-rebuild-uwp-executables-that-use-custom-app-manifest/7984 "2023-04-25T20:19:22Z")

</div>

Consider the following CMake project that builds 2 executables with a custom UWP manifest: set(CMAKE\_SYSTEM\_NAME "WindowsStore") set(CMAKE\_SYSTEM\_VERSION "10.0") cmake\_minimum\_required(VERSION 3.20) project(cmake\_uwp C…

---

## [Building multiple WinRT executables with custom appxmanifests in one cmake script fails](https://discourse.cmake.org/t/building-multiple-winrt-executables-with-custom-appxmanifests-in-one-cmake-script-fails/7936)

<div class="topic-metadata">

**Author:** [@amaarten](https://discourse.cmake.org/u/amaarten)\
**Replies:** 1\
**Last updated:** [April 25, 2023, 8:08pm UTC](https://discourse.cmake.org/t/building-multiple-winrt-executables-with-custom-appxmanifests-in-one-cmake-script-fails/7936 "2023-04-25T20:08:23Z")

</div>

Building a project that builds multiple UWP executables with all having a custom manifest fails. Consider this cmake project that creates multiple executables, all having custom app manifests. Configuring and building …

---

## [Linking cufft\_static with a CXX target](https://discourse.cmake.org/t/linking-cufft-static-with-a-cxx-target/7946)

<div class="topic-metadata">

**Author:** [@pauleonix](https://discourse.cmake.org/u/pauleonix)\
**Replies:** 5\
**Last updated:** [April 24, 2023, 5:40pm UTC](https://discourse.cmake.org/t/linking-cufft-static-with-a-cxx-target/7946 "2023-04-24T17:40:50Z")

</div>

The cuFFT/1d\_c2c sample by Nvidia provides a CMakeLists.txt which links CUDA::cufft. Modifying it to link against CUDA::cufft\_static causes a lot of linking issues. The cuFFT docs provide some guidance here, so I modifie…

---

## [How to edit rpath flag format for linking library](https://discourse.cmake.org/t/how-to-edit-rpath-flag-format-for-linking-library/7896)

<div class="topic-metadata">

**Author:** [@agustin-vaca](https://discourse.cmake.org/u/agustin-vaca)\
**Replies:** 3\
**Last updated:** [April 24, 2023, 5:20pm UTC](https://discourse.cmake.org/t/how-to-edit-rpath-flag-format-for-linking-library/7896 "2023-04-24T17:20:17Z")

</div>

I’m building a project that uses the CUDA Runtime library, as well as some tests for the project using CTest. Here is an example to illustrate my problem. Directory structure: Dir/ ├── CMakeLists.txt ├── main.c ├── mai…

---

## [FetchContent\_Populate not working as expected (?)](https://discourse.cmake.org/t/fetchcontent-populate-not-working-as-expected/7948)

<div class="topic-metadata">

**Author:** [@TimONT](https://discourse.cmake.org/u/TimONT)\
**Replies:** 4\
**Last updated:** [April 24, 2023, 4:01pm UTC](https://discourse.cmake.org/t/fetchcontent-populate-not-working-as-expected/7948 "2023-04-24T16:01:17Z")

</div>

Hello, I’m looking for some help with FetchContent\_Populate. I’m not sure if this is an issue with my understanding of the docs or with the tool. I want to use Populate to pull and extract a .tar.gz archive from our int…

---

## [compiling on AIX 7.1](https://discourse.cmake.org/t/compiling-on-aix-7-1/7955)

<div class="topic-metadata">

**Author:** [@cristian](https://discourse.cmake.org/u/cristian)\
**Replies:** 1\
**Last updated:** [April 24, 2023, 9:52am UTC](https://discourse.cmake.org/t/compiling-on-aix-7-1/7955 "2023-04-24T09:52:13Z")

</div>

I am compiling on AIX7.1 with cmake 3.16 and receive the following error when linking: collect2: fatal error lib… not a COFF file Compiler is gcc 8.3 Can anyone please give me a hint ? I must add that here are used s…

---

## [Build with separate src, include and build subdirectories](https://discourse.cmake.org/t/build-with-separate-src-include-and-build-subdirectories/7961)

<div class="topic-metadata">

**Author:** [@timie\_milie](https://discourse.cmake.org/u/timie_milie)\
**Replies:** 1\
**Last updated:** [April 24, 2023, 6:54am UTC](https://discourse.cmake.org/t/build-with-separate-src-include-and-build-subdirectories/7961 "2023-04-24T06:54:22Z")

</div>

Hi I’d like to create a CMake managed project with the following example directory structure: root - mainly empty, perhaps just a cmaklistfiles.txt file root/src/main.cpp root/include/main.hpp root/build/ Where root…

---

## [CPack : automatically offer user to install RPM dependencies ?](https://discourse.cmake.org/t/cpack-automatically-offer-user-to-install-rpm-dependencies/7847)

<div class="topic-metadata">

**Author:** [@Nicholas\_Yue](https://discourse.cmake.org/u/Nicholas_Yue)\
**Replies:** 2\
**Last updated:** [April 24, 2023, 4:57am UTC](https://discourse.cmake.org/t/cpack-automatically-offer-user-to-install-rpm-dependencies/7847 "2023-04-24T04:57:47Z")

</div>

I set the following set(CPACK\_RPM\_PACKAGE\_REQUIRES "boost\_filesystem,boost\_graph,boost\_log,boost\_log\_setup,boost\_serialization,boost\_unit\_test\_framework,cmake-filesystem") set(CPACK\_RPM\_PACKAGE\_REQUIRES\_PRE "boost\_files…

---

## [IN\_LIST unexpected behavior when used with file sets?](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857)

<div class="topic-metadata">

**Author:** [@dsterk-x](https://discourse.cmake.org/u/dsterk-x)\
**Replies:** 4\
**Last updated:** [April 24, 2023, 4:46am UTC](https://discourse.cmake.org/t/in-list-unexpected-behavior-when-used-with-file-sets/7857 "2023-04-24T04:46:48Z")

</div>

I tried to work with file sets and the IN\_LIST generator expression. My code looks like in the listing below. cmake\_minimum\_required(VERSION 3.24) set(TARGET\_NAME alice) add\_library(${TARGET\_NAME} src/alice.c ) ta…

---

## [CMakeDetermineCompilerABI.cmake removes any command line provided -D values before testing the compiler](https://discourse.cmake.org/t/cmakedeterminecompilerabi-cmake-removes-any-command-line-provided-d-values-before-testing-the-compiler/7841)

<div class="topic-metadata">

**Author:** [@Barry\_Smith](https://discourse.cmake.org/u/Barry_Smith)\
**Replies:** 1\
**Last updated:** [April 24, 2023, 4:30am UTC](https://discourse.cmake.org/t/cmakedeterminecompilerabi-cmake-removes-any-command-line-provided-d-values-before-testing-the-compiler/7841 "2023-04-24T04:30:02Z")

</div>

It appears CMakeDetermineCompilerABI.cmake when it runs the compiler starts with a clean slate. That is it sets set(CMAKE\_FLAGS ) set(COMPILE\_DEFINITIONS ) and then sets a very limited set of arguments that it runs es…

---

## [cmake getting confused on cuda version](https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835)

<div class="topic-metadata">

**Author:** [@rick](https://discourse.cmake.org/u/rick)\
**Replies:** 1\
**Last updated:** [April 24, 2023, 4:25am UTC](https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835 "2023-04-24T04:25:43Z")

</div>

I have the following toolchain… CMake(c++)(3.26.1) → OpenCV(4.6.0) → CudaToolkit(11.7) all on Ubuntu 22.04. when I run cmake on my CMakeList.txt I get the following error… CMake Error at /usr/share/cmake-3.22/Modules/…

---

## [How can i install the "libpng library" that is mentioned in the picture ?](https://discourse.cmake.org/t/how-can-i-install-the-libpng-library-that-is-mentioned-in-the-picture/7818)

<div class="topic-metadata">

**Author:** [@Fierce002](https://discourse.cmake.org/u/Fierce002)\
**Replies:** 1\
**Last updated:** [April 24, 2023, 4:13am UTC](https://discourse.cmake.org/t/how-can-i-install-the-libpng-library-that-is-mentioned-in-the-picture/7818 "2023-04-24T04:13:47Z")

</div>

---

## [Folder structurefor tests in project and in library](https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732)

<div class="topic-metadata">

**Author:** [@Bertrand\_Thelen](https://discourse.cmake.org/u/Bertrand_Thelen)\
**Replies:** 1\
**Last updated:** [April 21, 2023, 11:58pm UTC](https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732 "2023-04-21T23:58:51Z")

</div>

Hi, I’m rather new to cmake and I struggle a bit with my folders structure The project is cross-compiled to arm but the tests runs on the host. I don’t think that the multi-arch setup is relevant for this question but …

---

## [Find subdependency built / installed with execute\_command](https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 1\
**Last updated:** [April 20, 2023, 11:29pm UTC](https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903 "2023-04-20T23:29:26Z")

</div>

I use the library HERE Data SDK for C++ which has leveldb as a dependency. This library is (for some reasons) not pulled in via FetchContent / GitSubmodule + add\_subdirectory, but via some execute\_process commands: If…

---

## [How to completely ignore BUILD\_INTERFACE libraries in installation?](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806)

<div class="topic-metadata">

**Author:** [@gccore](https://discourse.cmake.org/u/gccore)\
**Replies:** 3\
**Last updated:** [April 20, 2023, 12:45am UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806 "2023-04-20T00:45:08Z")

</div>

Through that, I link private libraries with BUILD\_INTERFACE genexpr and they wouldn’t be in the exported targets, but the libraries’ linked libraries will be and unfortunately when we run the install rule they will be in…

---

## [Where are the exercise files?](https://discourse.cmake.org/t/where-are-the-exercise-files/7299)

<div class="topic-metadata">

**Author:** [@parrst](https://discourse.cmake.org/u/parrst)\
**Replies:** 1\
**Last updated:** [January 22, 2023, 12:24am UTC](https://discourse.cmake.org/t/where-are-the-exercise-files/7299 "2023-01-22T00:24:23Z")

</div>

Okay trying to learn how to program a Raspberry Pico and now trying to learn how CMake works. I was shown to the documentation section and am going through the tutorial and it mentions files in the Help/guide/tutorial/S…

---

## [set(CMAKE\_CXX\_STANDARD) should set /Zc:\_\_cplusplus for MSVC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876)

<div class="topic-metadata">

**Author:** [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)\
**Replies:** 2\
**Last updated:** [April 17, 2023, 5:53pm UTC](https://discourse.cmake.org/t/set-cmake-cxx-standard-should-set-zc-cplusplus-for-msvc/1876 "2023-04-17T17:53:33Z")

</div>

It appears that doing (say) set(CMAKE\_CXX\_STANDARD 17) when targeting MSVC will set the /std:c++17 flag, but not (also) the MS-specific /Zc:\_\_cplusplus flag; this is unfortunate, because MSVC explicitly sets \_\_cplusplus …

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

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