# Code

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

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

**Page:** 28

---

## [Library and include path](https://discourse.cmake.org/t/library-and-include-path/9523)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 3\
**Last updated:** [November 29, 2023, 9:43am UTC](https://discourse.cmake.org/t/library-and-include-path/9523 "2023-11-29T09:43:48Z")

</div>

Hello, I am creating a library, and the associated test. Here is the files structure : ── MyLibrary ├── CMakeLists.txt ├── include │ └── x.h ├── src │ ├── CMakeLists.txt │ ├── x.cpp │ ├── …

---

## [Is it possible to create several targets with different toolchains in CmakeList.txt?](https://discourse.cmake.org/t/is-it-possible-to-create-several-targets-with-different-toolchains-in-cmakelist-txt/9522)

<div class="topic-metadata">

**Author:** [@KSergeyP](https://discourse.cmake.org/u/KSergeyP)\
**Replies:** 1\
**Last updated:** [November 28, 2023, 8:42pm UTC](https://discourse.cmake.org/t/is-it-possible-to-create-several-targets-with-different-toolchains-in-cmakelist-txt/9522 "2023-11-28T20:42:17Z")

</div>

I know that you can set compiler settings separately for each target. Is it possible to define a different compiler for each target? For example, to build an application for different platforms (Windows Linux, etc.) in o…

---

## [set() / PARENT\_SCOPE](https://discourse.cmake.org/t/set-parent-scope/9512)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 3\
**Last updated:** [November 27, 2023, 8:41pm UTC](https://discourse.cmake.org/t/set-parent-scope/9512 "2023-11-27T20:41:51Z")

</div>

Hello, I am working on a file structure with several CMakeLists.txt. EDIT : Does it make sense to have this deep structure ? Visual Studio seems not to be able to mimic it in Solution / projects (tests wouldn’t be nest…

---

## [Module not found error on 3.28](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507)

<div class="topic-metadata">

**Author:** [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Replies:** 8\
**Last updated:** [November 26, 2023, 11:44pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507 "2023-11-26T23:44:06Z")

</div>

Hello, I’m trying to integrate the new modules functionality into a project. I’m currently having issues with the module not being found when I import it. I’ve added this to my CMakeLists: file(GLOB\_RECURSE TEST\_MODULE…

---

## [Help with linking snappy to leveldb (Windows) pay 40$](https://discourse.cmake.org/t/help-with-linking-snappy-to-leveldb-windows-pay-40/9472)

<div class="topic-metadata">

**Author:** [@Reload](https://discourse.cmake.org/u/Reload)\
**Replies:** 22\
**Last updated:** [November 24, 2023, 2:40pm UTC](https://discourse.cmake.org/t/help-with-linking-snappy-to-leveldb-windows-pay-40/9472 "2023-11-24T14:40:24Z")

</div>

snappy - GitHub - google/snappy: A fast compressor/decompressor leveldb - GitHub - google/leveldb: LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to strin…

---

## [Should cmake install an INTERFACE library when linked as PRIVATE dependency ?](https://discourse.cmake.org/t/should-cmake-install-an-interface-library-when-linked-as-private-dependency/9449)

<div class="topic-metadata">

**Author:** [@maxmarsc](https://discourse.cmake.org/u/maxmarsc)\
**Replies:** 13\
**Last updated:** [November 23, 2023, 11:51am UTC](https://discourse.cmake.org/t/should-cmake-install-an-interface-library-when-linked-as-private-dependency/9449 "2023-11-23T11:51:08Z")

</div>

Hi folks, I’m having a hard time understanding how cmake should behave regarding installation of dependencies added with FetchContent so I’m sorry if this is a noob question, but I couldn’t find a satisfying answer so f…

---

## [custom properties for target](https://discourse.cmake.org/t/custom-properties-for-target/9486)

<div class="topic-metadata">

**Author:** [@KSergeyP](https://discourse.cmake.org/u/KSergeyP)\
**Replies:** 2\
**Last updated:** [November 22, 2023, 9:40pm UTC](https://discourse.cmake.org/t/custom-properties-for-target/9486 "2023-11-22T21:40:16Z")

</div>

I’m adding an external library (subdirectory). In this case, it is necessary to specify some configuration properties for this library. Now I do this by setting the values of global variables, because these properties ar…

---

## [Build a library with different options in one run](https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485)

<div class="topic-metadata">

**Author:** [@KSergeyP](https://discourse.cmake.org/u/KSergeyP)\
**Replies:** 1\
**Last updated:** [November 22, 2023, 9:37pm UTC](https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485 "2023-11-22T21:37:25Z")

</div>

I have several configurations in my main project and each configuration depends on an external library. But for different configurations it is necessary to compile this library with different options. The library is comp…

---

## [How to set job pool for step targets defined by ExternalProject\_Add\_StepTargets](https://discourse.cmake.org/t/how-to-set-job-pool-for-step-targets-defined-by-externalproject-add-steptargets/9483)

<div class="topic-metadata">

**Author:** [@hehaoqian1](https://discourse.cmake.org/u/hehaoqian1)\
**Replies:** 1\
**Last updated:** [November 22, 2023, 2:23pm UTC](https://discourse.cmake.org/t/how-to-set-job-pool-for-step-targets-defined-by-externalproject-add-steptargets/9483 "2023-11-22T14:23:49Z")

</div>

As the doc of cmake property JOB\_POOLS says Defined pools could be used globally by setting CMAKE\_JOB\_POOL\_COMPILE and CMAKE\_JOB\_POOL\_LINKor per target by setting the target properties JOB\_POOL\_COMPILEand JOB\_POOL\_LINK …

---

## [project version from file (semver)](https://discourse.cmake.org/t/project-version-from-file-semver/9478)

<div class="topic-metadata">

**Author:** [@malaterre](https://discourse.cmake.org/u/malaterre)\
**Replies:** 1\
**Last updated:** [November 21, 2023, 1:25pm UTC](https://discourse.cmake.org/t/project-version-from-file-semver/9478 "2023-11-21T13:25:10Z")

</div>

Hi folks, I am trying to integrate gitlab-ci and cmake more tightly. I would like to be able to easily extract the project version (semver based) easily. I think the modern approach today is store the version in a sepa…

---

## [Create .o and .d files based on .c files](https://discourse.cmake.org/t/create-o-and-d-files-based-on-c-files/9442)

<div class="topic-metadata">

**Author:** [@deeptii1410](https://discourse.cmake.org/u/deeptii1410)\
**Replies:** 3\
**Last updated:** [November 21, 2023, 3:06am UTC](https://discourse.cmake.org/t/create-o-and-d-files-based-on-c-files/9442 "2023-11-21T03:06:44Z")

</div>

add\_library(lib\_trial OBJECT ${SOURCE\_FILES}) target\_include\_directories(lib\_trial PRIVATE ${CMAKE\_SOURCE\_DIR}/include) Migrating code from omake to cmake. Here my target creates .o and .d files. Try to achieve came i…

---

## [Add only library headers during target\_link\_libraries()](https://discourse.cmake.org/t/add-only-library-headers-during-target-link-libraries/2973)

<div class="topic-metadata">

**Author:** [@cerna](https://discourse.cmake.org/u/cerna)\
**Replies:** 17\
**Last updated:** [November 20, 2023, 1:52pm UTC](https://discourse.cmake.org/t/add-only-library-headers-during-target-link-libraries/2973 "2023-11-20T13:52:04Z")

</div>

Hello, I have a set of C source files and headers. From this I want to compile a shared library for normal linkage and then similar (just some different DEFINEs) MODULE library used to dynamically load the functionality…

---

## [How to define a script path. in vs](https://discourse.cmake.org/t/how-to-define-a-script-path-in-vs/9452)

<div class="topic-metadata">

**Author:** [@Drew66](https://discourse.cmake.org/u/Drew66)\
**Replies:** 2\
**Last updated:** [November 19, 2023, 1:02pm UTC](https://discourse.cmake.org/t/how-to-define-a-script-path-in-vs/9452 "2023-11-19T13:02:15Z")

</div>

Hi, I’m installing a new board into my 3d printer, to accomplish this I have to copy the firm ware from the site in to VS, make a couple of alterations and then debug. it was going ok until I hit debug and then I had to…

---

## [Defer install() and configure\_file() until libraries targets built](https://discourse.cmake.org/t/defer-install-and-configure-file-until-libraries-targets-built/9282)

<div class="topic-metadata">

**Author:** [@f.brier](https://discourse.cmake.org/u/f.brier)\
**Replies:** 3\
**Last updated:** [November 19, 2023, 2:54am UTC](https://discourse.cmake.org/t/defer-install-and-configure-file-until-libraries-targets-built/9282 "2023-11-19T02:54:57Z")

</div>

My CMakeLists.txt has two library targets. CPack needs to bundle the libraries and some other files that cannot be generated until the two library targets have been built. My understanding is that CMake cannot execute a …

---

## [Read file and transform the result in a custom command directly?](https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 1\
**Last updated:** [November 19, 2023, 2:40am UTC](https://discourse.cmake.org/t/read-file-and-transform-the-result-in-a-custom-command-directly/9448 "2023-11-19T02:40:03Z")

</div>

Before I run eg doxygen I want to read up some variables from a file that was written earlier in the build. This reading also entails transforming the result a bit before passing it on to doxygen. Is it customary to cr…

---

## [What is \`.dll\` executable file of shared library target on DLL platforms?](https://discourse.cmake.org/t/what-is-dll-executable-file-of-shared-library-target-on-dll-platforms/9433)

<div class="topic-metadata">

**Author:** [@zhongdongy](https://discourse.cmake.org/u/zhongdongy)\
**Replies:** 3\
**Last updated:** [November 19, 2023, 2:27am UTC](https://discourse.cmake.org/t/what-is-dll-executable-file-of-shared-library-target-on-dll-platforms/9433 "2023-11-19T02:27:22Z")

</div>

Hi all, I recently read this document Runtime Output Artifacts. It mentioned: On DLL platforms: the executable file (e.g. .dll) of a shared library target created by the add\_library() command with the SHARED option. A…

---

## [Replacing a list of sources with an extraction from the target later](https://discourse.cmake.org/t/replacing-a-list-of-sources-with-an-extraction-from-the-target-later/9404)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 5\
**Last updated:** [November 18, 2023, 8:10pm UTC](https://discourse.cmake.org/t/replacing-a-list-of-sources-with-an-extraction-from-the-target-later/9404 "2023-11-18T20:10:25Z")

</div>

Sorry for a very rookie question so please flame away. I had a list of sources that were passed around and I wanted to use target\_sources instead so I can use more “elegant” genex processing of including various sources…

---

## [unset cache variable in add\_custom\_target()](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366)

<div class="topic-metadata">

**Author:** [@Fabian188](https://discourse.cmake.org/u/Fabian188)\
**Replies:** 2\
**Last updated:** [November 17, 2023, 11:29am UTC](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366 "2023-11-17T11:29:24Z")

</div>

In my (limited) understanding, my required functionality is not possible, but I better ask. Ich have custom targets called “clean-xyz” which remove files nicely via cmake -E remove … I would like to also unset a cmake …

---

## [CMake Toolchain Files and \_GNU\_SOURCE definition](https://discourse.cmake.org/t/cmake-toolchain-files-and-gnu-source-definition/9411)

<div class="topic-metadata">

**Author:** [@axelsommerfeldt](https://discourse.cmake.org/u/axelsommerfeldt)\
**Replies:** 3\
**Last updated:** [November 17, 2023, 3:15am UTC](https://discourse.cmake.org/t/cmake-toolchain-files-and-gnu-source-definition/9411 "2023-11-17T03:15:12Z")

</div>

Usually CMake defines \_GNU\_SOURCE automatically but not when using a/my CMake Toolchain File. Is this a problem with my CMake Toolchain File, and if yes, how do I fix it? What exactly is the precondition that CMake defin…

---

## [Help including WPF project.](https://discourse.cmake.org/t/help-including-wpf-project/9436)

<div class="topic-metadata">

**Author:** [@IgorDev](https://discourse.cmake.org/u/IgorDev)\
**Replies:** 0\
**Last updated:** [November 15, 2023, 7:59pm UTC](https://discourse.cmake.org/t/help-including-wpf-project/9436 "2023-11-15T19:59:50Z")

</div>

Hello, in my CMakeLists.txt file I have the following code to include a WPF project into the Visual Studio solution generated by CMake. include\_external\_msproject(OrchisEditor OrchisEditor/OrchisEditor.csproj PLATFORM A…

---

## [visual studio looking for .lib](https://discourse.cmake.org/t/visual-studio-looking-for-lib/9427)

<div class="topic-metadata">

**Author:** [@superdu](https://discourse.cmake.org/u/superdu)\
**Replies:** 3\
**Last updated:** [November 14, 2023, 9:51pm UTC](https://discourse.cmake.org/t/visual-studio-looking-for-lib/9427 "2023-11-14T21:51:01Z")

</div>

Hello, I’m building my own librairy. I try to build a static and a share version (I’m using visual studio community) my structure: root | |-algos | |-src | | |\*.cpp | | | |-include | | |\*.h | | | | C…

---

## [Unexpected interactions between \`CMAKE\_SYSROOT\` and \`CMAKE\_FIND\_ROOT\_PATH\_MODE\_PACKAGE\`](https://discourse.cmake.org/t/unexpected-interactions-between-cmake-sysroot-and-cmake-find-root-path-mode-package/7893)

<div class="topic-metadata">

**Author:** [@PieterP](https://discourse.cmake.org/u/PieterP)\
**Replies:** 1\
**Last updated:** [November 14, 2023, 7:40pm UTC](https://discourse.cmake.org/t/unexpected-interactions-between-cmake-sysroot-and-cmake-find-root-path-mode-package/7893 "2023-11-14T19:40:02Z")

</div>

TL;DR: Why does leaving CMAKE\_SYSROOT unset in a toolchain file cause CMake to ignore CMAKE\_FIND\_ROOT\_PATH\_MODE\_PACKAGE=ONLY and allow find\_package to search CMAKE\_PREFIX\_PATH anyway? Context: I’m playing around with cr…

---

## [LINK\_LIBRARY:WHOLE\_ARCHIVE affects INTERFACE\_LINK\_LIBRARIES\_DIRECT, is that intentional?](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420)

<div class="topic-metadata">

**Author:** [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Replies:** 2\
**Last updated:** [November 13, 2023, 5:48pm UTC](https://discourse.cmake.org/t/link-library-whole-archive-affects-interface-link-libraries-direct-is-that-intentional/9420 "2023-11-13T17:48:02Z")

</div>

Given the following minimal project: cmake\_minimum\_required(VERSION 3.25) project(watest) add\_library(lib1 STATIC lib1.cpp) add\_library(lib2 STATIC lib2.cpp) #target\_link\_libraries(lib2 PRIVATE lib1) …

---

## [Target sources contains empty entries](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 3\
**Last updated:** [November 13, 2023, 10:24am UTC](https://discourse.cmake.org/t/target-sources-contains-empty-entries/9392 "2023-11-13T10:24:21Z")

</div>

I’m using target\_sources and noticed that when I need to retrieve those sources using $\<TARGET\_PROPERTY:my\_target,SOURCES\> I’d get a few empty entries here and there which breaks a bit of my build. Eg the list starts wi…

---

## [Use of CMAKE\_PROJECT\_TOP\_LEVEL\_INCLUDES  in options.cmake](https://discourse.cmake.org/t/use-of-cmake-project-top-level-includes-in-options-cmake/9408)

<div class="topic-metadata">

**Author:** [@Laxmi\_Jain](https://discourse.cmake.org/u/Laxmi_Jain)\
**Replies:** 1\
**Last updated:** [November 13, 2023, 9:47am UTC](https://discourse.cmake.org/t/use-of-cmake-project-top-level-includes-in-options-cmake/9408 "2023-11-13T09:47:06Z")

</div>

Hi, I want to use CMAKE\_PROJECT\_TOP\_LEVEL\_INCLUDES through options.cmake instead of passing this as an argument to command line e.g instead of using it like cmake -DCMAKE\_PROJECT\_TOP\_LEVEL\_INCLUDES= I want to define i…

---

## [CPackDeb: file utility is not available. CPACK\_DEBIAN\_PACKAGE\_SHLIBDEPS and CPACK\_DEBIAN\_PACKAGE\_GENERATE\_SHLIBS options are not available](https://discourse.cmake.org/t/cpackdeb-file-utility-is-not-available-cpack-debian-package-shlibdeps-and-cpack-debian-package-generate-shlibs-options-are-not-available/9407)

<div class="topic-metadata">

**Author:** [@paulbourelly999](https://discourse.cmake.org/u/paulbourelly999)\
**Replies:** 1\
**Last updated:** [November 10, 2023, 8:38pm UTC](https://discourse.cmake.org/t/cpackdeb-file-utility-is-not-available-cpack-debian-package-shlibdeps-and-cpack-debian-package-generate-shlibs-options-are-not-available/9407 "2023-11-10T20:38:41Z")

</div>

When installing CMake via the github release artifact as follows: CMAKE\_VERSION="3.27.7" echo "Installing CMake ${CMAKE\_VERSION}" wget https://github.com/Kitware/CMake/releases/download/v${CMAKE\_VERSION}/cmake-${CMAKE\_V…

---

## [Xcode ‘C++ and Objective-C Interoperability’ build setting not getting set](https://discourse.cmake.org/t/xcode-c-and-objective-c-interoperability-build-setting-not-getting-set/9337)

<div class="topic-metadata">

**Author:** [@Vipul\_Gupta](https://discourse.cmake.org/u/Vipul_Gupta)\
**Replies:** 3\
**Last updated:** [November 8, 2023, 4:45pm UTC](https://discourse.cmake.org/t/xcode-c-and-objective-c-interoperability-build-setting-not-getting-set/9337 "2023-11-08T16:45:50Z")

</div>

I m trying to create an xcode project with cpp-swift interoperability(introduced in xcode15) using cmake xcode generator. I m able to invoke cpp code in swift and vice-versa but when opening the project in xcode IDE, the…

---

## [New To CMake and Looking For Guidance](https://discourse.cmake.org/t/new-to-cmake-and-looking-for-guidance/9378)

<div class="topic-metadata">

**Author:** [@apek75](https://discourse.cmake.org/u/apek75)\
**Replies:** 2\
**Last updated:** [November 7, 2023, 6:39pm UTC](https://discourse.cmake.org/t/new-to-cmake-and-looking-for-guidance/9378 "2023-11-07T18:39:00Z")

</div>

Dear CMake, I am looking for your assistance in helping troubleshoot the below and am a CMake newby given the compassionate leave of my CTO. I have verified that the OpenCV module folder path is indeed current. Please c…

---

## [Use of include\_guard](https://discourse.cmake.org/t/use-of-include-guard/9370)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 1\
**Last updated:** [November 7, 2023, 4:00am UTC](https://discourse.cmake.org/t/use-of-include-guard/9370 "2023-11-07T04:00:43Z")

</div>

Is include\_guard still expected to only work for include and not add\_subdirectory (see https://gitlab.kitware.com/cmake/cmake/-/issues/17895 )? We have a setup where modules add\_subdirectory their direct dependencies, w…

---

## [Disallow numbers as variable names](https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354)

<div class="topic-metadata">

**Author:** [@trmagma](https://discourse.cmake.org/u/trmagma)\
**Replies:** 1\
**Last updated:** [November 3, 2023, 3:39pm UTC](https://discourse.cmake.org/t/disallow-numbers-as-variable-names/9354 "2023-11-03T15:39:41Z")

</div>

I found a strange behavior: if ( value EQUAL 0 ) did not match even if value has the value 0. The cause was, that it seems that there was a variable ${0} which had a value different from 0. The following example demons…

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

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