# Code

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

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

**Page:** 23

---

## [how do I set up linux headers with cmake in vscode ? ubuntu](https://discourse.cmake.org/t/how-do-i-set-up-linux-headers-with-cmake-in-vscode-ubuntu/10461)

<div class="topic-metadata">

**Author:** [@WaltOnline](https://discourse.cmake.org/u/WaltOnline)\
**Replies:** 1\
**Last updated:** [April 11, 2024, 12:10am UTC](https://discourse.cmake.org/t/how-do-i-set-up-linux-headers-with-cmake-in-vscode-ubuntu/10461 "2024-04-11T00:10:53Z")

</div>

Hi! I have a hard time setting a correct paths with cmake for “linux headers”. I installed linux 24 and those 2 directories were already there in “/usr/src/” directory, linux-headrs-6.8.0-11 linux-headers-6.8.0-11-g…

---

## [avoiding extra quotes in add\_test command](https://discourse.cmake.org/t/avoiding-extra-quotes-in-add-test-command/10425)

<div class="topic-metadata">

**Author:** [@samuelpmish](https://discourse.cmake.org/u/samuelpmish)\
**Replies:** 3\
**Last updated:** [April 10, 2024, 11:58pm UTC](https://discourse.cmake.org/t/avoiding-extra-quotes-in-add-test-command/10425 "2024-04-10T23:58:09Z")

</div>

Hi, I’m trying to add CMake support for an existing library that has a suite of tests that are expected to be invoked in the following way: test001 /ref/opt where /ref/opt is the project’s own notation for expressing a…

---

## [How to add custom bytes to the image after build?](https://discourse.cmake.org/t/how-to-add-custom-bytes-to-the-image-after-build/10428)

<div class="topic-metadata">

**Author:** [@gcckr](https://discourse.cmake.org/u/gcckr)\
**Replies:** 1\
**Last updated:** [April 10, 2024, 11:45pm UTC](https://discourse.cmake.org/t/how-to-add-custom-bytes-to-the-image-after-build/10428 "2024-04-10T23:45:44Z")

</div>

I am new to cmake. I want to add custom bytes to the image file and want to read these bytes in the mcu. There will be two usages, device id and custom checksum. I dont want to change h or c files but I want to add somet…

---

## [How to I include\_directories() and/or target\_include\_directories() with GCC's/Clang's -iquote/-idirafter](https://discourse.cmake.org/t/how-to-i-include-directories-and-or-target-include-directories-with-gccs-clangs-iquote-idirafter/9609)

<div class="topic-metadata">

**Author:** [@exoosh](https://discourse.cmake.org/u/exoosh)\
**Replies:** 10\
**Last updated:** [April 10, 2024, 10:36pm UTC](https://discourse.cmake.org/t/how-to-i-include-directories-and-or-target-include-directories-with-gccs-clangs-iquote-idirafter/9609 "2024-04-10T22:36:48Z")

</div>

Hi there, I am wondering how to wield include\_directories() and/or target\_include\_directories() to tell the preprocessor directly to use -iquote or -idirafter as opposed to a mere -I or -isystem. It’s a question I raise…

---

## [Few questions about find\_library()](https://discourse.cmake.org/t/few-questions-about-find-library/10332)

<div class="topic-metadata">

**Author:** [@WaltOnline](https://discourse.cmake.org/u/WaltOnline)\
**Replies:** 1\
**Last updated:** [April 10, 2024, 9:42pm UTC](https://discourse.cmake.org/t/few-questions-about-find-library/10332 "2024-04-10T21:42:10Z")

</div>

Hi! I have lib files in directory, so I set set(MYLIBSDIR "C:/Users/User1/Desktop/math\_libs") find\_library(RESULT NAMES lib PATHS "${MYLIBSDIR}/lib") message("RESULT: " ${RESULT}) libs name: lib\_trace.lib and li…

---

## [Getting pthreads cflags and library flags from Threads::Threads](https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304)

<div class="topic-metadata">

**Author:** [@mdorier](https://discourse.cmake.org/u/mdorier)\
**Replies:** 1\
**Last updated:** [April 10, 2024, 9:36pm UTC](https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304 "2024-04-10T21:36:03Z")

</div>

I am porting a C library from autotools to cmake. The library depends on pthreads, which with autotools is detected using an AX\_PTHREAD macro from an ax\_pthread.m4 file. This macro sets PTHREAD\_LIBS and PTHREAD\_CFLAGS ap…

---

## [Cannot "link" to interface library](https://discourse.cmake.org/t/cannot-link-to-interface-library/10624)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 6\
**Last updated:** [April 10, 2024, 1:36pm UTC](https://discourse.cmake.org/t/cannot-link-to-interface-library/10624 "2024-04-10T13:36:23Z")

</div>

Hello, I am working on a library (you can see the files structure here). I have packaged and zipped it, I get it from a remote server with FetchContent and everything is (almost) fine. In the root CMakeLists.txt, I ad…

---

## [Cross-compilation - sysroot - pkg\_check\_modules](https://discourse.cmake.org/t/cross-compilation-sysroot-pkg-check-modules/10610)

<div class="topic-metadata">

**Author:** [@Peter\_Featherstone](https://discourse.cmake.org/u/Peter_Featherstone)\
**Replies:** 0\
**Last updated:** [April 8, 2024, 2:53pm UTC](https://discourse.cmake.org/t/cross-compilation-sysroot-pkg-check-modules/10610 "2024-04-08T14:53:56Z")

</div>

I am cross compiling for the Analogue devices ADSP-SC589 Datasheet and Product Info | Analog Devices which ADI provide an SDK for, including a cmake toolchain. I am cross-compiling a library using autotools and the SDK …

---

## [check\_required\_components logics](https://discourse.cmake.org/t/check-required-components-logics/10567)

<div class="topic-metadata">

**Author:** [@emaschino](https://discourse.cmake.org/u/emaschino)\
**Replies:** 7\
**Last updated:** [April 8, 2024, 7:50am UTC](https://discourse.cmake.org/t/check-required-components-logics/10567 "2024-04-08T07:50:20Z")

</div>

Hi, I’m not sure to understand the logics of check\_required\_components macro generated by configure\_package\_config\_file of CMakePackageConfigHelpers package. It reads as follows: macro(check\_required\_components \_NAME) …

---

## [Share targets between src and tests subdirectory](https://discourse.cmake.org/t/share-targets-between-src-and-tests-subdirectory/10564)

<div class="topic-metadata">

**Author:** [@mredenti](https://discourse.cmake.org/u/mredenti)\
**Replies:** 4\
**Last updated:** [April 5, 2024, 1:49pm UTC](https://discourse.cmake.org/t/share-targets-between-src-and-tests-subdirectory/10564 "2024-04-05T13:49:40Z")

</div>

How can I make use of already compiled targets in another subdirectory? Do I necessarily need to build a library? Suppose I have a (mini) finite element code and have structured the project as follows │── CMakeLists.tx…

---

## [cmake project version - last guy wins?](https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 1\
**Last updated:** [April 4, 2024, 8:50am UTC](https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446 "2024-04-04T08:50:45Z")

</div>

How can one scope the cmake project version? It appears the project version string is last-guy wins. Say I have top project CMakeLists.txt that sets version, then it includes some other component by via add\_subdirectory,…

---

## [Copy DLL files to the binary directory on Mac and Linux.](https://discourse.cmake.org/t/copy-dll-files-to-the-binary-directory-on-mac-and-linux/10508)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 3\
**Last updated:** [April 1, 2024, 4:09pm UTC](https://discourse.cmake.org/t/copy-dll-files-to-the-binary-directory-on-mac-and-linux/10508 "2024-04-01T16:09:29Z")

</div>

According to the CMake documentation, we can use the following command to copy DLL files to the binary directory under the Windows operating system: if(WIN32) add\_custom\_command(TARGET ${EXECUTABLE\_NAME} POST\_BUIL…

---

## [Don't know how to prevent CMake from generating /MDd compiler option](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545)

<div class="topic-metadata">

**Author:** [@c4711](https://discourse.cmake.org/u/c4711)\
**Replies:** 4\
**Last updated:** [April 1, 2024, 9:48am UTC](https://discourse.cmake.org/t/dont-know-how-to-prevent-cmake-from-generating-mdd-compiler-option/10545 "2024-04-01T09:48:03Z")

</div>

Hi all. I am new to using CMake and have a very basic use case to build a cpp application on windows. My current CMakeList.txt consists only consists of a view lines: cmake\_minimum\_required(VERSION 3.15) project(keep…

---

## [Why does TARGET\_FILE\_DIR create a dependency on the target](https://discourse.cmake.org/t/why-does-target-file-dir-create-a-dependency-on-the-target/1069)

<div class="topic-metadata">

**Author:** [@sandercox](https://discourse.cmake.org/u/sandercox)\
**Replies:** 3\
**Last updated:** [March 29, 2024, 3:27pm UTC](https://discourse.cmake.org/t/why-does-target-file-dir-create-a-dependency-on-the-target/1069 "2024-03-29T15:27:50Z")

</div>

I’m trying to create some rules to copy files to a targets library directory. I’ve pretty much solved it but my current solution had some issues that it would only really work for sure if all targets would be build of th…

---

## [CMake scripts sharing](https://discourse.cmake.org/t/cmake-scripts-sharing/10406)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 3\
**Last updated:** [March 29, 2024, 12:04pm UTC](https://discourse.cmake.org/t/cmake-scripts-sharing/10406 "2024-03-29T12:04:03Z")

</div>

Hello, Today, to build many internal Git projects, my company uses a dedicated Git project to build other projects through batch scripts, then CMakeLists.txt and other CMake script, to finally use ExternalProject to ret…

---

## [Getting wrong ELF class error when attempting to use library](https://discourse.cmake.org/t/getting-wrong-elf-class-error-when-attempting-to-use-library/10170)

<div class="topic-metadata">

**Author:** [@Vekleon](https://discourse.cmake.org/u/Vekleon)\
**Replies:** 6\
**Last updated:** [March 29, 2024, 11:04am UTC](https://discourse.cmake.org/t/getting-wrong-elf-class-error-when-attempting-to-use-library/10170 "2024-03-29T11:04:43Z")

</div>

I’m having an issue where I’m trying to compile a shared library on system A and move it onto another system B with the same architecture (x86\_64). I then try to utilize some functions defined in this library but I see t…

---

## [FetchContent: how to set the URL depending the configuration ?](https://discourse.cmake.org/t/fetchcontent-how-to-set-the-url-depending-the-configuration/10510)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 2\
**Last updated:** [March 29, 2024, 8:41am UTC](https://discourse.cmake.org/t/fetchcontent-how-to-set-the-url-depending-the-configuration/10510 "2024-03-29T08:41:21Z")

</div>

Hello, I use FetchContent to retrieve binary libraries. But as I am on Window, I have to retrieve different binaries depending the configuration (Debug, Release…), so that the clients can link to any of these configurat…

---

## [Doxygen problems with find\_package()](https://discourse.cmake.org/t/doxygen-problems-with-find-package/10527)

<div class="topic-metadata">

**Author:** [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Replies:** 1\
**Last updated:** [March 29, 2024, 8:06am UTC](https://discourse.cmake.org/t/doxygen-problems-with-find-package/10527 "2024-03-29T08:06:26Z")

</div>

I am experiencing significant difficulties with the find\_package() command. I find it to be rather unreliable, as there are instances where it fails to locate dependencies even under ideal conditions. Below is the code s…

---

## [Can I compile .c and .cpp files seperately in a single project?](https://discourse.cmake.org/t/can-i-compile-c-and-cpp-files-seperately-in-a-single-project/10484)

<div class="topic-metadata">

**Author:** [@Giri](https://discourse.cmake.org/u/Giri)\
**Replies:** 3\
**Last updated:** [March 28, 2024, 4:34pm UTC](https://discourse.cmake.org/t/can-i-compile-c-and-cpp-files-seperately-in-a-single-project/10484 "2024-03-28T16:34:12Z")

</div>

Hi, I am developing a C project. I have a library with .cpp files (No other option). But my project has most of .c files. Finally, I have to connect the different file types. Whenever I build a project, I get compilati…

---

## [GCC: Skipping incompatible (ERROR)](https://discourse.cmake.org/t/gcc-skipping-incompatible-error/10472)

<div class="topic-metadata">

**Author:** [@Roberto](https://discourse.cmake.org/u/Roberto)\
**Replies:** 6\
**Last updated:** [March 26, 2024, 9:52pm UTC](https://discourse.cmake.org/t/gcc-skipping-incompatible-error/10472 "2024-03-26T21:52:31Z")

</div>

Good morning, I switched my IDE and applied the required additional include & preprocessor definitions into the CMakeLists.txt file, but encounter errors when trying to BUILD the project (x86 / Release). The binary con…

---

## [Fetch compiler toolchain in toolchain file](https://discourse.cmake.org/t/fetch-compiler-toolchain-in-toolchain-file/10490)

<div class="topic-metadata">

**Author:** [@Mathias\_B](https://discourse.cmake.org/u/Mathias_B)\
**Replies:** 1\
**Last updated:** [March 26, 2024, 9:29pm UTC](https://discourse.cmake.org/t/fetch-compiler-toolchain-in-toolchain-file/10490 "2024-03-26T21:29:33Z")

</div>

Hello, I have been trying to setup a C/C++/CMake project, with the ability to configure the cmake project with several toolchain files through the CMAKE\_TOOLCHAIN\_FILE CMake variable. I have a set of toolchain files (t…

---

## [Linking to library retrieved with fetchContent](https://discourse.cmake.org/t/linking-to-library-retrieved-with-fetchcontent/10157)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 5\
**Last updated:** [March 26, 2024, 9:22pm UTC](https://discourse.cmake.org/t/linking-to-library-retrieved-with-fetchcontent/10157 "2024-03-26T21:22:06Z")

</div>

Hello, I put a library on a server, and I retrieve it with FetchContent : cmake\_minimum\_required(VERSION 3.17.3) project("TestMyLib") include(FetchContent) FetchContent\_Declare(MyLibrary URL "https://../../MyLibrary.…

---

## [Depending upon a POST\_BUILD of an ExternalProject](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507)

<div class="topic-metadata">

**Author:** [@jmqwerk](https://discourse.cmake.org/u/jmqwerk)\
**Replies:** 5\
**Last updated:** [March 25, 2024, 7:14am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507 "2024-03-25T07:14:53Z")

</div>

Having an issue… I add an external project which is a cmake project which creates an output, then as post build creates additional files, from the main project it then adds targets that depend on these post build files, …

---

## [Syntax error in cmake code at /usr/share/cmake/Modules/CheckCSourceCompiles.cmake:59](https://discourse.cmake.org/t/syntax-error-in-cmake-code-at-usr-share-cmake-modules-checkcsourcecompiles-cmake-59/10432)

<div class="topic-metadata">

**Author:** [@Jack\_Smith](https://discourse.cmake.org/u/Jack_Smith)\
**Replies:** 5\
**Last updated:** [March 22, 2024, 11:24am UTC](https://discourse.cmake.org/t/syntax-error-in-cmake-code-at-usr-share-cmake-modules-checkcsourcecompiles-cmake-59/10432 "2024-03-22T11:24:51Z")

</div>

I am attempting to determine if a particular issue exists during Generate time. I have checked that the source code itself is correct, and quotes, etc, are correctly escaped. The resultant string dumped by the call to …

---

## [CMake Configure Always Runs Twice](https://discourse.cmake.org/t/cmake-configure-always-runs-twice/10433)

<div class="topic-metadata">

**Author:** [@ChadK](https://discourse.cmake.org/u/ChadK)\
**Replies:** 1\
**Last updated:** [March 21, 2024, 4:22pm UTC](https://discourse.cmake.org/t/cmake-configure-always-runs-twice/10433 "2024-03-21T16:22:45Z")

</div>

I’m using CMake with VS Code in Windows with gcc on ARM. I’ve tried fixing this a couple times, but never been successful. Whenever I run CMake configure, it always runs twice. This is annoying becuase the second time…

---

## [Unknown arguments specified](https://discourse.cmake.org/t/unknown-arguments-specified/10313)

<div class="topic-metadata">

**Author:** [@maiya](https://discourse.cmake.org/u/maiya)\
**Replies:** 3\
**Last updated:** [March 21, 2024, 4:02pm UTC](https://discourse.cmake.org/t/unknown-arguments-specified/10313 "2024-03-21T16:02:48Z")

</div>

Hi community, CMake Error at CMakeLists.txt:13 (if): if given arguments: "3.5.1" "VERSION\_GREATER\_EQUAL" "3.12" Unknown arguments specified -- Configuring incomplete, errors occurred! getting the above erro…

---

## [FetchContent with Boost](https://discourse.cmake.org/t/fetchcontent-with-boost/6596)

<div class="topic-metadata">

**Author:** [@malaterre](https://discourse.cmake.org/u/malaterre)\
**Replies:** 26\
**Last updated:** [March 20, 2024, 9:40am UTC](https://discourse.cmake.org/t/fetchcontent-with-boost/6596 "2024-03-20T09:40:27Z")

</div>

Hi there, I have been trying to make sense of the FetchContent documentation at: https://cmake.org/cmake/help/latest/module/FetchContent.html However I must say I totally fail to understand the documentation in my si…

---

## [ExternalProject\_Add: multiple INSTALL\_COMMAND ?](https://discourse.cmake.org/t/externalproject-add-multiple-install-command/10409)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 2\
**Last updated:** [March 20, 2024, 8:07am UTC](https://discourse.cmake.org/t/externalproject-add-multiple-install-command/10409 "2024-03-20T08:07:53Z")

</div>

Hello, I am reading a script, and I can see a call to ExternalProject\_Add(). But there are two INSTALL\_COMMAND arguments. Is it supposed to be possibe ? There is nothing in the documentation about these multiple uses. …

---

## [I keep getting linker error, could you help me fix it?](https://discourse.cmake.org/t/i-keep-getting-linker-error-could-you-help-me-fix-it/10405)

<div class="topic-metadata">

**Author:** [@Shepard](https://discourse.cmake.org/u/Shepard)\
**Replies:** 4\
**Last updated:** [March 19, 2024, 9:42am UTC](https://discourse.cmake.org/t/i-keep-getting-linker-error-could-you-help-me-fix-it/10405 "2024-03-19T09:42:49Z")

</div>

I can’t figure out why but I keep getting linker errors. I followed/read several problems for example this and I can’t get it to work. My root is as follows: . ├── bin ├── CMakeLists.txt ├── external │ ├── CMakeList…

---

## [Unique way to enable OpenMP with CMake?](https://discourse.cmake.org/t/unique-way-to-enable-openmp-with-cmake/10350)

<div class="topic-metadata">

**Author:** [@asimplecoder](https://discourse.cmake.org/u/asimplecoder)\
**Replies:** 5\
**Last updated:** [March 15, 2024, 2:47pm UTC](https://discourse.cmake.org/t/unique-way-to-enable-openmp-with-cmake/10350 "2024-03-15T14:47:34Z")

</div>

Hi everyone, I am wondering which is the recommended way to enable OpenMP support, regardless of the OS. I mostly work on Windows OS, and there it was only “sufficient” to set the target compile options to include the …

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

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