# Code

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

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

**Page:** 25

---

## [Adding link libraries at build time](https://discourse.cmake.org/t/adding-link-libraries-at-build-time/7552)

<div class="topic-metadata">

**Author:** [@jschwe](https://discourse.cmake.org/u/jschwe)\
**Replies:** 9\
**Last updated:** [February 19, 2024, 3:57am UTC](https://discourse.cmake.org/t/adding-link-libraries-at-build-time/7552 "2024-02-19T03:57:49Z")

</div>

Hi, I’m currently maintaining Corrosion which integrates Rusts cargo build system into CMake. When linking Rust static libraries into C/C++ code (managed by CMake), we also need to link some system libraries (e.g. pthr…

---

## [\`GenerateExportHeader\` and multi-compiler support](https://discourse.cmake.org/t/generateexportheader-and-multi-compiler-support/10102)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 2\
**Last updated:** [February 18, 2024, 10:22pm UTC](https://discourse.cmake.org/t/generateexportheader-and-multi-compiler-support/10102 "2024-02-18T22:22:14Z")

</div>

I have just started looking into GenerateExportHeader, but what I’ve noticed is that it does only generates the define for the specific compiler I am using, e.g. it does not have branching for \_\_GNUC\_\_, \_MSC\_VER. But the…

---

## [How to transmit the libusb dependency?](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100)

<div class="topic-metadata">

**Author:** [@Stefano\_M](https://discourse.cmake.org/u/Stefano_M)\
**Replies:** 3\
**Last updated:** [February 18, 2024, 4:01pm UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100 "2024-02-18T16:01:13Z")

</div>

Hi all, I’m writing two c++ projects, both controlled by CMakeLists files: a library and an application. VisualStudio 2019 as environment. Library libUpgrade It includes libusb library installed by vcpkg tool, so in C…

---

## [Setting RPATH and not RUNPATH for executable](https://discourse.cmake.org/t/setting-rpath-and-not-runpath-for-executable/10011)

<div class="topic-metadata">

**Author:** [@dconnell](https://discourse.cmake.org/u/dconnell)\
**Replies:** 16\
**Last updated:** [February 18, 2024, 5:05am UTC](https://discourse.cmake.org/t/setting-rpath-and-not-runpath-for-executable/10011 "2024-02-18T05:05:32Z")

</div>

I am working on a project that I would like to be able to distribute pre-compiled binaries for and I believe I’m in a scenario where I really do need to set RPATH and not RUNPATH but all the CMAKE\_\*\_RPATH seem to be sett…

---

## [\`export(EXPORT)\` does not work for windows?](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 7\
**Last updated:** [February 17, 2024, 5:19pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109 "2024-02-17T17:19:56Z")

</div>

I am using the build directory’s ...Config.cmake file to test that the project works well with find\_package. However, on windows this approach does not seem to work, giving me DLL\_IMPORT errors. I am not sure what to mak…

---

## [Create Imported Targets before or after find\_package\_handle\_standard\_args() call in Find modules?](https://discourse.cmake.org/t/create-imported-targets-before-or-after-find-package-handle-standard-args-call-in-find-modules/10092)

<div class="topic-metadata">

**Author:** [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Replies:** 2\
**Last updated:** [February 17, 2024, 5:03pm UTC](https://discourse.cmake.org/t/create-imported-targets-before-or-after-find-package-handle-standard-args-call-in-find-modules/10092 "2024-02-17T17:03:54Z")

</div>

Hello, CMake Team. Based on the statistical results, it appears that most of the CMake’s built-in Find modules create Imported Targets after the find\_package\_handle\_standard\_args() call in Find modules. Before find\_p…

---

## [Which search paths are disabled by specifying NO\_DEFAULT\_PATH in find\_xxx commands?](https://discourse.cmake.org/t/which-search-paths-are-disabled-by-specifying-no-default-path-in-find-xxx-commands/10060)

<div class="topic-metadata">

**Author:** [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Replies:** 4\
**Last updated:** [February 17, 2024, 7:36am UTC](https://discourse.cmake.org/t/which-search-paths-are-disabled-by-specifying-no-default-path-in-find-xxx-commands/10060 "2024-02-17T07:36:18Z")

</div>

Hello, CMake Team. From the content of the CMake documentation, it is known: For the find\_xxx family of commands, the search is generally conducted in the following order: paths in \<PackageName\>\_ROOT cache/environmen…

---

## [Adhere to the rules stipulated in 'cmake-developer' or those in 'find\_package' for Find modules?](https://discourse.cmake.org/t/adhere-to-the-rules-stipulated-in-cmake-developer-or-those-in-find-package-for-find-modules/10053)

<div class="topic-metadata">

**Author:** [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Replies:** 4\
**Last updated:** [February 17, 2024, 6:12am UTC](https://discourse.cmake.org/t/adhere-to-the-rules-stipulated-in-cmake-developer-or-those-in-find-package-for-find-modules/10053 "2024-02-17T06:12:09Z")

</div>

Hello, CMake Team. Recently, while writing my own Find module, I encountered a point of confusion: Should I adhere to the rules stipulated in cmake-developer or those in find\_package for Find modules? In the cmake-d…

---

## [using \`-isystem\` flag](https://discourse.cmake.org/t/using-isystem-flag/10044)

<div class="topic-metadata">

**Author:** [@David\_Brixton](https://discourse.cmake.org/u/David_Brixton)\
**Replies:** 2\
**Last updated:** [February 17, 2024, 5:59am UTC](https://discourse.cmake.org/t/using-isystem-flag/10044 "2024-02-17T05:59:03Z")

</div>

What I want to do: Disable warnings generated by external libraries while using CMake. Details: I’m using cmake to compile my OpenCV project. But OpenCV throws a lot of warnings. When I’m compiling the project from co…

---

## [Proper CTest integration with Visual Studio?](https://discourse.cmake.org/t/proper-ctest-integration-with-visual-studio/10042)

<div class="topic-metadata">

**Author:** [@malaterre](https://discourse.cmake.org/u/malaterre)\
**Replies:** 1\
**Last updated:** [February 17, 2024, 5:57am UTC](https://discourse.cmake.org/t/proper-ctest-integration-with-visual-studio/10042 "2024-02-17T05:57:25Z")

</div>

I’d like to tightly integrate my test suite with Visual Studio 2019. If I understand correctly, the correct way is to reference one project to another: Write unit tests for C++ DLLs - Visual Studio (Windows) | Microsof…

---

## [Fortran: Importing \`.mod\` with fallback to \`.f90\`](https://discourse.cmake.org/t/fortran-importing-mod-with-fallback-to-f90/9978)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 12\
**Last updated:** [February 17, 2024, 5:39am UTC](https://discourse.cmake.org/t/fortran-importing-mod-with-fallback-to-f90/9978 "2024-02-17T05:39:46Z")

</div>

I am thinking of a workaround compatibility until the CXX modules logic can be ported to Fortran as well. My idea is the following: Pacakge both the .mod files and the .f90 files with the install(TARGETS) all of which …

---

## [\[Beginner\] Compiling parmetis MacOS with homebrew](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006)

<div class="topic-metadata">

**Author:** [@bdl42](https://discourse.cmake.org/u/bdl42)\
**Replies:** 5\
**Last updated:** [February 16, 2024, 2:16pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006 "2024-02-16T14:16:20Z")

</div>

Big picture: Attempting to compile elmerfem on an M3 silicon Mac with parallel computing abilities Litle steps: Get some of the prerequisite libraries compiled with homebrew installed open-mpi or gcc. Step one: get par…

---

## [Link issues with CMake, CTest and Catch2](https://discourse.cmake.org/t/link-issues-with-cmake-ctest-and-catch2/8343)

<div class="topic-metadata">

**Author:** [@antoniovazquezblanco](https://discourse.cmake.org/u/antoniovazquezblanco)\
**Replies:** 3\
**Last updated:** [February 15, 2024, 7:10pm UTC](https://discourse.cmake.org/t/link-issues-with-cmake-ctest-and-catch2/8343 "2024-02-15T19:10:59Z")

</div>

I’ve been helping a friend improve it’s SDR (Software Defined Radio) project by trying to improve the build system. The project has gotten to a point where everything seems to be quite stable and functional so I wanted …

---

## [How to build 32 bit Windows apps with ninja?](https://discourse.cmake.org/t/how-to-build-32-bit-windows-apps-with-ninja/10070)

<div class="topic-metadata">

**Author:** [@marksibly](https://discourse.cmake.org/u/marksibly)\
**Replies:** 1\
**Last updated:** [February 13, 2024, 9:10am UTC](https://discourse.cmake.org/t/how-to-build-32-bit-windows-apps-with-ninja/10070 "2024-02-13T09:10:08Z")

</div>

Hi, Is it possible to use Ninja to build 32 bit apps on 64 bit windows? When I try passing “-G Ninja -DCMAKE\_GENERATOR\_PLATFORM=Win32” to cmake, I get the following error: “Ninja does not support platform specificati…

---

## [Installing headers the modern way, regurgitated and revisited](https://discourse.cmake.org/t/installing-headers-the-modern-way-regurgitated-and-revisited/3238)

<div class="topic-metadata">

**Author:** [@Braden](https://discourse.cmake.org/u/Braden)\
**Replies:** 4\
**Last updated:** [February 13, 2024, 10:43am UTC](https://discourse.cmake.org/t/installing-headers-the-modern-way-regurgitated-and-revisited/3238 "2024-02-13T10:43:59Z")

</div>

Some weeks ago, under Installing headers the modern way, I posed a question regarding the relationship (or lack thereof) between target\_sources(mylib PUBLIC ...) and install(TARGETS mylib PUBLIC\_HEADER ...). This is a pa…

---

## [install(EXPORT ...) and install(EXPORT\_ANDROID\_MK ...) cannot coexist. why?](https://discourse.cmake.org/t/install-export-and-install-export-android-mk-cannot-coexist-why/10024)

<div class="topic-metadata">

**Author:** [@Lukasz\_Tyrala](https://discourse.cmake.org/u/Lukasz_Tyrala)\
**Replies:** 2\
**Last updated:** [February 7, 2024, 8:53pm UTC](https://discourse.cmake.org/t/install-export-and-install-export-android-mk-cannot-coexist-why/10024 "2024-02-07T20:53:09Z")

</div>

Hi, I want to build my library for Android AOSP. I want to build it as a library and install it with android.mk this is my CMake script: cmake\_minimum\_required(VERSION 3.22.1) # test output set(CMAKE\_INSTALL\_PREFIX "$…

---

## [Exit with error if user attempt to override CMAKE\_INSTALL\_PREFIX during installation](https://discourse.cmake.org/t/exit-with-error-if-user-attempt-to-override-cmake-install-prefix-during-installation/10020)

<div class="topic-metadata">

**Author:** [@Kentzo](https://discourse.cmake.org/u/Kentzo)\
**Replies:** 3\
**Last updated:** [February 8, 2024, 5:16am UTC](https://discourse.cmake.org/t/exit-with-error-if-user-attempt-to-override-cmake-install-prefix-during-installation/10020 "2024-02-08T05:16:41Z")

</div>

My project requires CMAKE\_INSTALL\_PREFIX to be provided during the configuration step. However, cmake allow the user to override it with cmake --install ... --prefix. That will result in a broken installation. Is there …

---

## [different include file for different test](https://discourse.cmake.org/t/different-include-file-for-different-test/10023)

<div class="topic-metadata">

**Author:** [@joris\_van\_emden](https://discourse.cmake.org/u/joris_van_emden)\
**Replies:** 1\
**Last updated:** [February 7, 2024, 12:41pm UTC](https://discourse.cmake.org/t/different-include-file-for-different-test/10023 "2024-02-07T12:41:43Z")

</div>

Hello great minds ! I am using Zephyr for a project and write tests by using cpputest. In my code I have some buffers. These buffers depend on the hardware underneath (in this case FLASH NAND page size), we can use zep…

---

## [Toolchainfile for Armclang](https://discourse.cmake.org/t/toolchainfile-for-armclang/9976)

<div class="topic-metadata">

**Author:** [@pedahl](https://discourse.cmake.org/u/pedahl)\
**Replies:** 1\
**Last updated:** [February 4, 2024, 7:42pm UTC](https://discourse.cmake.org/t/toolchainfile-for-armclang/9976 "2024-02-04T19:42:00Z")

</div>

Hi, i have created a Toolchainfile for Armclang: set(CMAKE\_SYSTEM\_PROCESSOR cortex-m4) set(CMAKE\_SYSTEM\_NAME Generic) set(CMAKE\_SYSTEM\_VERSION "6") set(TOOLCHAIN\_PATH C:/Keil\_v5/ARM/ARMCLANG) find\_program(ARM\_CC NAMES…

---

## [ExternalProject that depends on another target for SOURCE\_DIR](https://discourse.cmake.org/t/externalproject-that-depends-on-another-target-for-source-dir/9979)

<div class="topic-metadata">

**Author:** [@Kentzo](https://discourse.cmake.org/u/Kentzo)\
**Replies:** 1\
**Last updated:** [February 4, 2024, 1:57pm UTC](https://discourse.cmake.org/t/externalproject-that-depends-on-another-target-for-source-dir/9979 "2024-02-04T13:57:59Z")

</div>

I’m trying to define an external project that depends on another target to prepare its source directory: ExternalProject\_Add(Dependency ...) ExternalProject\_Get\_Property(Dependency INSTALL\_DIR) set(target\_source\_dir "${…

---

## [Cross project cmake utils structure/export/import](https://discourse.cmake.org/t/cross-project-cmake-utils-structure-export-import/9985)

<div class="topic-metadata">

**Author:** [@McMill](https://discourse.cmake.org/u/McMill)\
**Replies:** 2\
**Last updated:** [February 3, 2024, 12:05pm UTC](https://discourse.cmake.org/t/cross-project-cmake-utils-structure-export-import/9985 "2024-02-03T12:05:50Z")

</div>

Hi, We need some way to share various cmake functions, macros and maybe targets between multiple other cmake based projects that each reside in their own git repo. I was thinking making a cmake-utility project/git repo …

---

## [source\_group Visual Studio](https://discourse.cmake.org/t/source-group-visual-studio/9990)

<div class="topic-metadata">

**Author:** [@jmigual](https://discourse.cmake.org/u/jmigual)\
**Replies:** 2\
**Last updated:** [February 3, 2024, 8:05am UTC](https://discourse.cmake.org/t/source-group-visual-studio/9990 "2024-02-03T08:05:25Z")

</div>

I am trying to use source\_group to show the files nicely in my IDE (Visual Studio 2022). The structure of my header files has some files in subfolders and others only in the include folder (sorry I can only embed one pho…

---

## [CMakePresets: What is the overwrite order for multiple inheritance?](https://discourse.cmake.org/t/cmakepresets-what-is-the-overwrite-order-for-multiple-inheritance/8775)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 11\
**Last updated:** [February 1, 2024, 4:18pm UTC](https://discourse.cmake.org/t/cmakepresets-what-is-the-overwrite-order-for-multiple-inheritance/8775 "2024-02-01T16:18:24Z")

</div>

I have the CMakeUserPreset.json: { "version": 6, "cmakeMinimumRequired": { "major": 3, "minor": 25, "patch": 0 }, "configurePresets": \[ { "name": "dev", "displayName": "developer Ninj…

---

## [Adding a new file to an existing source\_group](https://discourse.cmake.org/t/adding-a-new-file-to-an-existing-source-group/9977)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 1\
**Last updated:** [February 1, 2024, 1:59am UTC](https://discourse.cmake.org/t/adding-a-new-file-to-an-existing-source-group/9977 "2024-02-01T01:59:51Z")

</div>

I have a fairly large project which is structured in such a way that, after a large number of files have been generated, they are placed into a special ‘Generated’ folder within my Visual Studio project: source\_group(TR…

---

## [Confused with Toolchain and CMAKE\_SYSTEM\_PROCESSOR and CMP0123](https://discourse.cmake.org/t/confused-with-toolchain-and-cmake-system-processor-and-cmp0123/9966)

<div class="topic-metadata">

**Author:** [@pedahl](https://discourse.cmake.org/u/pedahl)\
**Replies:** 2\
**Last updated:** [January 31, 2024, 8:48am UTC](https://discourse.cmake.org/t/confused-with-toolchain-and-cmake-system-processor-and-cmp0123/9966 "2024-01-31T08:48:21Z")

</div>

Hi, i’m a little bit confused about set CMAKE\_SYSTEM\_PROCESSOR and the policy CMP0123 according to a Toolchainfile. I want to build a cmake project for a bare metal system and i want to compile it with armclang. I cr…

---

## [Understanding of FetchContent](https://discourse.cmake.org/t/understanding-of-fetchcontent/9963)

<div class="topic-metadata">

**Author:** [@Codeboybebop](https://discourse.cmake.org/u/Codeboybebop)\
**Replies:** 4\
**Last updated:** [January 30, 2024, 8:49pm UTC](https://discourse.cmake.org/t/understanding-of-fetchcontent/9963 "2024-01-30T20:49:59Z")

</div>

I have created a repository that contains two libraries foo and bar. They define same functions std::string call() but provides different result. I want to use one of them in different project. Hence I wrote the follow…

---

## [Replace file GLOB for a better way to add include files](https://discourse.cmake.org/t/replace-file-glob-for-a-better-way-to-add-include-files/9947)

<div class="topic-metadata">

**Author:** [@BrendanL](https://discourse.cmake.org/u/BrendanL)\
**Replies:** 2\
**Last updated:** [January 29, 2024, 6:21pm UTC](https://discourse.cmake.org/t/replace-file-glob-for-a-better-way-to-add-include-files/9947 "2024-01-29T18:21:33Z")

</div>

I have a project that I put together from a tutorial on a website a few years ago. I have learned that I shouldn’t use GLOB to create a list of files for many reasons but I’m having trouble figuring out the correct way …

---

## [How to share precompiled headers via an interface library](https://discourse.cmake.org/t/how-to-share-precompiled-headers-via-an-interface-library/9933)

<div class="topic-metadata">

**Author:** [@Kentzo](https://discourse.cmake.org/u/Kentzo)\
**Replies:** 7\
**Last updated:** [January 27, 2024, 9:04am UTC](https://discourse.cmake.org/t/how-to-share-precompiled-headers-via-an-interface-library/9933 "2024-01-27T09:04:13Z")

</div>

From target\_precompile\_headers: A notable exception to this is where an interface library is created to define a commonly used set of precompile headers in one place and then other targets link to that interface librar…

---

## [FetchContent does not support properly URLs with brackets](https://discourse.cmake.org/t/fetchcontent-does-not-support-properly-urls-with-brackets/8650)

<div class="topic-metadata">

**Author:** [@Yannick\_Daveluy](https://discourse.cmake.org/u/Yannick_Daveluy)\
**Replies:** 4\
**Last updated:** [January 27, 2024, 1:07am UTC](https://discourse.cmake.org/t/fetchcontent-does-not-support-properly-urls-with-brackets/8650 "2024-01-27T01:07:19Z")

</div>

Hello, I tried to fecth this URL : https://ecss.nl/wp-content/uploads/2020/04/ECSS\_SMP\_Issue1(2March2020).zip I think that the correct way would be to write something like: FetchContent\_Declare( ecss\_smp URL “https:…

---

## [Target-dependent linker output location](https://discourse.cmake.org/t/target-dependent-linker-output-location/9923)

<div class="topic-metadata">

**Author:** [@gpanders](https://discourse.cmake.org/u/gpanders)\
**Replies:** 6\
**Last updated:** [January 26, 2024, 8:09pm UTC](https://discourse.cmake.org/t/target-dependent-linker-output-location/9923 "2024-01-26T20:09:12Z")

</div>

We use -Wl,-Map,output.map in add\_link\_options to output a map file in the link stage for all executable targets. This works when using the Makefile generator because Make first changes to the target build directory befo…

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

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