# Code

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

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

**Page:** 10

---

## [Install IMPORTED library and its lib file with IMPORTED\_RUNTIME\_ARTIFACTS](https://discourse.cmake.org/t/install-imported-library-and-its-lib-file-with-imported-runtime-artifacts/14050)

<div class="topic-metadata">

**Author:** [@Xnum](https://discourse.cmake.org/u/Xnum)\
**Replies:** 0\
**Last updated:** [May 6, 2025, 10:12am UTC](https://discourse.cmake.org/t/install-imported-library-and-its-lib-file-with-imported-runtime-artifacts/14050 "2025-05-06T10:12:55Z")

</div>

Hello everyone! I’ve got a cmake project where I build my static library, let’s call it “mylib”. This library depends on external .dll and the linking shouldn’t be done in cmake - it is done via LoadLibrary function in …

---

## [Best way to support Rust Language](https://discourse.cmake.org/t/best-way-to-support-rust-language/1108)

<div class="topic-metadata">

**Author:** [@yashi](https://discourse.cmake.org/u/yashi)\
**Replies:** 2\
**Last updated:** [May 6, 2025, 11:23am UTC](https://discourse.cmake.org/t/best-way-to-support-rust-language/1108 "2025-05-06T11:23:39Z")

</div>

By checking enable\_language(), CMake doesn’t seem to support Rust. What would be the current best way to mix Rust with C project? Especially most of the code is written in C but would like to use a few libraries writte…

---

## [Clarify the Documentation for CMAKE\_TRY\_COMPILE\_PLATFORM\_VARIABLES](https://discourse.cmake.org/t/clarify-the-documentation-for-cmake-try-compile-platform-variables/14040)

<div class="topic-metadata">

**Author:** [@trunketh](https://discourse.cmake.org/u/trunketh)\
**Replies:** 0\
**Last updated:** [May 4, 2025, 12:32pm UTC](https://discourse.cmake.org/t/clarify-the-documentation-for-cmake-try-compile-platform-variables/14040 "2025-05-04T12:32:36Z")

</div>

The documentation for CMAKE\_TRY\_COMPILE\_PLATFORM\_VARIABLES states (emphasis mine): Variables meaningful to CMake, such as CMAKE\_\<LANG\>\_FLAGS, are propagated automatically. The CMAKE\_TRY\_COMPILE\_PLATFORM\_VARIABLES varia…

---

## [find\_package() with a multi-config generated binary package](https://discourse.cmake.org/t/find-package-with-a-multi-config-generated-binary-package/13899)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 1\
**Last updated:** [May 2, 2025, 2:20am UTC](https://discourse.cmake.org/t/find-package-with-a-multi-config-generated-binary-package/13899 "2025-05-02T02:20:18Z")

</div>

I am struggling to figure out how to tie a package I can grab with find\_package() into my multi-configuration build (using Ninja Multi-Config). The package in question is a binary-only first-party library built by GraalV…

---

## [Building a MAC .app with more than one executable](https://discourse.cmake.org/t/building-a-mac-app-with-more-than-one-executable/13997)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 6\
**Last updated:** [April 29, 2025, 10:27am UTC](https://discourse.cmake.org/t/building-a-mac-app-with-more-than-one-executable/13997 "2025-04-29T10:27:35Z")

</div>

I would like to create a macOS .app containing a gui application and its command line equivalent. This is exactly the sort of thing that the CMake.app appears to do. How can I do this I initially thought to build the …

---

## [Why are DLL builds bottlenecked by Linker calls?](https://discourse.cmake.org/t/why-are-dll-builds-bottlenecked-by-linker-calls/13973)

<div class="topic-metadata">

**Author:** [@zachdanz](https://discourse.cmake.org/u/zachdanz)\
**Replies:** 2\
**Last updated:** [April 28, 2025, 11:03pm UTC](https://discourse.cmake.org/t/why-are-dll-builds-bottlenecked-by-linker-calls/13973 "2025-04-28T23:03:24Z")

</div>

Hey Cmake Community! We build our project statically as well as dynamically, and we have noticed that when building with DLLs, the build is severely bottlenecked compared to its static lib OPTIMIZE\_DEPENDENCIES — CMake …

---

## [Adding "stuff" to the SharedSupport folder of a MacOS bundle](https://discourse.cmake.org/t/adding-stuff-to-the-sharedsupport-folder-of-a-macos-bundle/13999)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 0\
**Last updated:** [April 28, 2025, 1:37pm UTC](https://discourse.cmake.org/t/adding-stuff-to-the-sharedsupport-folder-of-a-macos-bundle/13999 "2025-04-28T13:37:17Z")

</div>

What are the preferred ways to do this please? I can see that I could do things using add\_custom\_command (POST\_BUILD) but that feels a bit clumsy but if the things that need to be added also need to be built, I don’t se…

---

## [Generate header file containing the path to a build artifact for multi-config generators](https://discourse.cmake.org/t/generate-header-file-containing-the-path-to-a-build-artifact-for-multi-config-generators/13989)

<div class="topic-metadata">

**Author:** [@ottmar-zittlau](https://discourse.cmake.org/u/ottmar-zittlau)\
**Replies:** 1\
**Last updated:** [April 25, 2025, 7:12pm UTC](https://discourse.cmake.org/t/generate-header-file-containing-the-path-to-a-build-artifact-for-multi-config-generators/13989 "2025-04-25T19:12:43Z")

</div>

Hi, I have problems generating a file that contains a target\_file-generator expression. I reduced the issue to a small example: CMakeLists.txt cmake\_minimum\_required(VERSION 3.19) project(GenerateTest LANGUAGES CXX) …

---

## [How to control the MSVC CRT with cmake?](https://discourse.cmake.org/t/how-to-control-the-msvc-crt-with-cmake/13195)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 1\
**Last updated:** [April 25, 2025, 11:28am UTC](https://discourse.cmake.org/t/how-to-control-the-msvc-crt-with-cmake/13195 "2025-04-25T11:28:34Z")

</div>

I I need to use MSVC v140 toolchain and QT v8.8.7 with an old version of OpenSSL. Both does’t support to mix debug and release builds out of the box. Warning LNK2038: defaultlib '\*library\* ' conflicts with use of other…

---

## [Creating two separate packages with the same binary using components](https://discourse.cmake.org/t/creating-two-separate-packages-with-the-same-binary-using-components/13971)

<div class="topic-metadata">

**Author:** [@aludeck12](https://discourse.cmake.org/u/aludeck12)\
**Replies:** 0\
**Last updated:** [April 23, 2025, 2:40pm UTC](https://discourse.cmake.org/t/creating-two-separate-packages-with-the-same-binary-using-components/13971 "2025-04-23T14:40:38Z")

</div>

Hello, I am very new to packaging targets and files using components. My goal was that I want 2 different packages, that contain the same binary each and different files and based on which package is installed, the bin…

---

## [Installing CMake target containing C++20-Module without installing the compiled artifact](https://discourse.cmake.org/t/installing-cmake-target-containing-c-20-module-without-installing-the-compiled-artifact/13928)

<div class="topic-metadata">

**Author:** [@M2-TE](https://discourse.cmake.org/u/M2-TE)\
**Replies:** 1\
**Last updated:** [April 23, 2025, 11:16am UTC](https://discourse.cmake.org/t/installing-cmake-target-containing-c-20-module-without-installing-the-compiled-artifact/13928 "2025-04-23T11:16:00Z")

</div>

Given the target moduletarget add\_library(moduletarget) target\_sources(moduletarget PUBLIC FILE\_SET module TYPE CXX\_MODULES FILES "some/module/source.cppm") installing the target will also install the libmo…

---

## [Unwanted quotes in extra compile options for a specific Fortran source](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778)

<div class="topic-metadata">

**Author:** [@artu72](https://discourse.cmake.org/u/artu72)\
**Replies:** 8\
**Last updated:** [April 15, 2025, 2:17pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778 "2025-04-15T14:17:53Z")

</div>

Hi, in my Fortran project I need to add some extra compilation flag for a given source file cklib.f I used the command set\_source\_files\_properties(src/cklib.f PROPERTIES COMPILE\_OPTIONS "-warn nointerfaces") It insert…

---

## [Code Injection with Language Information?](https://discourse.cmake.org/t/code-injection-with-language-information/13907)

<div class="topic-metadata">

**Author:** [@Naville](https://discourse.cmake.org/u/Naville)\
**Replies:** 0\
**Last updated:** [April 10, 2025, 11:03am UTC](https://discourse.cmake.org/t/code-injection-with-language-information/13907 "2025-04-10T11:03:13Z")

</div>

Hi: I’m reading https://cmake.org/cmake/help/latest/command/project.html#code-injection But it seems to me that there isn’t a hook for: - Toolchain is read and compilers setup - Languages has been enabled - No targets h…

---

## [packaging an imported, but first-party, library](https://discourse.cmake.org/t/packaging-an-imported-but-first-party-library/13698)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 1\
**Last updated:** [April 8, 2025, 2:14pm UTC](https://discourse.cmake.org/t/packaging-an-imported-but-first-party-library/13698 "2025-04-08T14:14:44Z")

</div>

In my product, we have a C++ library which depends on a library produced by Graal VM’s native-image tool. Effectively, a binary-only dependency. We build that from a set of Java sources. I can get CMake to correctly bui…

---

## [How to export environment variables globally?](https://discourse.cmake.org/t/how-to-export-environment-variables-globally/13892)

<div class="topic-metadata">

**Author:** [@CsatiZoltan](https://discourse.cmake.org/u/CsatiZoltan)\
**Replies:** 4\
**Last updated:** [April 8, 2025, 8:53am UTC](https://discourse.cmake.org/t/how-to-export-environment-variables-globally/13892 "2025-04-08T08:53:17Z")

</div>

Hi, I have a C++ project with Doxygen documentation. I set variables in the CMake script, such as set(P4LBM\_HOME ${CMAKE\_CURRENT\_SOURCE\_DIR}) set(P4LBM\_DOC ${P4LBM\_HOME}/docs) add\_custom\_target(docs COMMAND ${D…

---

## [Adding two macOS .app directories to a bundle](https://discourse.cmake.org/t/adding-two-macos-app-directories-to-a-bundle/13878)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 0\
**Last updated:** [April 3, 2025, 8:06pm UTC](https://discourse.cmake.org/t/adding-two-macos-app-directories-to-a-bundle/13878 "2025-04-03T20:06:30Z")

</div>

I am using CMake’s Bundle to install my single application. However, I have now developed a new one. For Linux and Windows it is no issue as they can both live in the bin folder. However, for macOS, I would like, for …

---

## [Execute Command Post Build - CMake / ESP-IDF (VS-Code with PIO)](https://discourse.cmake.org/t/execute-command-post-build-cmake-esp-idf-vs-code-with-pio/13869)

<div class="topic-metadata">

**Author:** [@K0I05](https://discourse.cmake.org/u/K0I05)\
**Replies:** 9\
**Last updated:** [April 3, 2025, 7:51pm UTC](https://discourse.cmake.org/t/execute-command-post-build-cmake-esp-idf-vs-code-with-pio/13869 "2025-04-03T19:51:11Z")

</div>

I’ve posted this in the esp-idf and platformio forums and am getting limited feedback. Hopefully, someone can help or point me in the right direction. I am using VS-Code with PlatformIO, developing with the ESP-IDF fra…

---

## [Remove the inner dependency when linked into the final target.](https://discourse.cmake.org/t/remove-the-inner-dependency-when-linked-into-the-final-target/13857)

<div class="topic-metadata">

**Author:** [@co-neco](https://discourse.cmake.org/u/co-neco)\
**Replies:** 0\
**Last updated:** [March 31, 2025, 3:56am UTC](https://discourse.cmake.org/t/remove-the-inner-dependency-when-linked-into-the-final-target/13857 "2025-03-31T03:56:42Z")

</div>

Hello, I want to build a shared library as follow on windows with VS generator: add\_library(A STATIC a.cpp) add\_library(B STATIC b.cpp) target\_link\_libraries(B PRIVATE A) add\_library(Dyn SHARED xx $\<TARGET\_OBJ…

---

## [How to include "WIN32" in an "add\_executable()" command only on Windows?](https://discourse.cmake.org/t/how-to-include-win32-in-an-add-executable-command-only-on-windows/13852)

<div class="topic-metadata">

**Author:** [@fishnet37222](https://discourse.cmake.org/u/fishnet37222)\
**Replies:** 2\
**Last updated:** [March 29, 2025, 9:12pm UTC](https://discourse.cmake.org/t/how-to-include-win32-in-an-add-executable-command-only-on-windows/13852 "2025-03-29T21:12:13Z")

</div>

I currently have the following block of code in my CMakeLists.txt file. What I’d like to be able to do is have just one “add\_executable()” command and still have the “WIN32” keyword included only on Windows. if(${WIN32…

---

## [CMP0143 seemingly not working, how to debug?](https://discourse.cmake.org/t/cmp0143-seemingly-not-working-how-to-debug/13828)

<div class="topic-metadata">

**Author:** [@aursulis](https://discourse.cmake.org/u/aursulis)\
**Replies:** 3\
**Last updated:** [March 27, 2025, 10:37pm UTC](https://discourse.cmake.org/t/cmp0143-seemingly-not-working-how-to-debug/13828 "2025-03-27T22:37:42Z")

</div>

Hi there, a colleague of mine was upgrading our CMake version from 3.24.2 to 3.31.6 (along with all the policy changes) and we stumbled upon some strange behaviour with the USE\_FOLDERS property which should now default t…

---

## [Adding cxx sources to swig\_add\_library](https://discourse.cmake.org/t/adding-cxx-sources-to-swig-add-library/13838)

<div class="topic-metadata">

**Author:** [@stanprogram](https://discourse.cmake.org/u/stanprogram)\
**Replies:** 2\
**Last updated:** [March 27, 2025, 3:04pm UTC](https://discourse.cmake.org/t/adding-cxx-sources-to-swig-add-library/13838 "2025-03-27T15:04:54Z")

</div>

What is the correct way to add additional cxx sources with swig\_add\_library? I am having trouble building an example for myself. It seems like what I am doing should work. CMakeLists.txt: cmake\_minimum\_required(VERSIO…

---

## [How $\<LINK\_ONLY:...\> really works?](https://discourse.cmake.org/t/how-link-only-really-works/10673)

<div class="topic-metadata">

**Author:** [@silverqx](https://discourse.cmake.org/u/silverqx)\
**Replies:** 3\
**Last updated:** [April 16, 2024, 8:23pm UTC](https://discourse.cmake.org/t/how-link-only-really-works/10673 "2024-04-16T20:23:48Z")

</div>

I need to understand this $\<LINK\_ONLY:...\> genex in INTERFACE\_LINK\_LIBRARIES in the package config file. I don’t understand what is written in the documentation. Content of …, except while collecting Transitive Usage …

---

## [check\_symbol\_exists() and #define](https://discourse.cmake.org/t/check-symbol-exists-and-define/13820)

<div class="topic-metadata">

**Author:** [@pol2095](https://discourse.cmake.org/u/pol2095)\
**Replies:** 14\
**Last updated:** [March 26, 2025, 2:59pm UTC](https://discourse.cmake.org/t/check-symbol-exists-and-define/13820 "2025-03-26T14:59:55Z")

</div>

Hello, I try to detect a #define in a header file : #define USAGE\_QUALITY 0u using list(APPEND CMAKE\_REQUIRED\_INCLUDES ${TEST\_INCLUDE\_DIR}) check\_symbol\_exists(USAGE\_QUALITY test/test.h usage\_flag\_exists) but usage\_…

---

## [Toolchain with shipped older cmake conflicts with outer newer one](https://discourse.cmake.org/t/toolchain-with-shipped-older-cmake-conflicts-with-outer-newer-one/13825)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 0\
**Last updated:** [March 26, 2025, 12:11pm UTC](https://discourse.cmake.org/t/toolchain-with-shipped-older-cmake-conflicts-with-outer-newer-one/13825 "2025-03-26T12:11:09Z")

</div>

Upgrading my cmake I have a few old (Yocto for instance) toolchains now blowing up as there is an older cmake within the toolchain that takes precedence. I.e the mininum required version is not met. Is there a setting t…

---

## [How to use a module BMI built outside of CMake to build module and executable](https://discourse.cmake.org/t/how-to-use-a-module-bmi-built-outside-of-cmake-to-build-module-and-executable/13616)

<div class="topic-metadata">

**Author:** [@rmerriam](https://discourse.cmake.org/u/rmerriam)\
**Replies:** 5\
**Last updated:** [March 19, 2025, 9:49pm UTC](https://discourse.cmake.org/t/how-to-use-a-module-bmi-built-outside-of-cmake-to-build-module-and-executable/13616 "2025-03-19T21:49:03Z")

</div>

I’m on Ubuntu 24.04 with both GCC and Clang. I can build modules from the command line, with CMake, and inside CLion. I’m working to include “print” from the std but not the entire std. It builds on the command line to c…

---

## [Detecting if a target has CUDA sources with separable compilation](https://discourse.cmake.org/t/detecting-if-a-target-has-cuda-sources-with-separable-compilation/13767)

<div class="topic-metadata">

**Author:** [@pcanal](https://discourse.cmake.org/u/pcanal)\
**Replies:** 8\
**Last updated:** [March 18, 2025, 4:01pm UTC](https://discourse.cmake.org/t/detecting-if-a-target-has-cuda-sources-with-separable-compilation/13767 "2025-03-18T16:01:43Z")

</div>

In the context of this project: GitHub - celeritas-project/CudaRdcUtils: CMake utility functions for building and linking libraries containing CUDA relocatable device code that help solve the NVidia Relocatable Device C…

---

## [How to run \`add\_custom\_target\` when source file changes](https://discourse.cmake.org/t/how-to-run-add-custom-target-when-source-file-changes/13763)

<div class="topic-metadata">

**Author:** [@buildtool](https://discourse.cmake.org/u/buildtool)\
**Replies:** 1\
**Last updated:** [March 17, 2025, 12:41pm UTC](https://discourse.cmake.org/t/how-to-run-add-custom-target-when-source-file-changes/13763 "2025-03-17T12:41:17Z")

</div>

How do I ensure that when a source file changes, the custom target with command is re-run? This is what I’m using add\_custom\_target("gen\_code" COMMAND run.py ${INPUT\_FILE} -o ${OUTPUT\_FILE} SOURCES ${INPUT\_FILE…

---

## [Is it appropriate to use enable\_language in a CMake package file?](https://discourse.cmake.org/t/is-it-appropriate-to-use-enable-language-in-a-cmake-package-file/4335)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 3\
**Last updated:** [March 17, 2025, 8:22am UTC](https://discourse.cmake.org/t/is-it-appropriate-to-use-enable-language-in-a-cmake-package-file/4335 "2025-03-17T08:22:22Z")

</div>

We have a library that has a pure-C interface, but is partially written in C++ and uses OpenMP. We generate a CMake package file for this library, so other CMake projects can easily use it. However, when a C language pr…

---

## [Adding openssl.xcframework to XCode using CMake](https://discourse.cmake.org/t/adding-openssl-xcframework-to-xcode-using-cmake/11035)

<div class="topic-metadata">

**Author:** [@puneet\_gurtoo](https://discourse.cmake.org/u/puneet_gurtoo)\
**Replies:** 1\
**Last updated:** [March 13, 2025, 10:11pm UTC](https://discourse.cmake.org/t/adding-openssl-xcframework-to-xcode-using-cmake/11035 "2025-03-13T22:11:02Z")

</div>

I have created a static xcframework for openssl to use in one of my iOS projects. Have attached the screenshot with structure of xcframework. Can we link this to XCode project using CMake ? Is this supported by CMake no…

---

## [cygwin cmake failing with windows-style path names not found](https://discourse.cmake.org/t/cygwin-cmake-failing-with-windows-style-path-names-not-found/11005)

<div class="topic-metadata">

**Author:** [@phrodod](https://discourse.cmake.org/u/phrodod)\
**Replies:** 4\
**Last updated:** [March 13, 2025, 9:54pm UTC](https://discourse.cmake.org/t/cygwin-cmake-failing-with-windows-style-path-names-not-found/11005 "2025-03-13T21:54:41Z")

</div>

I’ve got a multi-language project building both C++ and Java executables. I’ve managed to get this working on a really old Linux (CentOS 7.9) system, and now am trying to build on Windows using Cygwin (this is a code tha…

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

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