# Code

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

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

**Page:** 31

---

## [Statically linking llvm into a library, results in unresolved externals.](https://discourse.cmake.org/t/statically-linking-llvm-into-a-library-results-in-unresolved-externals/8867)

<div class="topic-metadata">

**Author:** [@natschz](https://discourse.cmake.org/u/natschz)\
**Replies:** 8\
**Last updated:** [September 13, 2023, 2:45am UTC](https://discourse.cmake.org/t/statically-linking-llvm-into-a-library-results-in-unresolved-externals/8867 "2023-09-13T02:45:02Z")

</div>

I’m not really experienced with cmake, but the last few days I tried to figure out, why I can’t build a static library which contains llvm. I’m trying to build this on windows. I’ve created a subdirectory, where I link…

---

## [Using target-specific generator expressions in global CMake variables](https://discourse.cmake.org/t/using-target-specific-generator-expressions-in-global-cmake-variables/8886)

<div class="topic-metadata">

**Author:** [@AnyOldName3](https://discourse.cmake.org/u/AnyOldName3)\
**Replies:** 2\
**Last updated:** [September 6, 2023, 11:12pm UTC](https://discourse.cmake.org/t/using-target-specific-generator-expressions-in-global-cmake-variables/8886 "2023-09-06T23:12:23Z")

</div>

I’d like to write something of the form set(CMAKE\_VS\_DEBUGGER\_WORKING\_DIRECTORY "$\<TARGET\_FILE\_DIR:$\<some genex to get the name of the target this ends up applying to\>\>") so that each target’s value of VS\_DEBUGGER\_WORK…

---

## [How to link to wxWidgets static libs](https://discourse.cmake.org/t/how-to-link-to-wxwidgets-static-libs/8876)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 5\
**Last updated:** [September 6, 2023, 2:43pm UTC](https://discourse.cmake.org/t/how-to-link-to-wxwidgets-static-libs/8876 "2023-09-06T14:43:17Z")

</div>

I am attempting to link my project to the wxWidgets library by employing the following sequence of CMake commands: # Linking to libraray set(wxWidgets\_ROOT\_DIR "${CMAKE\_SOURCE\_DIR}/lib/wxWidgets-3.2.2.1") set(wxWidgets…

---

## [External project dependency](https://discourse.cmake.org/t/external-project-dependency/8862)

<div class="topic-metadata">

**Author:** [@natersoz](https://discourse.cmake.org/u/natersoz)\
**Replies:** 4\
**Last updated:** [September 4, 2023, 12:24am UTC](https://discourse.cmake.org/t/external-project-dependency/8862 "2023-09-04T00:24:53Z")

</div>

Greetings, CMake version in use: 3.24, but would be nice to work on 3.16 as well. I cannot seem to get CMake to recognize a dependency based on an external project. The goal is to download Nordic Semiconductor’s SDK a…

---

## [how to make cmake reconfigure itself from cmakelists, or how to re-addsubdirectory ?](https://discourse.cmake.org/t/how-to-make-cmake-reconfigure-itself-from-cmakelists-or-how-to-re-addsubdirectory/8858)

<div class="topic-metadata">

**Author:** [@Gerodote](https://discourse.cmake.org/u/Gerodote)\
**Replies:** 7\
**Last updated:** [September 2, 2023, 6:34am UTC](https://discourse.cmake.org/t/how-to-make-cmake-reconfigure-itself-from-cmakelists-or-how-to-re-addsubdirectory/8858 "2023-09-02T06:34:58Z")

</div>

I thought to use CPM for my project. I got to problem that if CPM adds smth, then it’s cannot be readded. Example : boost. one package adds only one library from it ( and the dependencies ) , but another package uses s…

---

## [Using third-party libraries](https://discourse.cmake.org/t/using-third-party-libraries/8852)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 1\
**Last updated:** [September 1, 2023, 11:33am UTC](https://discourse.cmake.org/t/using-third-party-libraries/8852 "2023-09-01T11:33:19Z")

</div>

I’d like to begin by acknowledging that there are many other posts discussing this topic. Nevertheless, after a thorough review, I’ve observed that none of them explicitly explain the specifics of my questions issues tha…

---

## [Extending generator expressions?](https://discourse.cmake.org/t/extending-generator-expressions/8851)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 1\
**Last updated:** [August 31, 2023, 7:25pm UTC](https://discourse.cmake.org/t/extending-generator-expressions/8851 "2023-08-31T19:25:24Z")

</div>

I’ve inherited a lot of cmake code that looks at CMAKE\_BUILD\_TYPE and a group of users who use multi-config generators. Whoops. As I began the process of refactoring to generator expressions I quickly find my eyes bleed…

---

## [Changing target output path based on architecture](https://discourse.cmake.org/t/changing-target-output-path-based-on-architecture/8839)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 3\
**Last updated:** [August 30, 2023, 11:41pm UTC](https://discourse.cmake.org/t/changing-target-output-path-based-on-architecture/8839 "2023-08-30T23:41:41Z")

</div>

Sometimes, I might need to modify the output directory based on whether my build is 32-bit or 64-bit . Currently, this is what I have in place: # Decide where to put the target based on the architecture (32/64 bit) if(…

---

## [Changing output directories](https://discourse.cmake.org/t/changing-output-directories/8829)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 1\
**Last updated:** [August 28, 2023, 10:46am UTC](https://discourse.cmake.org/t/changing-output-directories/8829 "2023-08-28T10:46:35Z")

</div>

I wanted to modify the output destination for building my binaries through CMake. My objective was to organize the generation of executables, static libraries, and dynamic libraries based on architecture (64-bit/32-bit) …

---

## [CMake goes into an infinite loop when there are two stand-alone subprojects with two different compilers within the same build](https://discourse.cmake.org/t/cmake-goes-into-an-infinite-loop-when-there-are-two-stand-alone-subprojects-with-two-different-compilers-within-the-same-build/8833)

<div class="topic-metadata">

**Author:** [@chudur-budur](https://discourse.cmake.org/u/chudur-budur)\
**Replies:** 1\
**Last updated:** [August 29, 2023, 1:54am UTC](https://discourse.cmake.org/t/cmake-goes-into-an-infinite-loop-when-there-are-two-stand-alone-subprojects-with-two-different-compilers-within-the-same-build/8833 "2023-08-29T01:54:32Z")

</div>

I am new to CMake. What I want to have is two different stand-alone subprojects within one “root” project such that those two subprojects could be built independently. Given that those two subprojects use two different t…

---

## [Using multiple toolchains in the same project?](https://discourse.cmake.org/t/using-multiple-toolchains-in-the-same-project/1505)

<div class="topic-metadata">

**Author:** [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)\
**Replies:** 3\
**Last updated:** [August 28, 2023, 11:44pm UTC](https://discourse.cmake.org/t/using-multiple-toolchains-in-the-same-project/1505 "2023-08-28T23:44:39Z")

</div>

I’m looking at adding proper support for WebAssembly to the CMake build files for a project (Halide) and am a little unclear as to whether there is a simple way to make this happen. Here’s the problem: Halide is, itse…

---

## [install(EXPORT) complains that a dependency is in multiple export sets](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218)

<div class="topic-metadata">

**Author:** [@Dylan\_Reedy](https://discourse.cmake.org/u/Dylan_Reedy)\
**Replies:** 2\
**Last updated:** [August 28, 2023, 8:42pm UTC](https://discourse.cmake.org/t/install-export-complains-that-a-dependency-is-in-multiple-export-sets/8218 "2023-08-28T20:42:04Z")

</div>

I have a project, Foo, which depends on another project, Bar. Bar creates multiple targets, which I add to a single export set via a macro thusly: add\_library(Bar::${TARGET\_NAME} ALIAS ${TARGET\_NAME}) # do things like…

---

## [CMAKE\_IGNORE\_PREFIX\_PATH](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 5\
**Last updated:** [August 28, 2023, 2:38pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559 "2023-08-28T14:38:33Z")

</div>

I am trying to use CMAKE\_IGNORE\_PREFIX\_PATH to avoid having to set a long list of CMAKE\_IGNORE\_PATH subdirectories. However, it appears not to work for the use case described in the MR discussion. My case is Anaconda Py…

---

## [sometimes find\_package() does not look for files in passed PATHS parameter](https://discourse.cmake.org/t/sometimes-find-package-does-not-look-for-files-in-passed-paths-parameter/8614)

<div class="topic-metadata">

**Author:** [@zeroxia](https://discourse.cmake.org/u/zeroxia)\
**Replies:** 2\
**Last updated:** [August 25, 2023, 8:10am UTC](https://discourse.cmake.org/t/sometimes-find-package-does-not-look-for-files-in-passed-paths-parameter/8614 "2023-08-25T08:10:25Z")

</div>

Hello, We’ve a repository running for a long while, recently, without any related changes, a spurious cmake error happened, only on some build environments. The environment is Ubuntu 18.04. CMake version is 3.23.0 o…

---

## [Cmake Project not linking correctly](https://discourse.cmake.org/t/cmake-project-not-linking-correctly/8806)

<div class="topic-metadata">

**Author:** [@Tmurdoch](https://discourse.cmake.org/u/Tmurdoch)\
**Replies:** 8\
**Last updated:** [August 24, 2023, 12:10am UTC](https://discourse.cmake.org/t/cmake-project-not-linking-correctly/8806 "2023-08-24T00:10:08Z")

</div>

I have been trying to link a test file (TestIntstantiator.cpp) to a library for a while, i’ve tried using add\_subdirectories and multiple libraries but this just confused me (and the compiler). I am now trying to do it i…

---

## [tests that are meant to abort()](https://discourse.cmake.org/t/tests-that-are-meant-to-abort/537)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 12\
**Last updated:** [August 22, 2023, 6:57pm UTC](https://discourse.cmake.org/t/tests-that-are-meant-to-abort/537 "2023-08-22T18:57:00Z")

</div>

I understand that the WILL\_FAIL test property informs CTest that a test is expected to fail, which in this case means “exits with a non-zero exit code”. However, we have a set of tests that confirm that our application o…

---

## [Why does my test calling \`abort()\` not output anything?](https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803)

<div class="topic-metadata">

**Author:** [@perlun](https://discourse.cmake.org/u/perlun)\
**Replies:** 1\
**Last updated:** [August 22, 2023, 6:56pm UTC](https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803 "2023-08-22T18:56:04Z")

</div>

Quoting myself from tests that are meant to abort() - #11 by perlun, but moving this to a separate thread for discoverability: \[P\]rocesses raising SIGABRT (e.g. using asserts which call abort()) will cause ctest to pri…

---

## [CMake Build Fails After Migration from 3.23.5 to 3.24.0-rc1](https://discourse.cmake.org/t/cmake-build-fails-after-migration-from-3-23-5-to-3-24-0-rc1/8693)

<div class="topic-metadata">

**Author:** [@alanpaterson78](https://discourse.cmake.org/u/alanpaterson78)\
**Replies:** 5\
**Last updated:** [August 22, 2023, 11:48am UTC](https://discourse.cmake.org/t/cmake-build-fails-after-migration-from-3-23-5-to-3-24-0-rc1/8693 "2023-08-22T11:48:34Z")

</div>

I have a cmake project which uses FetchContent to pull in google test from a github mirror. There are also some custom targets for optionally enabling and disabling bullseye coverage on the build. This all worked well up…

---

## [CMAKE\_SYSTEM\_HOST\_PROCESSOR and CMAKE\_SYSTEM\_PROCESSOR wrong](https://discourse.cmake.org/t/cmake-system-host-processor-and-cmake-system-processor-wrong/8796)

<div class="topic-metadata">

**Author:** [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Replies:** 2\
**Last updated:** [August 22, 2023, 10:50am UTC](https://discourse.cmake.org/t/cmake-system-host-processor-and-cmake-system-processor-wrong/8796 "2023-08-22T10:50:42Z")

</div>

I use this value to pull specific cross compiled artifacts from our artifactory server. This time I am NOT cross compiling. I am compiling on a arm64 board. (aarch64) uname -m returns “aarch64” Both CMAKE\_SYSTEM\_HOST…

---

## [link\_directories() command Adds two directories for each directory passed to it](https://discourse.cmake.org/t/link-directories-command-adds-two-directories-for-each-directory-passed-to-it/8794)

<div class="topic-metadata">

**Author:** [@Malaz99](https://discourse.cmake.org/u/Malaz99)\
**Replies:** 4\
**Last updated:** [August 22, 2023, 10:49am UTC](https://discourse.cmake.org/t/link-directories-command-adds-two-directories-for-each-directory-passed-to-it/8794 "2023-08-22T10:49:27Z")

</div>

link\_directories() command Adds two directories for each directory passed to it; one is the same as what I pass to the command and another with the appended Visual Studio $(Configuration) variable. How do I prevent that…

---

## [file(LOCK \<file-name\> GUARD ... What do the three GUARDs function, file and process mean exactly?](https://discourse.cmake.org/t/file-lock-file-name-guard-what-do-the-three-guards-function-file-and-process-mean-exactly/8767)

<div class="topic-metadata">

**Author:** [@romkell](https://discourse.cmake.org/u/romkell)\
**Replies:** 2\
**Last updated:** [August 21, 2023, 5:31pm UTC](https://discourse.cmake.org/t/file-lock-file-name-guard-what-do-the-three-guards-function-file-and-process-mean-exactly/8767 "2023-08-21T17:31:40Z")

</div>

Hi The long story (below) short, I need to protect a central cmake generated static code analyzer configuration folder from being overwritten by a second call of cmake. I currently use if(EXISTS \<lock-file.txt\>) to te…

---

## [Forcing libraries to be linked in order to expose header-only dependencies.](https://discourse.cmake.org/t/forcing-libraries-to-be-linked-in-order-to-expose-header-only-dependencies/8778)

<div class="topic-metadata">

**Author:** [@Noah\_Watkins](https://discourse.cmake.org/u/Noah_Watkins)\
**Replies:** 3\
**Last updated:** [August 21, 2023, 2:12am UTC](https://discourse.cmake.org/t/forcing-libraries-to-be-linked-in-order-to-expose-header-only-dependencies/8778 "2023-08-21T02:12:04Z")

</div>

Like many projects we many different libraries, executables, and tests that depend on different combinations of dependencies. project/src/ - libA/\*.{h,c} - libB/\*.{h,c} - exeA depends\_on libA - testA depends\_on lib{A,B}…

---

## [Shared library in CMake](https://discourse.cmake.org/t/shared-library-in-cmake/8773)

<div class="topic-metadata">

**Author:** [@Matheus\_Diogenes\_And](https://discourse.cmake.org/u/Matheus_Diogenes_And)\
**Replies:** 4\
**Last updated:** [August 18, 2023, 7:02pm UTC](https://discourse.cmake.org/t/shared-library-in-cmake/8773 "2023-08-18T19:02:49Z")

</div>

Hello everyone. Summary I am working in a C++20 project that makes use of a shared library. So far, I successfully managed to call the shared library when compiling and running the script, however, when using CMake to …

---

## [ExternalProject's CONFIGURE\_COMMAND - can I "extend" instead of replacing it?](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765)

<div class="topic-metadata">

**Author:** [@MaxEd](https://discourse.cmake.org/u/MaxEd)\
**Replies:** 2\
**Last updated:** [August 18, 2023, 12:48pm UTC](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765 "2023-08-18T12:48:59Z")

</div>

I need to set some environment variables before running configuration step. The recommended way to do this is to modify CONFIGURE\_COMMAND and add ${CMAKE\_COMMAND} -E env VAR=VALUE to it. However, I still need to call CMa…

---

## [CMAKE\_HAVE\_LIBC\_PTHREAD failed](https://discourse.cmake.org/t/cmake-have-libc-pthread-failed/319)

<div class="topic-metadata">

**Author:** [@mahmoodn](https://discourse.cmake.org/u/mahmoodn)\
**Replies:** 10\
**Last updated:** [August 18, 2023, 12:39pm UTC](https://discourse.cmake.org/t/cmake-have-libc-pthread-failed/319 "2023-08-18T12:39:07Z")

</div>

Hi, I want to build Pytorch which uses cmake for its building procedure. Since the system gcc is 4.8.5, I want to use a custom path installed gcc-6.1.0. Currently, when I run $ export CC=/storage/users/mnaderan/tools/g…

---

## [target\_compile\_options being applied to header files from FetchContent dependency](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738)

<div class="topic-metadata">

**Author:** [@SchizoidSage](https://discourse.cmake.org/u/SchizoidSage)\
**Replies:** 6\
**Last updated:** [August 17, 2023, 2:05pm UTC](https://discourse.cmake.org/t/target-compile-options-being-applied-to-header-files-from-fetchcontent-dependency/8738 "2023-08-17T14:05:44Z")

</div>

I’m creating a Pong game project with a dependency on a Github project called EnTT, a header-only library. Previously, I manually downloaded and installed EnTT in /usr/local, and included it with find\_package(EnTT), whic…

---

## [CMakePresets: why not expand macros in name or inherits fields?](https://discourse.cmake.org/t/cmakepresets-why-not-expand-macros-in-name-or-inherits-fields/8747)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 2\
**Last updated:** [August 17, 2023, 11:26am UTC](https://discourse.cmake.org/t/cmakepresets-why-not-expand-macros-in-name-or-inherits-fields/8747 "2023-08-17T11:26:59Z")

</div>

{ "version": 7, "cmakeMinimumRequired": { "major": 3, "minor": 27, "patch": 0 }, "configurePresets": \[ { "name": "default-config", "hidden": true, …

---

## [ExternalProject\_Add and CMAKE\_CONFIGURATION\_TYPES](https://discourse.cmake.org/t/externalproject-add-and-cmake-configuration-types/8744)

<div class="topic-metadata">

**Author:** [@MaxEd](https://discourse.cmake.org/u/MaxEd)\
**Replies:** 4\
**Last updated:** [August 16, 2023, 8:58am UTC](https://discourse.cmake.org/t/externalproject-add-and-cmake-configuration-types/8744 "2023-08-16T08:58:03Z")

</div>

I added an external project to my CMake file, and I wanted it to have the same set of configurations as the parent project. However, the generated project seems to have only one configuration - the default RelWithDebInfo…

---

## [How to remove -arch flag from arm-none-eabi-gcc in macos builds](https://discourse.cmake.org/t/how-to-remove-arch-flag-from-arm-none-eabi-gcc-in-macos-builds/7339)

<div class="topic-metadata">

**Author:** [@Girish](https://discourse.cmake.org/u/Girish)\
**Replies:** 4\
**Last updated:** [August 15, 2023, 3:05pm UTC](https://discourse.cmake.org/t/how-to-remove-arch-flag-from-arm-none-eabi-gcc-in-macos-builds/7339 "2023-08-15T15:05:00Z")

</div>

I am cross compiling using arm-none-eabi-gcc on MacOS (M1) with rosetta x86. It does not make sense to have -arch x86\_64b compilation flag as it gives error. v12 of arm-none-eabi-gcc (latest from brew) does not support …

---

## [CMake presets: What is a testpreset for?](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 3\
**Last updated:** [August 15, 2023, 2:08pm UTC](https://discourse.cmake.org/t/cmake-presets-what-is-a-testpreset-for/5404 "2023-08-15T14:08:44Z")

</div>

If you want to use the presets in an IDE, you only need the configurePresets , or not? If you do not know, what the binary directory is, you need the buildPresets too on console. And with the cmake --build builddirpat…

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

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