# Code

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

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

**Page:** 38

---

## [Best way to support different CUDA version](https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313)

<div class="topic-metadata">

**Author:** [@GiovaBx](https://discourse.cmake.org/u/GiovaBx)\
**Replies:** 1\
**Last updated:** [January 25, 2023, 4:48pm UTC](https://discourse.cmake.org/t/best-way-to-support-different-cuda-version/7313 "2023-01-25T16:48:18Z")

</div>

Hi all, I’m moving some of our internal libraries that use CUDA to cmake to generate a solution for Visual Studio (and then create conan packages from them). I need to support different versions of CUDA (at the moment …

---

## [Extend list of file extensions for a LANGUAGE globally (for the whole project)](https://discourse.cmake.org/t/extend-list-of-file-extensions-for-a-language-globally-for-the-whole-project/7307)

<div class="topic-metadata">

**Author:** [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Replies:** 6\
**Last updated:** [January 24, 2023, 1:27am UTC](https://discourse.cmake.org/t/extend-list-of-file-extensions-for-a-language-globally-for-the-whole-project/7307 "2023-01-24T01:27:44Z")

</div>

In a fairly large project I’m converting over to CMake there are lots of files with .rcv extensions that are actually RC files (windows resource). How I can tell CMake to treat all such files as RC files without setting …

---

## [C# csproj \<None\> tool, VS\_TOOL\_OVERRIDE not working](https://discourse.cmake.org/t/c-csproj-none-tool-vs-tool-override-not-working/7249)

<div class="topic-metadata">

**Author:** [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Replies:** 3\
**Last updated:** [January 23, 2023, 6:10pm UTC](https://discourse.cmake.org/t/c-csproj-none-tool-vs-tool-override-not-working/7249 "2023-01-23T18:10:20Z")

</div>

I’m using CMake to convert an old project having C# project files, and in them there are a couple file using the \<None …\> tool, effectively disabling them from build. I saw the VS\_TOOL\_OVERRIDE property (https://cmake.or…

---

## [Cross compile the same library](https://discourse.cmake.org/t/cross-compile-the-same-library/7309)

<div class="topic-metadata">

**Author:** [@Samega7Cattac](https://discourse.cmake.org/u/Samega7Cattac)\
**Replies:** 1\
**Last updated:** [January 23, 2023, 5:38pm UTC](https://discourse.cmake.org/t/cross-compile-the-same-library/7309 "2023-01-23T17:38:55Z")

</div>

I’m trying to cross compile my libs with the objective to create a package (just a zip) with with the same lib but in different cpu arch. So I want to compile the same target but with a diff compiler to target a diff ar…

---

## [FILE(COPY header\_set) or file\_set](https://discourse.cmake.org/t/file-copy-header-set-or-file-set/7282)

<div class="topic-metadata">

**Author:** [@jk000](https://discourse.cmake.org/u/jk000)\
**Replies:** 4\
**Last updated:** [January 23, 2023, 12:30am UTC](https://discourse.cmake.org/t/file-copy-header-set-or-file-set/7282 "2023-01-23T00:30:36Z")

</div>

It would be useful to be able to copy a file\_set to the build tree so other targets could depend on it. In the case where header files are installed in a specific directory layout different from the source tree, this wo…

---

## [C++ - Reuse PCH accross static libraries](https://discourse.cmake.org/t/c-reuse-pch-accross-static-libraries/7305)

<div class="topic-metadata">

**Author:** [@Glad](https://discourse.cmake.org/u/Glad)\
**Replies:** 1\
**Last updated:** [January 22, 2023, 5:56pm UTC](https://discourse.cmake.org/t/c-reuse-pch-accross-static-libraries/7305 "2023-01-22T17:56:34Z")

</div>

Hi, I would like to generate precompiled headers and reuse them in static libraries, to avoid having n times the same pch, generated locally. Here the structure: -- root\_folder -- pch\_lib -- build …

---

## [Installing Dependencies.](https://discourse.cmake.org/t/installing-dependencies/7242)

<div class="topic-metadata">

**Author:** [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Replies:** 5\
**Last updated:** [January 22, 2023, 12:16am UTC](https://discourse.cmake.org/t/installing-dependencies/7242 "2023-01-22T00:16:11Z")

</div>

I am trying to use the RUNTIME\_DEPENDENCY system to install the shared libraries and dlls that have been linked to in my project. But just those. Our build server puts our builds in an opt folder, either /opt or c:/opt …

---

## [Please Help CPMAddPackage install zlib in build directory](https://discourse.cmake.org/t/please-help-cpmaddpackage-install-zlib-in-build-directory/7286)

<div class="topic-metadata">

**Author:** [@john](https://discourse.cmake.org/u/john)\
**Replies:** 1\
**Last updated:** [January 21, 2023, 5:19pm UTC](https://discourse.cmake.org/t/please-help-cpmaddpackage-install-zlib-in-build-directory/7286 "2023-01-21T17:19:26Z")

</div>

Please help, I have been trying to figure out a way to download and compile zlib in a build directory via CPMAddPackage with Cmake 3.25.1. The reason is that I don’t want the user to need to have zlib previously install…

---

## [Restricting target\_precompile\_headers to one language?](https://discourse.cmake.org/t/restricting-target-precompile-headers-to-one-language/7284)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 0\
**Last updated:** [January 19, 2023, 7:52pm UTC](https://discourse.cmake.org/t/restricting-target-precompile-headers-to-one-language/7284 "2023-01-19T19:52:00Z")

</div>

Attempting to use target\_precompile\_headers with a long list of C+±only header files for a C+±only target in a multi-language project. Is it possible to tell CMake that a given target only uses a specific subset of the …

---

## [Looking for complete examples of cross platform projects](https://discourse.cmake.org/t/looking-for-complete-examples-of-cross-platform-projects/4731)

<div class="topic-metadata">

**Author:** [@obushnell](https://discourse.cmake.org/u/obushnell)\
**Replies:** 18\
**Last updated:** [January 18, 2023, 8:17pm UTC](https://discourse.cmake.org/t/looking-for-complete-examples-of-cross-platform-projects/4731 "2023-01-18T20:17:12Z")

</div>

Me and my colleagues are using CMake 3.20 to build cross platform projects. We can make it build and deploy on Windows, with some manual effort. We can’t get it to build on the other platforms without breaking the Window…

---

## [Ccache clang and -fno-pch-timestamp](https://discourse.cmake.org/t/ccache-clang-and-fno-pch-timestamp/7253)

<div class="topic-metadata">

**Author:** [@silverqx](https://discourse.cmake.org/u/silverqx)\
**Replies:** 5\
**Last updated:** [January 18, 2023, 7:36am UTC](https://discourse.cmake.org/t/ccache-clang-and-fno-pch-timestamp/7253 "2023-01-18T07:36:37Z")

</div>

The latest ccache recommends adding -fno-pch-timestamp to the Clang compile command for PCH, but I can’t find anywhere how to do it in CMake. I’m creating precompiled header like this: target\_precompile\_headers(${TinyO…

---

## [Loading .SO file using CMAKE](https://discourse.cmake.org/t/loading-so-file-using-cmake/7252)

<div class="topic-metadata">

**Author:** [@Jubin2607](https://discourse.cmake.org/u/Jubin2607)\
**Replies:** 5\
**Last updated:** [January 17, 2023, 4:55pm UTC](https://discourse.cmake.org/t/loading-so-file-using-cmake/7252 "2023-01-17T16:55:33Z")

</div>

I am facing an issue while loading a .SO file using cmake The error which I am getting is “undefined reference to” some function which I am accessing while building Compilation of the code is proper.

---

## [CMAKE\_CXX\_FLAGS - removing defaults, yet allowing user-specified values](https://discourse.cmake.org/t/cmake-cxx-flags-removing-defaults-yet-allowing-user-specified-values/7238)

<div class="topic-metadata">

**Author:** [@hainest](https://discourse.cmake.org/u/hainest)\
**Replies:** 1\
**Last updated:** [January 15, 2023, 2:50am UTC](https://discourse.cmake.org/t/cmake-cxx-flags-removing-defaults-yet-allowing-user-specified-values/7238 "2023-01-15T02:50:06Z")

</div>

I would like to remove the default values from CMAKE\_CXX\_FLAGS while still allowing users to specify values in configuration mode (i.e., cmake ... -DCMAKE\_CXX\_FLAGS="..."). Clearly, this could be done by just writing to…

---

## [Find Module script can’t find packages installed with MacPorts](https://discourse.cmake.org/t/find-module-script-can-t-find-packages-installed-with-macports/7244)

<div class="topic-metadata">

**Author:** [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)\
**Replies:** 1\
**Last updated:** [January 15, 2023, 2:44am UTC](https://discourse.cmake.org/t/find-module-script-can-t-find-packages-installed-with-macports/7244 "2023-01-15T02:44:09Z")

</div>

I’ve been struggling with a seemingly simple problem. My CMakeLists.txt looks for a package named “Proj”, with find\_package() and third-party-provided FindProj.cmake, but is unable to find it on MacOS when the package ha…

---

## [Determinate os platform](https://discourse.cmake.org/t/determinate-os-platform/7218)

<div class="topic-metadata">

**Author:** [@Samega7Cattac](https://discourse.cmake.org/u/Samega7Cattac)\
**Replies:** 5\
**Last updated:** [January 11, 2023, 5:18pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218 "2023-01-11T17:18:11Z")

</div>

hi, I’m trying to determinate the os platform that is being used so I can create a definition and pass it to my code. From what I checked from old mails (~2011). It is possible by checking the size of void like so: i…

---

## [try\_compile/try\_run link against target](https://discourse.cmake.org/t/try-compile-try-run-link-against-target/7189)

<div class="topic-metadata">

**Author:** [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Replies:** 10\
**Last updated:** [January 7, 2023, 2:49pm UTC](https://discourse.cmake.org/t/try-compile-try-run-link-against-target/7189 "2023-01-07T14:49:22Z")

</div>

I’m executing a try\_run command where I need to link against a target. My initial hope was that it would act like target\_link\_libraries and take things like the include directories and compiler flags and add them to the …

---

## [Best practice for finding dlls from the buildtree](https://discourse.cmake.org/t/best-practice-for-finding-dlls-from-the-buildtree/7201)

<div class="topic-metadata">

**Author:** [@neundorf](https://discourse.cmake.org/u/neundorf)\
**Replies:** 1\
**Last updated:** [January 4, 2023, 11:32pm UTC](https://discourse.cmake.org/t/best-practice-for-finding-dlls-from-the-buildtree/7201 "2023-01-04T23:32:38Z")

</div>

Hi, I’m used to RPATH under Linux, which makes running executables in the build tree simple under Linux. Whatever shared libs have been linked, the executable will find them via RPATH. AFAIK such a feature still does…

---

## [Best way of adding compiler flags in toolchain](https://discourse.cmake.org/t/best-way-of-adding-compiler-flags-in-toolchain/6452)

<div class="topic-metadata">

**Author:** [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Replies:** 5\
**Last updated:** [January 4, 2023, 9:43pm UTC](https://discourse.cmake.org/t/best-way-of-adding-compiler-flags-in-toolchain/6452 "2023-01-04T21:43:20Z")

</div>

I’m writing a toolchain file to cross-compile and I need to set some compiler flags (e.g. -arch x86\_64). Now I’m wondering what the best way is to add those flags. It works if I use add\_compile\_options and add\_link\_opt…

---

## [How to modify a cmake variable based on whether "install" has been specified on command line](https://discourse.cmake.org/t/how-to-modify-a-cmake-variable-based-on-whether-install-has-been-specified-on-command-line/7195)

<div class="topic-metadata">

**Author:** [@surfmich](https://discourse.cmake.org/u/surfmich)\
**Replies:** 1\
**Last updated:** [January 4, 2023, 2:14pm UTC](https://discourse.cmake.org/t/how-to-modify-a-cmake-variable-based-on-whether-install-has-been-specified-on-command-line/7195 "2023-01-04T14:14:09Z")

</div>

I am using header file generated by configure\_file() to specify a path to a json file which is parsed by my c++ application. In my CMakeLists.txt file I set a CMake variable equal to the path I want which is used in the…

---

## [Wait for execute\_process to finish](https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191)

<div class="topic-metadata">

**Author:** [@some\_name](https://discourse.cmake.org/u/some_name)\
**Replies:** 1\
**Last updated:** [January 4, 2023, 2:10pm UTC](https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191 "2023-01-04T14:10:12Z")

</div>

My project depends on external libraries such as Boost, GTest, and GMock. I am providing a facility wherein a user can pass a variable BINARY\_ROOT from the command line, and if FindBoost, FindGTest etc fail, it will auto…

---

## [using cpack with install of auxiliary includes/libraries like those of ExternalProject\_Add](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 5\
**Last updated:** [January 4, 2023, 2:08pm UTC](https://discourse.cmake.org/t/using-cpack-with-install-of-auxiliary-includes-libraries-like-those-of-externalproject-add/6669 "2023-01-04T14:08:21Z")

</div>

I have a project that depends on a git submodule and several static libraries that are built with add\_subdirectory and they all have install commands to install the libraries and header files in CMAKE\_INSTALL\_PREFIX/lib,…

---

## [link option wrong with -latomic](https://discourse.cmake.org/t/link-option-wrong-with-latomic/7173)

<div class="topic-metadata">

**Author:** [@dglz.hyj](https://discourse.cmake.org/u/dglz.hyj)\
**Replies:** 2\
**Last updated:** [January 4, 2023, 11:38am UTC](https://discourse.cmake.org/t/link-option-wrong-with-latomic/7173 "2023-01-04T11:38:54Z")

</div>

\#include "thread" #include "iostream" #include "atomic" using namespace std; struct A { int a\[100\]; }; struct B { int x, y; }; int main() { std::atomic\<A\> Ap ; std::atomic\<B\> Bp ; std::cout \<\< std::boolalp…

---

## [A install directory depends on custom command](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171)

<div class="topic-metadata">

**Author:** [@bradbell](https://discourse.cmake.org/u/bradbell)\
**Replies:** 5\
**Last updated:** [January 4, 2023, 8:38am UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171 "2023-01-04T08:38:13Z")

</div>

I am installing a directory that is created by a custom command. How do I make that step in the install depend on first executing the custom comamnd ?

---

## [Undefined refence ?????](https://discourse.cmake.org/t/undefined-refence/7166)

<div class="topic-metadata">

**Author:** [@Eric\_THIB](https://discourse.cmake.org/u/Eric_THIB)\
**Replies:** 3\
**Last updated:** [January 3, 2023, 10:09pm UTC](https://discourse.cmake.org/t/undefined-refence/7166 "2023-01-03T22:09:22Z")

</div>

Hello ! I have an issue with cmake (I’m a beginner) I don’t really know how to express my problem since I don’t know the terms and since english is not my mother language… but basically I can’t get my project to compile …

---

## [How to get access cmake variable in a header file](https://discourse.cmake.org/t/how-to-get-access-cmake-variable-in-a-header-file/7125)

<div class="topic-metadata">

**Author:** [@surfmich](https://discourse.cmake.org/u/surfmich)\
**Replies:** 3\
**Last updated:** [January 3, 2023, 10:08pm UTC](https://discourse.cmake.org/t/how-to-get-access-cmake-variable-in-a-header-file/7125 "2023-01-03T22:08:23Z")

</div>

I want want to access a cmake variable in a header file. I was able to use add\_compile\_definition() to create a preprocessor definition based on a cmake variable that I could use in a cpp file, but when I try the same m…

---

## [Handle custom Findfoo.cmake in dependency](https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178)

<div class="topic-metadata">

**Author:** [@skcusekamc](https://discourse.cmake.org/u/skcusekamc)\
**Replies:** 1\
**Last updated:** [January 3, 2023, 12:03am UTC](https://discourse.cmake.org/t/handle-custom-findfoo-cmake-in-dependency/7178 "2023-01-03T00:03:17Z")

</div>

For my library bla I have a Config.cmake.in that does a find\_dependency(foo) because bla depends on foo and by using find\_dependency(foo) I can propogate this dependency to any project that uses bla via find\_package(bla …

---

## [Installation Qt6 Qml Application Cross Plattform](https://discourse.cmake.org/t/installation-qt6-qml-application-cross-plattform/7110)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 10\
**Last updated:** [January 2, 2023, 8:23am UTC](https://discourse.cmake.org/t/installation-qt6-qml-application-cross-plattform/7110 "2023-01-02T08:23:33Z")

</div>

Hi, for my Qt6 Qml Application I want to create installers for all major platforms (Linux, Mac Os, Windows). I do already have a working cmake files which handles the non Qt6 part of my application. Additionally I also…

---

## [cannot use CMAKE\_SOURCE\_DIR in toolchain file](https://discourse.cmake.org/t/cannot-use-cmake-source-dir-in-toolchain-file/546)

<div class="topic-metadata">

**Author:** [@Tokra](https://discourse.cmake.org/u/Tokra)\
**Replies:** 5\
**Last updated:** [January 1, 2023, 1:02am UTC](https://discourse.cmake.org/t/cannot-use-cmake-source-dir-in-toolchain-file/546 "2023-01-01T01:02:07Z")

</div>

When trying to include something from CMAKE\_SOURCE\_DIR in a toolchain-file, cmake seems to make a flat copy of the file for compiler-tests, then /CMakeFiles/CMakeTmp/CMakeLists.txt:3 cannot find the include-file in /CMak…

---

## [CPMAddPackage lib](https://discourse.cmake.org/t/cpmaddpackage-lib/7128)

<div class="topic-metadata">

**Author:** [@john](https://discourse.cmake.org/u/john)\
**Replies:** 1\
**Last updated:** [December 26, 2022, 2:36pm UTC](https://discourse.cmake.org/t/cpmaddpackage-lib/7128 "2022-12-26T14:36:04Z")

</div>

Hello all, I am fairly new to CMake but am interested in using the CMake Package Management (CPM) to add a local library/source files. My question is probably simple, so please forgive. I would like to know how to down…

---

## [Community practices for platform/compiler specific compiler options](https://discourse.cmake.org/t/community-practices-for-platform-compiler-specific-compiler-options/7104)

<div class="topic-metadata">

**Author:** [@some\_name](https://discourse.cmake.org/u/some_name)\
**Replies:** 4\
**Last updated:** [December 25, 2022, 1:05pm UTC](https://discourse.cmake.org/t/community-practices-for-platform-compiler-specific-compiler-options/7104 "2022-12-25T13:05:44Z")

</div>

I would like to build my project under Windows using Visual Studio 2022, and under Linux using Clang and Gcc. For each case, I have a set of options that I would like to apply to the entire project. I would like to know …

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

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