# Code

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

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

**Page:** 29

---

## [OpenACC + CUDA + CMake](https://discourse.cmake.org/t/openacc-cuda-cmake/9317)

<div class="topic-metadata">

**Author:** [@mihaly\_sisak\_conti](https://discourse.cmake.org/u/mihaly_sisak_conti)\
**Replies:** 1\
**Last updated:** [November 2, 2023, 9:16pm UTC](https://discourse.cmake.org/t/openacc-cuda-cmake/9317 "2023-11-02T21:16:38Z")

</div>

New users can not upload attachements, so I linked them here: https://forums.developer.nvidia.com/t/openacc-cuda-interop-with-cmake/270794/4?u=janos.mihaly.sisak We would like to use C with OpenACC pragmas and CUDA ker…

---

## [CMAKE include PATHS causing trouble for linux cross compiling for arm64 (Raspberry pi)](https://discourse.cmake.org/t/cmake-include-paths-causing-trouble-for-linux-cross-compiling-for-arm64-raspberry-pi/9314)

<div class="topic-metadata">

**Author:** [@Ole](https://discourse.cmake.org/u/Ole)\
**Replies:** 6\
**Last updated:** [November 2, 2023, 3:43am UTC](https://discourse.cmake.org/t/cmake-include-paths-causing-trouble-for-linux-cross-compiling-for-arm64-raspberry-pi/9314 "2023-11-02T03:43:07Z")

</div>

Hi I am creating programs in C++ for my Raspberry Pi Pico W on my dev machine, which is a Raspberry Pi 400 running Linux. The problem, I am going to describe is exactly the same whether I am working on a Raspberry PI OS…

---

## [Add interface library but I want to copy my .dll in the same CMake](https://discourse.cmake.org/t/add-interface-library-but-i-want-to-copy-my-dll-in-the-same-cmake/9319)

<div class="topic-metadata">

**Author:** [@monisse](https://discourse.cmake.org/u/monisse)\
**Replies:** 1\
**Last updated:** [November 1, 2023, 3:25am UTC](https://discourse.cmake.org/t/add-interface-library-but-i-want-to-copy-my-dll-in-the-same-cmake/9319 "2023-11-01T03:25:09Z")

</div>

Hello everyone, I’m currently doing a library that can be add in every project and just working directly without adding anything. My project is quit easy, it’s just some header file, a .lib and a .dll, so nothing to co…

---

## [How to add resources to MacOS Bundle](https://discourse.cmake.org/t/how-to-add-resources-to-macos-bundle/9323)

<div class="topic-metadata">

**Author:** [@julcs](https://discourse.cmake.org/u/julcs)\
**Replies:** 2\
**Last updated:** [October 31, 2023, 9:11pm UTC](https://discourse.cmake.org/t/how-to-add-resources-to-macos-bundle/9323 "2023-10-31T21:11:26Z")

</div>

Currently I add resources like this: cmake\_minimum\_required(VERSION 3.26) project(Example VERSION 1.0 LANGUAGES CXX C) set(SRC src/main.cpp ) set(SHADERS shaders/example.frag ) set(MODELS models/cube.obj ) …

---

## [c++ library with cmake](https://discourse.cmake.org/t/c-library-with-cmake/9322)

<div class="topic-metadata">

**Author:** [@superdu](https://discourse.cmake.org/u/superdu)\
**Replies:** 1\
**Last updated:** [October 31, 2023, 5:47pm UTC](https://discourse.cmake.org/t/c-library-with-cmake/9322 "2023-10-31T17:47:17Z")

</div>

Hello every one, I’m doing my first library (shared and static) in C++ with cmake. The idea is i could just compile it and install it as all other libraries to include it to other projects My project have this structu…

---

## [How to check for incorrect dependencies when using add\_custom\_command?](https://discourse.cmake.org/t/how-to-check-for-incorrect-dependencies-when-using-add-custom-command/9267)

<div class="topic-metadata">

**Author:** [@Griffon26](https://discourse.cmake.org/u/Griffon26)\
**Replies:** 4\
**Last updated:** [October 31, 2023, 2:41pm UTC](https://discourse.cmake.org/t/how-to-check-for-incorrect-dependencies-when-using-add-custom-command/9267 "2023-10-31T14:41:43Z")

</div>

Recently I have discovered that I have a problem in my CMake file that can lead to a generator for source files being run while the sources are being compiled. I think I know how to fix this instance, but what I am looki…

---

## [CMake ignores missing required package](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290)

<div class="topic-metadata">

**Author:** [@benschreiber](https://discourse.cmake.org/u/benschreiber)\
**Replies:** 4\
**Last updated:** [October 31, 2023, 12:32am UTC](https://discourse.cmake.org/t/cmake-ignores-missing-required-package/9290 "2023-10-31T00:32:03Z")

</div>

I have a required dependency Bar. Even if Bar is not found, CMake finishes configuring without error. CMakeLists.txt cmake\_minimum\_required(VERSION 3.27) project(Foo) set(CMAKE\_MODULE\_PATH "${Foo\_SOURCE\_DIR}") find\_pa…

---

## [Looking for help improving CMake configure time](https://discourse.cmake.org/t/looking-for-help-improving-cmake-configure-time/9313)

<div class="topic-metadata">

**Author:** [@samuelpmish](https://discourse.cmake.org/u/samuelpmish)\
**Replies:** 3\
**Last updated:** [October 31, 2023, 12:24am UTC](https://discourse.cmake.org/t/looking-for-help-improving-cmake-configure-time/9313 "2023-10-31T00:24:02Z")

</div>

Hi, I’m looking for help on how to reduce cmake configure time for a C++ project. This project takes about 10s to configure, and when profiling with --profiling-format=google-trace --profiling-output=cmake-configuratio…

---

## [cmake 3.28 and importing C++ headers in gcc](https://discourse.cmake.org/t/cmake-3-28-and-importing-c-headers-in-gcc/9311)

<div class="topic-metadata">

**Author:** [@John\_Fourkiotis](https://discourse.cmake.org/u/John_Fourkiotis)\
**Replies:** 5\
**Last updated:** [October 30, 2023, 5:18pm UTC](https://discourse.cmake.org/t/cmake-3-28-and-importing-c-headers-in-gcc/9311 "2023-10-30T17:18:18Z")

</div>

Hi, I’m trying to create a CMakeLists.txt that more or less will do what the following Makefile does: CXX=a path to gcc14 built from master MODULE\_FLAGS = -fmodules-ts -flang-info-module-cmi make\_module\_of\_vector: …

---

## [Using --keep and --keep-dir with CUDA compilation commands](https://discourse.cmake.org/t/using-keep-and-keep-dir-with-cuda-compilation-commands/9307)

<div class="topic-metadata">

**Author:** [@krasznaa](https://discourse.cmake.org/u/krasznaa)\
**Replies:** 3\
**Last updated:** [October 30, 2023, 3:19pm UTC](https://discourse.cmake.org/t/using-keep-and-keep-dir-with-cuda-compilation-commands/9307 "2023-10-30T15:19:21Z")

</div>

Hi, I ran into an unexpected complication with our project, which I’d like to collect some ideas about. In our project, amongst other things, we build some CUDA source code. In order to do some not-completely-trivial de…

---

## [Multiple Build Invocations Required to Compile?](https://discourse.cmake.org/t/multiple-build-invocations-required-to-compile/9301)

<div class="topic-metadata">

**Author:** [@KTRR](https://discourse.cmake.org/u/KTRR)\
**Replies:** 1\
**Last updated:** [October 29, 2023, 12:17pm UTC](https://discourse.cmake.org/t/multiple-build-invocations-required-to-compile/9301 "2023-10-29T12:17:05Z")

</div>

I’m running into an issue where multiple build invocations are required to complete compilation (because modules are not being compiled in the correct order). I’m using CMake 3.27.7 and Ninja 1.11.1 on Windows with the l…

---

## [Let CMake link against a specific version of libstdc++](https://discourse.cmake.org/t/let-cmake-link-against-a-specific-version-of-libstdc/9283)

<div class="topic-metadata">

**Author:** [@evilroach](https://discourse.cmake.org/u/evilroach)\
**Replies:** 1\
**Last updated:** [October 29, 2023, 12:26pm UTC](https://discourse.cmake.org/t/let-cmake-link-against-a-specific-version-of-libstdc/9283 "2023-10-29T12:26:00Z")

</div>

I need to not only statically link, but also against specific version of libstdc++.a. Details: I’m working on a fresh installed Debian-12 at where only the version 11/12 of gcc/g++ can be installed against the official…

---

## [Using C++20 modules in a multiple directory project](https://discourse.cmake.org/t/using-c-20-modules-in-a-multiple-directory-project/9239)

<div class="topic-metadata">

**Author:** [@nitroglyceryne](https://discourse.cmake.org/u/nitroglyceryne)\
**Replies:** 4\
**Last updated:** [October 24, 2023, 7:28pm UTC](https://discourse.cmake.org/t/using-c-20-modules-in-a-multiple-directory-project/9239 "2023-10-24T19:28:37Z")

</div>

Hey everyone ! I wanted to try C++ modules on a project I’m working on. This project contains multiple directories and multiple CMakeLists.txt files. The structure is as follows: Root/ ├─ Kernel/ │ ├─ CMakeLists.txt │…

---

## [add\_test: Handling of spaces in path in WORKING\_DIRECTORY](https://discourse.cmake.org/t/add-test-handling-of-spaces-in-path-in-working-directory/9265)

<div class="topic-metadata">

**Author:** [@imrichardcole](https://discourse.cmake.org/u/imrichardcole)\
**Replies:** 2\
**Last updated:** [October 24, 2023, 3:40pm UTC](https://discourse.cmake.org/t/add-test-handling-of-spaces-in-path-in-working-directory/9265 "2023-10-24T15:40:26Z")

</div>

Currently banging my head against the following. Am on Windows and have the following working directory: C:\\code\\project - windows\\build I then configured a test within the CMakeLists.txt: add\_test(NAME MyTest COMM…

---

## [Does CTest always return exit code 0?](https://discourse.cmake.org/t/does-ctest-always-return-exit-code-0/9257)

<div class="topic-metadata">

**Author:** [@imikejackson](https://discourse.cmake.org/u/imikejackson)\
**Replies:** 3\
**Last updated:** [October 24, 2023, 1:36pm UTC](https://discourse.cmake.org/t/does-ctest-always-return-exit-code-0/9257 "2023-10-24T13:36:31Z")

</div>

Been struggling with an Azure build and it turns out that I think CTest is not reporting back when a compile fails? Here is some output from Azure: \[20/1636\] Building CXX object complex/CMakeFiles/complex.dir/src/comple…

---

## [cmake 3.28 CMAKE\_CXX\_COMPILER\_CLANG\_SCAN\_DEPS-NOTFOUND: not found](https://discourse.cmake.org/t/cmake-3-28-cmake-cxx-compiler-clang-scan-deps-notfound-not-found/9244)

<div class="topic-metadata">

**Author:** [@cooper](https://discourse.cmake.org/u/cooper)\
**Replies:** 5\
**Last updated:** [October 24, 2023, 11:17am UTC](https://discourse.cmake.org/t/cmake-3-28-cmake-cxx-compiler-clang-scan-deps-notfound-not-found/9244 "2023-10-24T11:17:32Z")

</div>

I’m writing code in docker and my dockerfile is as below. # Add the LLVM repository RUN apt-get update && \\ apt-get install -y software-properties-common wget jq sudo curl gnupg2 && \\ wget -O - https://apt.llvm.…

---

## [A quirk for debug symbols on Windows](https://discourse.cmake.org/t/a-quirk-for-debug-symbols-on-windows/9241)

<div class="topic-metadata">

**Author:** [@windymindy](https://discourse.cmake.org/u/windymindy)\
**Replies:** 3\
**Last updated:** [October 23, 2023, 6:55pm UTC](https://discourse.cmake.org/t/a-quirk-for-debug-symbols-on-windows/9241 "2023-10-23T18:55:01Z")

</div>

Hey. So I made this module. https://github.com/windymindy/examples\_cmake/blob/default/main/cmake/fix\_debug\_symbols.cmake It enumerates all targets in the current directory, for static libraries it sets some variables…

---

## [two tier source generation](https://discourse.cmake.org/t/two-tier-source-generation/9236)

<div class="topic-metadata">

**Author:** [@Brian](https://discourse.cmake.org/u/Brian)\
**Replies:** 6\
**Last updated:** [October 22, 2023, 3:47pm UTC](https://discourse.cmake.org/t/two-tier-source-generation/9236 "2023-10-22T15:47:45Z")

</div>

Hi All, I’m looking for some advice on how declare a library that depends on two custom tools being run. 1. glob the source tree for a list of files 2. run a tool on this list to convert to a slightly different format …

---

## [after installing he can't find Qt6Core.so.6 but the file is there](https://discourse.cmake.org/t/after-installing-he-cant-find-qt6core-so-6-but-the-file-is-there/9235)

<div class="topic-metadata">

**Author:** [@bytec0unter](https://discourse.cmake.org/u/bytec0unter)\
**Replies:** 3\
**Last updated:** [October 22, 2023, 3:44pm UTC](https://discourse.cmake.org/t/after-installing-he-cant-find-qt6core-so-6-but-the-file-is-there/9235 "2023-10-22T15:44:14Z")

</div>

the error messsage is like “…/out/bsApplication: /lib/x86\_64-linux-gnu/libQt6Core.so.6: version \`Qt\_6.6’ not found (required by …/out/bsApplication)” when i try to run the exe (linux). here is my CMakeLists.txt: debian …

---

## [how can i build static program by cmake+clang+nmake on windows?](https://discourse.cmake.org/t/how-can-i-build-static-program-by-cmake-clang-nmake-on-windows/9226)

<div class="topic-metadata">

**Author:** [@KSbread](https://discourse.cmake.org/u/KSbread)\
**Replies:** 7\
**Last updated:** [October 22, 2023, 12:45pm UTC](https://discourse.cmake.org/t/how-can-i-build-static-program-by-cmake-clang-nmake-on-windows/9226 "2023-10-22T12:45:31Z")

</div>

i asked this question on stackoverflow two days ago.this is original post. due to my low english proficiency,please don’t be surprised if there are any strange expressions. thanks for your response.

---

## [Project modularization using object libraries](https://discourse.cmake.org/t/project-modularization-using-object-libraries/3825)

<div class="topic-metadata">

**Author:** [@mredolatti](https://discourse.cmake.org/u/mredolatti)\
**Replies:** 16\
**Last updated:** [October 20, 2023, 6:14am UTC](https://discourse.cmake.org/t/project-modularization-using-object-libraries/3825 "2023-10-20T06:14:54Z")

</div>

Hello Everyone, I hope you’re all doing well! While i have some experience developing, i’m still trying to get familiar with CMake and trying to come up with a practical layout for a kinda-large library i’m working on.…

---

## [Complete Command Line Used By The Compiler?](https://discourse.cmake.org/t/complete-command-line-used-by-the-compiler/9214)

<div class="topic-metadata">

**Author:** [@Bertram](https://discourse.cmake.org/u/Bertram)\
**Replies:** 1\
**Last updated:** [October 17, 2023, 9:44pm UTC](https://discourse.cmake.org/t/complete-command-line-used-by-the-compiler/9214 "2023-10-17T21:44:34Z")

</div>

In order to incorporate a CRC into my microcontroller application, I am required to execute the linker twice. Currently, I have implemented all the necessary build procedures and CRC calculations from the generated files…

---

## [Imported projects don't resolve include paths in intellisense](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185)

<div class="topic-metadata">

**Author:** [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Replies:** 8\
**Last updated:** [October 17, 2023, 3:10am UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185 "2023-10-17T03:10:12Z")

</div>

When I create an imported project and generate for MSVC, the include paths are specified with additional options \<AdditionalOptions\>/external:I "/path/to/my/external/"\</AdditionalOptions\>, which then doesn’t allow intell…

---

## [FetchContent and Compiler launcher](https://discourse.cmake.org/t/fetchcontent-and-compiler-launcher/9202)

<div class="topic-metadata">

**Author:** [@silverqx](https://discourse.cmake.org/u/silverqx)\
**Replies:** 2\
**Last updated:** [October 16, 2023, 7:34am UTC](https://discourse.cmake.org/t/fetchcontent-and-compiler-launcher/9202 "2023-10-16T07:34:14Z")

</div>

I want to know if the FetchContent and ExternalProject consider the CMAKE\_CXX\_COMPILER\_LAUNCHER=ccache. Thx

---

## [Running \`try\_compile\` within \`Find\<Package\>.cmake\`](https://discourse.cmake.org/t/running-try-compile-within-find-package-cmake/9199)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 1\
**Last updated:** [October 13, 2023, 3:11pm UTC](https://discourse.cmake.org/t/running-try-compile-within-find-package-cmake/9199 "2023-10-13T15:11:14Z")

</div>

For example: add\_library(Package::Target ALIAS PkgConfig::Package) ... try\_compile(test\_package\_api SOURCES ${CMAKE\_CURRENT\_LIST\_DIR}/test\_package\_api.f90 LINK\_LIBRARIES Package::Target ) As far as I’ve tried this …

---

## [try\_compile to use include directory from imported target](https://discourse.cmake.org/t/try-compile-to-use-include-directory-from-imported-target/5127)

<div class="topic-metadata">

**Author:** [@bryn](https://discourse.cmake.org/u/bryn)\
**Replies:** 3\
**Last updated:** [October 13, 2023, 3:08pm UTC](https://discourse.cmake.org/t/try-compile-to-use-include-directory-from-imported-target/5127 "2023-10-13T15:08:20Z")

</div>

I am trying to figure out during configure time if the BLAS I find (ubuntu-20.04) is from Intel MKL, or some other vendor. find\_package(BLAS REQUIRED) try\_compile( test\_use\_mkl ${CMAKE\_BINARY\_DIR} ${CMAKE\_C…

---

## [exec\_program() could be useful.](https://discourse.cmake.org/t/exec-program-could-be-useful/9190)

<div class="topic-metadata">

**Author:** [@johnny96](https://discourse.cmake.org/u/johnny96)\
**Replies:** 7\
**Last updated:** [October 13, 2023, 1:12pm UTC](https://discourse.cmake.org/t/exec-program-could-be-useful/9190 "2023-10-13T13:12:22Z")

</div>

I am a new comer to cmake. so I am not aware of the reasons and the discussions as to why execute\_program() was deprecated. But I think execute\_program() is useful in some circumstances. Recently I hit a problem when us…

---

## [CMake Error Code 1: Troubleshooting Build Issue with SFML and MinGW](https://discourse.cmake.org/t/cmake-error-code-1-troubleshooting-build-issue-with-sfml-and-mingw/8985)

<div class="topic-metadata">

**Author:** [@luka](https://discourse.cmake.org/u/luka)\
**Replies:** 6\
**Last updated:** [October 12, 2023, 12:40pm UTC](https://discourse.cmake.org/t/cmake-error-code-1-troubleshooting-build-issue-with-sfml-and-mingw/8985 "2023-10-12T12:40:35Z")

</div>

Hello fellow developers, I hope you’re all doing well. I’m currently working on one of my first projects using SFML and CMake, and I’ve run into an issue that I could use some help with. What’s puzzling is that the prog…

---

## [Swig and Java Package Flag option not working](https://discourse.cmake.org/t/swig-and-java-package-flag-option-not-working/9183)

<div class="topic-metadata">

**Author:** [@Trevor\_Cash1](https://discourse.cmake.org/u/Trevor_Cash1)\
**Replies:** 2\
**Last updated:** [October 11, 2023, 11:31pm UTC](https://discourse.cmake.org/t/swig-and-java-package-flag-option-not-working/9183 "2023-10-11T23:31:01Z")

</div>

Hello All, I am using CMake and UseSwig() to create some java bindings. All seems to work - but I get an error when trying to pass the “-package” option on to swig (in order to wrap the created java into a java package) …

---

## [Proper way to use OpenMP: target\_link\_libraries() enough?](https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 3\
**Last updated:** [October 9, 2023, 11:38pm UTC](https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158 "2023-10-09T23:38:57Z")

</div>

With a project that uses OpenMP, is it sufficient to set target\_link\_libraries(... OpenMP::OpenMP\_C) or do we need to set compiler options (in addition to linker options) separately? The following test project works fin…

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

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