# Code

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

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

**Page:** 12

---

## [How I add a test that has multiple commands](https://discourse.cmake.org/t/how-i-add-a-test-that-has-multiple-commands/13576)

<div class="topic-metadata">

**Author:** [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)\
**Replies:** 3\
**Last updated:** [February 15, 2025, 5:30pm UTC](https://discourse.cmake.org/t/how-i-add-a-test-that-has-multiple-commands/13576 "2025-02-15T17:30:02Z")

</div>

Sometimes you want to run multiple commands as part of a test. For instance, I wanted to: Run my program with command-line arguments to generate an image Run a program to compare the generated image with a reference i…

---

## [Operating on Target after it's built to modify based on input file](https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575)

<div class="topic-metadata">

**Author:** [@jcurl](https://discourse.cmake.org/u/jcurl)\
**Replies:** 4\
**Last updated:** [February 15, 2025, 5:48am UTC](https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575 "2025-02-15T05:48:33Z")

</div>

After building my binary, I need to run a post processing script on the binary, which effectively copies an input into the ELF object. Under QNX, this is the “usemsg” command. The input is the target and a text file, th…

---

## [Need help structuring project with multiple targets that share \`main\`](https://discourse.cmake.org/t/need-help-structuring-project-with-multiple-targets-that-share-main/13555)

<div class="topic-metadata">

**Author:** [@ZadenRB](https://discourse.cmake.org/u/ZadenRB)\
**Replies:** 2\
**Last updated:** [February 14, 2025, 5:17pm UTC](https://discourse.cmake.org/t/need-help-structuring-project-with-multiple-targets-that-share-main/13555 "2025-02-14T17:17:40Z")

</div>

Hi all, I’m struggling with the correct way to structure my project using CMake. I have a large chunk of shared code which includes the entrypoint for all targets. The main function, as well as other portions of the sha…

---

## [Compiler options for code coverage](https://discourse.cmake.org/t/compiler-options-for-code-coverage/13175)

<div class="topic-metadata">

**Author:** [@Bidski](https://discourse.cmake.org/u/Bidski)\
**Replies:** 1\
**Last updated:** [February 7, 2025, 5:59am UTC](https://discourse.cmake.org/t/compiler-options-for-code-coverage/13175 "2025-02-07T05:59:05Z")

</div>

My GCC compiler version (actually the QNX q++ compiler) requires me to specify the following command line arguments to generate code coverage metrics -ftest-coverage -fprofile-arcs -nopipe -Wc,-auxbase-strip,$@ The fir…

---

## [Adding a library to a library](https://discourse.cmake.org/t/adding-a-library-to-a-library/13547)

<div class="topic-metadata">

**Author:** [@rsalz](https://discourse.cmake.org/u/rsalz)\
**Replies:** 2\
**Last updated:** [February 6, 2025, 11:25pm UTC](https://discourse.cmake.org/t/adding-a-library-to-a-library/13547 "2025-02-06T23:25:43Z")

</div>

CMake newbie here. I have a library, add\_library(crypto... that needs to incorporate another library add\_library(defprov ... In Unix I can just add libdefprov.a to the $(CC) line. How do I write that in cmake?

---

## [Persuading file(DOWNLOAD) to do best-effort for ssl revoke](https://discourse.cmake.org/t/persuading-file-download-to-do-best-effort-for-ssl-revoke/13539)

<div class="topic-metadata">

**Author:** [@brewmook](https://discourse.cmake.org/u/brewmook)\
**Replies:** 3\
**Last updated:** [February 5, 2025, 6:32pm UTC](https://discourse.cmake.org/t/persuading-file-download-to-do-best-effort-for-ssl-revoke/13539 "2025-02-05T18:32:26Z")

</div>

Hi, The embedded libcurl seems to ignore my .curlrc. I’ve tried try setting CURLRC or CURL\_HOME env vars in an effort to persuade it, but to no avail. I’m trying to get it to do ssl-revoke-best-effort to work around a …

---

## [Modify default link flag "subsystem"](https://discourse.cmake.org/t/modify-default-link-flag-subsystem/13525)

<div class="topic-metadata">

**Author:** [@Zohar](https://discourse.cmake.org/u/Zohar)\
**Replies:** 4\
**Last updated:** [February 4, 2025, 10:50am UTC](https://discourse.cmake.org/t/modify-default-link-flag-subsystem/13525 "2025-02-04T10:50:35Z")

</div>

For visual studio, I’d like to change the link flag /subsystem:CONSOLE to /subsystem:WINDOWS I tried variations such as set\_target\_properties( pyconfstruct PROPERTIES LINK\_FLAGS /subsystem:WINDOWS ) #get\_tar…

---

## [How to build NVidia binaries using CMake's new HIP language?](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208)

<div class="topic-metadata">

**Author:** [@krasznaa](https://discourse.cmake.org/u/krasznaa)\
**Replies:** 7\
**Last updated:** [February 3, 2025, 10:05am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208 "2025-02-03T10:05:06Z")

</div>

I’ve updated my code recently to make use of the “HIP language”, introduced in 3.21. After some initial success on a host with an AMD card, I was now trying to build some code on a host that has an NVidia card. And had …

---

## [ChatGPT gave me a solution that works but idk why?](https://discourse.cmake.org/t/chatgpt-gave-me-a-solution-that-works-but-idk-why/13521)

<div class="topic-metadata">

**Author:** [@TanmayPani](https://discourse.cmake.org/u/TanmayPani)\
**Replies:** 1\
**Last updated:** [February 1, 2025, 8:10am UTC](https://discourse.cmake.org/t/chatgpt-gave-me-a-solution-that-works-but-idk-why/13521 "2025-02-01T08:10:42Z")

</div>

While trying to compile code that uses ROOT, fastjet, Apache-arrow and another pre-compiled shared library, I ran into an issue when I added SoftDrop functionalities using the RecursiveTools library from fastjet contrib,…

---

## [Create list variables in CMakePresets.json](https://discourse.cmake.org/t/create-list-variables-in-cmakepresets-json/9861)

<div class="topic-metadata">

**Author:** [@sharadhr](https://discourse.cmake.org/u/sharadhr)\
**Replies:** 1\
**Last updated:** [January 31, 2025, 1:32pm UTC](https://discourse.cmake.org/t/create-list-variables-in-cmakepresets-json/9861 "2025-01-31T13:32:11Z")

</div>

Is there a way to create list variables in CMakePresets.json? For instance, a list of preprocessor macros to then be passed to target\_compile\_definitions? In CMake syntax, I’d do something like set(MY\_DEFINES\_1 MACRO…

---

## [nvlink fatal : elfLink linker library load error](https://discourse.cmake.org/t/nvlink-fatal-elflink-linker-library-load-error/13512)

<div class="topic-metadata">

**Author:** [@Rafael\_Scatena](https://discourse.cmake.org/u/Rafael_Scatena)\
**Replies:** 1\
**Last updated:** [January 30, 2025, 11:18am UTC](https://discourse.cmake.org/t/nvlink-fatal-elflink-linker-library-load-error/13512 "2025-01-30T11:18:20Z")

</div>

Hello, I am trying to compile a project with cuda. The cuda part of the code compiles correctly, but there is an error in the linking phase. nvlink fatal : elfLink linker library load error Verified that nvcc wor…

---

## [CMake Error : Cannot find source file -\> No SOURCES given to target](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650)

<div class="topic-metadata">

**Author:** [@Raphy](https://discourse.cmake.org/u/Raphy)\
**Replies:** 7\
**Last updated:** [January 29, 2025, 3:53pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650 "2025-01-29T15:53:37Z")

</div>

With this CMakeLists.txt file: cmake\_minimum\_required(VERSION 3.24) project(my\_application LANGUAGES CXX) include(FetchContent) FetchContent\_Declare( WebKit2 #URL https://webkitgtk.org/releases/webkitgtk-2.42.3.tar…

---

## [How I get bison/flex on Windows](https://discourse.cmake.org/t/how-i-get-bison-flex-on-windows/13505)

<div class="topic-metadata">

**Author:** [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)\
**Replies:** 0\
**Last updated:** [January 28, 2025, 10:40pm UTC](https://discourse.cmake.org/t/how-i-get-bison-flex-on-windows/13505 "2025-01-28T22:40:52Z")

</div>

Having code that depends on bison/flex has always been a bit of a PITA on Windows because you have to manually go get the dependency, install it somewhere and then make sure that all your builds have that location in you…

---

## [Including headers from library within same project](https://discourse.cmake.org/t/including-headers-from-library-within-same-project/13496)

<div class="topic-metadata">

**Author:** [@sebastian](https://discourse.cmake.org/u/sebastian)\
**Replies:** 2\
**Last updated:** [January 28, 2025, 3:16pm UTC](https://discourse.cmake.org/t/including-headers-from-library-within-same-project/13496 "2025-01-28T15:16:57Z")

</div>

Hello \*, I have a project where I am building one application and a bunch of (mostly shared) libraries; the application is set up with project(myapp C CXX) and the libraries are set up with add\_library(mod\_plugin1 MODUL…

---

## [XCode generator doesn't pass field "Frameworks, Libraries, and Embedded Content" for Frameworks](https://discourse.cmake.org/t/xcode-generator-doesnt-pass-field-frameworks-libraries-and-embedded-content-for-frameworks/13457)

<div class="topic-metadata">

**Author:** [@Ygrik2003](https://discourse.cmake.org/u/Ygrik2003)\
**Replies:** 1\
**Last updated:** [January 28, 2025, 7:34am UTC](https://discourse.cmake.org/t/xcode-generator-doesnt-pass-field-frameworks-libraries-and-embedded-content-for-frameworks/13457 "2025-01-28T07:34:46Z")

</div>

Hello As I noticed, the manual link to StoreKit in XCode in the “ProjectName → General → Frameworks, Libraries, and Embedded Content” tab adds the In-app-purchase property to Capabilities, which can also be added via XC…

---

## [Proper way to craft a CMakeLists.txt whose (only) output is a Bash script?](https://discourse.cmake.org/t/proper-way-to-craft-a-cmakelists-txt-whose-only-output-is-a-bash-script/13439)

<div class="topic-metadata">

**Author:** [@Dennis\_Ferron](https://discourse.cmake.org/u/Dennis_Ferron)\
**Replies:** 3\
**Last updated:** [January 27, 2025, 10:02am UTC](https://discourse.cmake.org/t/proper-way-to-craft-a-cmakelists-txt-whose-only-output-is-a-bash-script/13439 "2025-01-27T10:02:53Z")

</div>

I have a project using ANTLR4 with an executable in a top level CMakeLists.txt, and one of the subfolders is “testrig” which I want to just produce a Bash script that issues Java commandlines to run the ANTLR4 testrig on…

---

## [ExternalWarningLevel automatically set](https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477)

<div class="topic-metadata">

**Author:** [@nick](https://discourse.cmake.org/u/nick)\
**Replies:** 1\
**Last updated:** [January 27, 2025, 9:58am UTC](https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477 "2025-01-27T09:58:57Z")

</div>

I was investigating why external warnings were turned off in our generated projects. I found out that imported libraries, i.e. add\_library(library\_name INTERFACE IMPORTED), automatically sets the SYSTEM property, which i…

---

## [What character encoding do cache strings use?](https://discourse.cmake.org/t/what-character-encoding-do-cache-strings-use/13492)

<div class="topic-metadata">

**Author:** [@JasonYundt](https://discourse.cmake.org/u/JasonYundt)\
**Replies:** 0\
**Last updated:** [January 26, 2025, 2:58pm UTC](https://discourse.cmake.org/t/what-character-encoding-do-cache-strings-use/13492 "2025-01-26T14:58:01Z")

</div>

I noticed that the documentation for string(SUBSTRING…) says this: Both \<begin\> and \<length\> are counted in bytes, so care must be exercised if \<string\> could contain multi-byte characters. This got me thinking: what…

---

## [Qt6 testing using cmake](https://discourse.cmake.org/t/qt6-testing-using-cmake/13489)

<div class="topic-metadata">

**Author:** [@yl280](https://discourse.cmake.org/u/yl280)\
**Replies:** 1\
**Last updated:** [January 26, 2025, 11:16am UTC](https://discourse.cmake.org/t/qt6-testing-using-cmake/13489 "2025-01-26T11:16:53Z")

</div>

Greetings everyone! I am using the cmake --build ./build command to build certain tests for this project using google tests but I am getting this error. It is searching for Qt5 but I am using Qt6 (-DQT\_VERSION=6) to conf…

---

## [Do I need -m32, etc., in compiler flags?](https://discourse.cmake.org/t/do-i-need-m32-etc-in-compiler-flags/13486)

<div class="topic-metadata">

**Author:** [@rsalz](https://discourse.cmake.org/u/rsalz)\
**Replies:** 0\
**Last updated:** [January 25, 2025, 2:48pm UTC](https://discourse.cmake.org/t/do-i-need-m32-etc-in-compiler-flags/13486 "2025-01-25T14:48:56Z")

</div>

I am a cmake newbie; as my first project I am converting a fork of OpenSSL from a bespoke build environment to cmake. I assume that I don’t need to explicitly add things like -m32, -mcpu=sparc, or /Zi /Fddso.pdb when com…

---

## [Proper post\_build script in xcode for Firebase Crashlytics?](https://discourse.cmake.org/t/proper-post-build-script-in-xcode-for-firebase-crashlytics/13465)

<div class="topic-metadata">

**Author:** [@shokarta](https://discourse.cmake.org/u/shokarta)\
**Replies:** 0\
**Last updated:** [January 23, 2025, 11:55am UTC](https://discourse.cmake.org/t/proper-post-build-script-in-xcode-for-firebase-crashlytics/13465 "2025-01-23T11:55:09Z")

</div>

Hello Guys… I am trying to properly automatizate Get started with Firebase Crashlytics step 4C and 4D. when it set manualy, it shall look like this: so, what I tried is: set(DWARF\_DSYM\_FOLDER\_PATH "${DWARF\_DSYM\_F…

---

## [How to mimic \`make check\` behavior](https://discourse.cmake.org/t/how-to-mimic-make-check-behavior/13462)

<div class="topic-metadata">

**Author:** [@vbsteph](https://discourse.cmake.org/u/vbsteph)\
**Replies:** 0\
**Last updated:** [January 22, 2025, 11:33pm UTC](https://discourse.cmake.org/t/how-to-mimic-make-check-behavior/13462 "2025-01-22T23:33:52Z")

</div>

I want to use CMake to mimic the behavior of a testing workflow that uses make check (as generated by Autotools). Let’s say I have two libraries, A and B, where B depends on A. If I run make check from the binary direct…

---

## [CMake编译ghs工程报警告 CMake generates a warning when compiling the ghs project.](https://discourse.cmake.org/t/cmake-ghs-cmake-generates-a-warning-when-compiling-the-ghs-project/13451)

<div class="topic-metadata">

**Author:** [@wild.boy](https://discourse.cmake.org/u/wild.boy)\
**Replies:** 0\
**Last updated:** [January 22, 2025, 7:27am UTC](https://discourse.cmake.org/t/cmake-ghs-cmake-generates-a-warning-when-compiling-the-ghs-project/13451 "2025-01-22T07:27:04Z")

</div>

I encountered a problem when compiling C code using the Ghs compiler through CMake. Scenario: The MinGw Makefiles generator is used. Problem: When compiling the source file, I always get a warning that “init.c.obj igno…

---

## [set\_tests\_properties ENVIRONMENT ignored](https://discourse.cmake.org/t/set-tests-properties-environment-ignored/13425)

<div class="topic-metadata">

**Author:** [@RobStewart](https://discourse.cmake.org/u/RobStewart)\
**Replies:** 1\
**Last updated:** [January 21, 2025, 12:53pm UTC](https://discourse.cmake.org/t/set-tests-properties-environment-ignored/13425 "2025-01-21T12:53:47Z")

</div>

In my CMakeLists.txt, I define a Python unit test like this: ADD\_TEST(NAME foo COMMAND "${python}" -B -m unittest discover -v WORKING\_DIRECTORY ${CMAKE\_CURRENT\_SOURCE\_DIR} ) For that to work, a related .pyd must …

---

## [After update from FindBoost to BoostConfig (policy 0167), how to convert library targets to paths](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 5\
**Last updated:** [January 21, 2025, 10:28am UTC](https://discourse.cmake.org/t/after-update-from-findboost-to-boostconfig-policy-0167-how-to-convert-library-targets-to-paths/13431 "2025-01-21T10:28:31Z")

</div>

We changed policy 0167 from OLD to NEW, which means we are now using BoostConfig.cmake from Boost instead of the FindBoost module from CMake. This has the side effect that Boost\_LIBRARIES changed from /usr/lib/x86\_64-li…

---

## [Handling configuration related options between multiple projects](https://discourse.cmake.org/t/handling-configuration-related-options-between-multiple-projects/13435)

<div class="topic-metadata">

**Author:** [@SamCoutteauHybrid](https://discourse.cmake.org/u/SamCoutteauHybrid)\
**Replies:** 0\
**Last updated:** [January 20, 2025, 12:31pm UTC](https://discourse.cmake.org/t/handling-configuration-related-options-between-multiple-projects/13435 "2025-01-20T12:31:29Z")

</div>

Within the context of FetchContent, How would you best approach constructs like if (build\_debug) or if (build\_singlethreaded) which are configured from cmake and passed through macro defines (or other means) to cpp code. …

---

## [Make a Windows app ready for the Microsoft Store](https://discourse.cmake.org/t/make-a-windows-app-ready-for-the-microsoft-store/8651)

<div class="topic-metadata">

**Author:** [@paul.masristone](https://discourse.cmake.org/u/paul.masristone)\
**Replies:** 19\
**Last updated:** [January 20, 2025, 11:43am UTC](https://discourse.cmake.org/t/make-a-windows-app-ready-for-the-microsoft-store/8651 "2025-01-20T11:43:57Z")

</div>

Hi. I’m new to using CMake to prepare an app for the Microsoft Store. Can you help or direct me to a tutorial that walks through the process? Background: I’m a Qt developer. I’ve published to the Microsoft Store using …

---

## [CMake bug? Building for Microsoft Store. App does not start up properly](https://discourse.cmake.org/t/cmake-bug-building-for-microsoft-store-app-does-not-start-up-properly/9503)

<div class="topic-metadata">

**Author:** [@paul.masristone](https://discourse.cmake.org/u/paul.masristone)\
**Replies:** 1\
**Last updated:** [January 20, 2025, 11:38am UTC](https://discourse.cmake.org/t/cmake-bug-building-for-microsoft-store-app-does-not-start-up-properly/9503 "2025-01-20T11:38:53Z")

</div>

What works The app builds, installs to bin folder, gets packaged, gets bundled, gets signed. I can install it on my Windows 10 PC (if using a local self-signed certificate). Alternatively I can upload it to Micro…

---

## [Undefined references issue](https://discourse.cmake.org/t/undefined-references-issue/13433)

<div class="topic-metadata">

**Author:** [@asimplecoder](https://discourse.cmake.org/u/asimplecoder)\
**Replies:** 3\
**Last updated:** [January 20, 2025, 9:21am UTC](https://discourse.cmake.org/t/undefined-references-issue/13433 "2025-01-20T09:21:30Z")

</div>

Consider the following tree structure: ├── app │ └── CMakeLists.txt ├── lib │ ├── bindings │ │ ├── CMakeLists.txt │ │ └── fortran │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ └── src │ ├──…

---

## [Link interface library Iconv:Iconv not found](https://discourse.cmake.org/t/link-interface-library-iconv-iconv-not-found/13430)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 2\
**Last updated:** [January 20, 2025, 8:01am UTC](https://discourse.cmake.org/t/link-interface-library-iconv-iconv-not-found/13430 "2025-01-20T08:01:36Z")

</div>

I’m trying to build my project on macOS. I’m installing pre-reqs using vcpkg. I’m getting this error: 1\> \[CMake\] CMake Error at out/build/vcpkg\_installed/arm64-osx/share/exiv2/exiv2Export.cmake:60 (set\_target\_properti…

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

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