# Code

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

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

**Page:** 45

---

## [Ensure binary is created before add\_test is run](https://discourse.cmake.org/t/ensure-binary-is-created-before-add-test-is-run/6042)

<div class="topic-metadata">

**Author:** [@Anuj\_Choudhury](https://discourse.cmake.org/u/Anuj_Choudhury)\
**Replies:** 5\
**Last updated:** [July 11, 2022, 5:16pm UTC](https://discourse.cmake.org/t/ensure-binary-is-created-before-add-test-is-run/6042 "2022-07-11T17:16:49Z")

</div>

I am trying to run individual tests for Boost in CMake. a Boost test binary can be run with --list\_content option to list down all the tests inside the executable. I am using this list with CMake’s add\_test option to …

---

## [How to get cmake to show a percentage progress report?](https://discourse.cmake.org/t/how-to-get-cmake-to-show-a-percentage-progress-report/6019)

<div class="topic-metadata">

**Author:** [@ddddxie](https://discourse.cmake.org/u/ddddxie)\
**Replies:** 10\
**Last updated:** [July 11, 2022, 6:20am UTC](https://discourse.cmake.org/t/how-to-get-cmake-to-show-a-percentage-progress-report/6019 "2022-07-11T06:20:56Z")

</div>

Hi,Experts I want to know how to get cmake to show a percentage progress report? like this \[ 66%\] Building CXX object utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/DFAEmitter.cpp.o \[ 66%\] Building CXX object utils/Ta…

---

## [Iterate over results of execute\_process](https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041)

<div class="topic-metadata">

**Author:** [@Anuj\_Choudhury](https://discourse.cmake.org/u/Anuj_Choudhury)\
**Replies:** 1\
**Last updated:** [July 10, 2022, 3:25pm UTC](https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041 "2022-07-10T15:25:22Z")

</div>

How can i get the result of a bash command in a list variable ? Say I have the output of a command, run in cmake using execute\_process (this output can be 100-200 lines large): aa bb cc dd ee ff Now, I need to get th…

---

## [file(WRITE ...) behaves differently on Linux compared to Windows regarding escaped whitespaces?](https://discourse.cmake.org/t/file-write-behaves-differently-on-linux-compared-to-windows-regarding-escaped-whitespaces/6012)

<div class="topic-metadata">

**Author:** [@JohannesWilde](https://discourse.cmake.org/u/JohannesWilde)\
**Replies:** 4\
**Last updated:** [July 9, 2022, 1:16pm UTC](https://discourse.cmake.org/t/file-write-behaves-differently-on-linux-compared-to-windows-regarding-escaped-whitespaces/6012 "2022-07-09T13:16:39Z")

</div>

Hi, I wanted to automate the version-string generation from a git tag via CMake and came up with an approach very similar to the following. main.c: #include \<stdio.h\> int main() { printf("Hello World!\\n"); re…

---

## [missing libraries when use self cmake generated package](https://discourse.cmake.org/t/missing-libraries-when-use-self-cmake-generated-package/5881)

<div class="topic-metadata">

**Author:** [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)\
**Replies:** 1\
**Last updated:** [July 9, 2022, 1:05pm UTC](https://discourse.cmake.org/t/missing-libraries-when-use-self-cmake-generated-package/5881 "2022-07-09T13:05:11Z")

</div>

I have generated a package by myself, and the CMakeLists.txt looks like: ... install(TARGETS pA pB EXPORT SustaoBasic RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) install(DIRECTORY pac…

---

## [What it means? Imported target "my\_sort\_lib" includes non-existent path](https://discourse.cmake.org/t/what-it-means-imported-target-my-sort-lib-includes-non-existent-path/5850)

<div class="topic-metadata">

**Author:** [@petrasvestartas](https://discourse.cmake.org/u/petrasvestartas)\
**Replies:** 17\
**Last updated:** [July 9, 2022, 1:03pm UTC](https://discourse.cmake.org/t/what-it-means-imported-target-my-sort-lib-includes-non-existent-path/5850 "2022-07-09T13:03:34Z")

</div>

Hi, I am trying to use function find\_package for my created package which is very simple for learning purposes. This is how I create and install my own package: This is the project where I try to use find\_package met…

---

## [Copy resources to build folder](https://discourse.cmake.org/t/copy-resources-to-build-folder/1010)

<div class="topic-metadata">

**Author:** [@dfireBird](https://discourse.cmake.org/u/dfireBird)\
**Replies:** 4\
**Last updated:** [July 8, 2022, 9:01pm UTC](https://discourse.cmake.org/t/copy-resources-to-build-folder/1010 "2022-07-08T21:01:37Z")

</div>

I’m doing an OpenGL project where I mostly write shaders and have several texture files. Is there a way I can copy it to the build folder so the binary can access it?

---

## [Undefined symbols when linking application to library](https://discourse.cmake.org/t/undefined-symbols-when-linking-application-to-library/5977)

<div class="topic-metadata">

**Author:** [@mitchcurtis](https://discourse.cmake.org/u/mitchcurtis)\
**Replies:** 6\
**Last updated:** [July 5, 2022, 1:16pm UTC](https://discourse.cmake.org/t/undefined-symbols-when-linking-application-to-library/5977 "2022-07-05T13:16:01Z")

</div>

When building this project, I get linker errors: 17:28:00: Running steps for project root... 17:28:00: Starting: "/opt/homebrew/Cellar/cmake/3.23.1/bin/cmake" --build /Users/mitch/dev/cmake-test-qt\_dev\_debug\_non\_fw-Debu…

---

## [How do I remove compile options from target](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965)

<div class="topic-metadata">

**Author:** [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Replies:** 6\
**Last updated:** [July 2, 2022, 9:50pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965 "2022-07-02T21:50:32Z")

</div>

I need to send a build to a code verification service and they require it be built with certain flags. I am able to get most with target\_compile\_options but I cannot set it to “Default” like we do in the IDE which has t…

---

## [EXEC : CPack error : Cannot initialize the generator ZIP](https://discourse.cmake.org/t/exec-cpack-error-cannot-initialize-the-generator-zip/5967)

<div class="topic-metadata">

**Author:** [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Replies:** 2\
**Last updated:** [June 30, 2022, 11:46am UTC](https://discourse.cmake.org/t/exec-cpack-error-cannot-initialize-the-generator-zip/5967 "2022-06-30T11:46:14Z")

</div>

I have used the following for quite a while in my cpack :slight\_smile: SET( CPACK\_GENERATOR “NSIS” “ZIP” ) But recently I get the error in the title. The only thing I remember is updating to 3.23.1. Any know why this…

---

## [Dealing with multiple microcontrollers/toolchains in one code base](https://discourse.cmake.org/t/dealing-with-multiple-microcontrollers-toolchains-in-one-code-base/5952)

<div class="topic-metadata">

**Author:** [@itavero](https://discourse.cmake.org/u/itavero)\
**Replies:** 4\
**Last updated:** [June 30, 2022, 11:32am UTC](https://discourse.cmake.org/t/dealing-with-multiple-microcontrollers-toolchains-in-one-code-base/5952 "2022-06-30T11:32:05Z")

</div>

For a new development we are starting, we have multiple different microcontrollers on single board. We want to maintain this codebase in one Git repository and preferably prevent duplication in the CMake configuration a…

---

## [dll linking](https://discourse.cmake.org/t/dll-linking/4805)

<div class="topic-metadata">

**Author:** [@bambo09](https://discourse.cmake.org/u/bambo09)\
**Replies:** 12\
**Last updated:** [June 30, 2022, 8:28am UTC](https://discourse.cmake.org/t/dll-linking/4805 "2022-06-30T08:28:22Z")

</div>

How do i link a dll? I tried few examples from the decumentation, but completely useless, no real world examples on how to load the library… I tried to do add this in the cmakelist target\_link\_libraries(project\_name C:…

---

## [Trouble trying to link/distribute a 3rd party library as a framework for iOS](https://discourse.cmake.org/t/trouble-trying-to-link-distribute-a-3rd-party-library-as-a-framework-for-ios/5299)

<div class="topic-metadata">

**Author:** [@def-pri-pub](https://discourse.cmake.org/u/def-pri-pub)\
**Replies:** 2\
**Last updated:** [June 29, 2022, 5:49pm UTC](https://discourse.cmake.org/t/trouble-trying-to-link-distribute-a-3rd-party-library-as-a-framework-for-ios/5299 "2022-06-29T17:49:59Z")

</div>

I’m working on an app right now and I’m using Qt to build it. Android and iOS are the targets of mine. Part of my issue is that I need to use a dynamically linked 3rd party library (that uses CMake) in the app. When buil…

---

## [CMake Rebuilding all files when only one has changed](https://discourse.cmake.org/t/cmake-rebuilding-all-files-when-only-one-has-changed/947)

<div class="topic-metadata">

**Author:** [@jayatkinson](https://discourse.cmake.org/u/jayatkinson)\
**Replies:** 5\
**Last updated:** [June 29, 2022, 4:17am UTC](https://discourse.cmake.org/t/cmake-rebuilding-all-files-when-only-one-has-changed/947 "2022-06-29T04:17:48Z")

</div>

I am porting a project to CMake from plain Makefiles. There is tool used to generate header files at build time. The line in the Makefile looks like this: %.o:%.cpp foo $\< compile command So, every time a …

---

## [Add dependency to ZERO\_CHECK? \[SOLVED\]](https://discourse.cmake.org/t/add-dependency-to-zero-check-solved/5957)

<div class="topic-metadata">

**Author:** [@marco1475](https://discourse.cmake.org/u/marco1475)\
**Replies:** 2\
**Last updated:** [June 29, 2022, 1:06am UTC](https://discourse.cmake.org/t/add-dependency-to-zero-check-solved/5957 "2022-06-29T01:06:08Z")

</div>

For my project I need to create executables with different “branding” (e.g. exe file name, window title, etc.), some of which needs to be compiled in (i.e. not runtime editable). Since the branding will be modified by n…

---

## [clang-tidy does not find include \`\<iostream\>\` with \`\_\_run\_co\_compile\`](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910)

<div class="topic-metadata">

**Author:** [@gabyx](https://discourse.cmake.org/u/gabyx)\
**Replies:** 5\
**Last updated:** [June 27, 2022, 11:35pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910 "2022-06-27T23:35:17Z")

</div>

I am wondering why clang-tidy does not find includes with libc++ but does with libstdc++ when configured with CXX\_CLANG\_TIDY=clang-tidy: The compile command which works with linux-clang-libstc++-debug is: /usr/local/…

---

## [alternative to GLOB?](https://discourse.cmake.org/t/alternative-to-glob/5938)

<div class="topic-metadata">

**Author:** [@TripRichert](https://discourse.cmake.org/u/TripRichert)\
**Replies:** 2\
**Last updated:** [June 25, 2022, 5:03pm UTC](https://discourse.cmake.org/t/alternative-to-glob/5938 "2022-06-25T17:03:03Z")

</div>

I’ve commonly seen advice to avoid globbing for files because cmake won’t automatically rerun if a file is added. Typically, people recommend to hardcode the list of files into a cmake variable. This can be tedious to …

---

## [daq in snort become myself crazy this should be understand my skill but fail](https://discourse.cmake.org/t/daq-in-snort-become-myself-crazy-this-should-be-understand-my-skill-but-fail/5924)

<div class="topic-metadata">

**Author:** [@Azaretdodo](https://discourse.cmake.org/u/Azaretdodo)\
**Replies:** 1\
**Last updated:** [June 24, 2022, 6:20pm UTC](https://discourse.cmake.org/t/daq-in-snort-become-myself-crazy-this-should-be-understand-my-skill-but-fail/5924 "2022-06-24T18:20:14Z")

</div>

hello, i am not understand why i keep the errors following for fill daq in the last snort 3-1-31.0 : CMake Error at /usr/local/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:283 (message): (missing: da…

---

## [Is there a builtin method to create a target that's only run if dependent files are changed/touched?](https://discourse.cmake.org/t/is-there-a-builtin-method-to-create-a-target-thats-only-run-if-dependent-files-are-changed-touched/5927)

<div class="topic-metadata">

**Author:** [@dundargoc](https://discourse.cmake.org/u/dundargoc)\
**Replies:** 5\
**Last updated:** [June 24, 2022, 5:39pm UTC](https://discourse.cmake.org/t/is-there-a-builtin-method-to-create-a-target-thats-only-run-if-dependent-files-are-changed-touched/5927 "2022-06-24T17:39:33Z")

</div>

Hey. I looked everywhere for this and couldn’t find anything. So basically I’m looking for a way to create a target that is dependent on existing files. For example, let’s say I have a bunch of python files in my repo an…

---

## [Mistake in FetchContent documentation](https://discourse.cmake.org/t/mistake-in-fetchcontent-documentation/5916)

<div class="topic-metadata">

**Author:** [@modkin](https://discourse.cmake.org/u/modkin)\
**Replies:** 2\
**Last updated:** [June 23, 2022, 10:41pm UTC](https://discourse.cmake.org/t/mistake-in-fetchcontent-documentation/5916 "2022-06-23T22:41:23Z")

</div>

Hello everyone, it seams to me that there is a mistake in the documentation of FetchContent. In Populating Content Without Adding It To The Build FetchContent\_MakeAvailable is used. However, it should be FetchContent\_…

---

## [Cmake parallel build](https://discourse.cmake.org/t/cmake-parallel-build/1838)

<div class="topic-metadata">

**Author:** [@ProTur1](https://discourse.cmake.org/u/ProTur1)\
**Replies:** 22\
**Last updated:** [June 23, 2022, 1:05pm UTC](https://discourse.cmake.org/t/cmake-parallel-build/1838 "2022-06-23T13:05:36Z")

</div>

How do I set an option for a parallel build? My approach so far: add\_library(myLib ${SRCS} ${HDRS}) add\_custom\_command(TARGET myLib COMMAND ${CMAKE\_COMMAND} -j5}) It doesnt have any effect like this. Any other sugges…

---

## [Setting compile\_options for a AUTORCC generated file](https://discourse.cmake.org/t/setting-compile-options-for-a-autorcc-generated-file/5886)

<div class="topic-metadata">

**Author:** [@Abhishek\_Mohata](https://discourse.cmake.org/u/Abhishek_Mohata)\
**Replies:** 8\
**Last updated:** [June 23, 2022, 11:57am UTC](https://discourse.cmake.org/t/setting-compile-options-for-a-autorcc-generated-file/5886 "2022-06-23T11:57:35Z")

</div>

My Project uses Qt and hence I have set AUTORCC as ON. Because, AUTORCC is ON, the qrc files in the target sources would be picked and rcc executable would be invoked, resulting in the generation of qrc\_qml\_CMAKE\_.cpp f…

---

## [Generator expression to get the generator name?](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911)

<div class="topic-metadata">

**Author:** [@benthevining](https://discourse.cmake.org/u/benthevining)\
**Replies:** 3\
**Last updated:** [June 22, 2022, 9:12pm UTC](https://discourse.cmake.org/t/generator-expression-to-get-the-generator-name/5911 "2022-06-22T21:12:21Z")

</div>

Is there a generator expression that evaluates to the name of the CMake generator being used? If not, is there a reason why not?

---

## [CMake and CUDA 11.7](https://discourse.cmake.org/t/cmake-and-cuda-11-7/5896)

<div class="topic-metadata">

**Author:** [@Rick\_Frank](https://discourse.cmake.org/u/Rick_Frank)\
**Replies:** 5\
**Last updated:** [June 21, 2022, 3:04pm UTC](https://discourse.cmake.org/t/cmake-and-cuda-11-7/5896 "2022-06-21T15:04:06Z")

</div>

Hi, I’m trying to move older code to new environment. I’m having a hard time figuring out what the latest working way to use CMake and CUDA is My project is MainProject Subproject (cuda kernels and cpp) FindCudaTo…

---

## [Generating C# .NET6 Projects - Problems with DOTNET\_SDK](https://discourse.cmake.org/t/generating-c-net6-projects-problems-with-dotnet-sdk/5745)

<div class="topic-metadata">

**Author:** [@mattsnowboard](https://discourse.cmake.org/u/mattsnowboard)\
**Replies:** 2\
**Last updated:** [June 21, 2022, 3:55pm UTC](https://discourse.cmake.org/t/generating-c-net6-projects-problems-with-dotnet-sdk/5745 "2022-06-21T15:55:19Z")

</div>

I have a project with both C/C++ native code, and C# .NET code. We can currently generate C# projects in cmake which use the “old” style of csproj files and it works perfectly fine for .NET 4.8. E.g. set\_target\_propertie…

---

## [how to understand the PlatformName in CMake](https://discourse.cmake.org/t/how-to-understand-the-platformname-in-cmake/5867)

<div class="topic-metadata">

**Author:** [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)\
**Replies:** 6\
**Last updated:** [June 20, 2022, 6:06am UTC](https://discourse.cmake.org/t/how-to-understand-the-platformname-in-cmake/5867 "2022-06-20T06:06:25Z")

</div>

I want to generate myself package by CMake. My CMakeLists.txt is: ... set(Bin\_Root "${CMAKE\_CURRENT\_SOURCE\_DIR}/Bin/${PlatformName}") set(Lib\_Root "${CMAKE\_CURRENT\_SOURCE\_DIR}/Lib/${PlatformName}") install(TARGETS Comm…

---

## [add\_externalproject argument explanation](https://discourse.cmake.org/t/add-externalproject-argument-explanation/5888)

<div class="topic-metadata">

**Author:** [@petrasvestartas](https://discourse.cmake.org/u/petrasvestartas)\
**Replies:** 3\
**Last updated:** [June 20, 2022, 5:55am UTC](https://discourse.cmake.org/t/add-externalproject-argument-explanation/5888 "2022-06-20T05:55:21Z")

</div>

Question is about arguments inside ExternalProject\_Add function. What is the difference between: 1. SOURCE\_DIR 2. INSTALL\_DIR 3. CMAKE\_ARGS -DCMAKE\_INSTALL\_PREFIX:PATH

---

## [Building an independent watchOS app using CMake](https://discourse.cmake.org/t/building-an-independent-watchos-app-using-cmake/5885)

<div class="topic-metadata">

**Author:** [@Abhishek\_Mohata](https://discourse.cmake.org/u/Abhishek_Mohata)\
**Replies:** 2\
**Last updated:** [June 20, 2022, 4:21am UTC](https://discourse.cmake.org/t/building-an-independent-watchos-app-using-cmake/5885 "2022-06-20T04:21:50Z")

</div>

We are building an application that would be cross-platform and hence using CMake as the build system. While am able to build for iOS, macOS, tvOS etc, have not been able to build for watchOS using CMake. Right now, am l…

---

## [Automatically wrapping a static library in "whole-archive"/"no-whole-archive" when used during linking](https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883)

<div class="topic-metadata">

**Author:** [@ingolf](https://discourse.cmake.org/u/ingolf)\
**Replies:** 4\
**Last updated:** [June 19, 2022, 10:50am UTC](https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883 "2022-06-19T10:50:43Z")

</div>

Hi, what is the correct way to add some linking flags whenever a certain static library is used when linking an executable? Example: there is a static library L (providing its own public include directories and maybe…

---

## [Exporting a static data member of a class for dll using MSVC](https://discourse.cmake.org/t/exporting-a-static-data-member-of-a-class-for-dll-using-msvc/5892)

<div class="topic-metadata">

**Author:** [@ravimohan1991](https://discourse.cmake.org/u/ravimohan1991)\
**Replies:** 2\
**Last updated:** [June 18, 2022, 11:24pm UTC](https://discourse.cmake.org/t/exporting-a-static-data-member-of-a-class-for-dll-using-msvc/5892 "2022-06-18T23:24:40Z")

</div>

Since past couple of days I have been searching and experimenting with the right way to export a static data member of a class for dynamic linkage in Windows using MSVC solution generated by CMake. The CMake hierarchy i…

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

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