# Code

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

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

**Page:** 15

---

## [Problems getting CMake to install the HEADERS file set](https://discourse.cmake.org/t/problems-getting-cmake-to-install-the-headers-file-set/13048)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 2\
**Last updated:** [November 24, 2024, 7:12pm UTC](https://discourse.cmake.org/t/problems-getting-cmake-to-install-the-headers-file-set/13048 "2024-11-24T19:12:34Z")

</div>

Given the following CMakeLists.txt: cmake\_minimum\_required(VERSION 3.27) project(gubbins) set(CMAKE\_CXX\_STANDARD 14) set(CMAKE\_CXX\_VISIBILITY\_PRESET hidden) set(CMAKE\_VISIBILITY\_INLINES\_HIDDEN YES) add\_library(gubbins…

---

## [Do I need to quote list value for set(PARENT\_SCOPE)?](https://discourse.cmake.org/t/do-i-need-to-quote-list-value-for-set-parent-scope/13043)

<div class="topic-metadata">

**Author:** [@silverqx](https://discourse.cmake.org/u/silverqx)\
**Replies:** 2\
**Last updated:** [November 24, 2024, 12:57pm UTC](https://discourse.cmake.org/t/do-i-need-to-quote-list-value-for-set-parent-scope/13043 "2024-11-24T12:57:06Z")

</div>

Do I need to quote that ${l1} value? I tested it and it works as expected without quotes. function(f1) list(APPEND l1 "v1") set(l1 ${l1} PARENT\_SCOPE) endfunction()

---

## [Supplying if() condition arguments via list variable](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015)

<div class="topic-metadata">

**Author:** [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Replies:** 3\
**Last updated:** [November 22, 2024, 1:25am UTC](https://discourse.cmake.org/t/supplying-if-condition-arguments-via-list-variable/13015 "2024-11-22T01:25:02Z")

</div>

I know it’s not uncommon to do things like this: set(\_my\_targets lib1 lib2 mainexe configexe) install( TARGETS ${\_my\_targets} RUNTIME DESTINATION ... ) Or this… set(\_qt\_components Core Network Widgets) find\_packag…

---

## [Inject "/EHa" MSVC option via CXXFLAGS for Visual Studio generator - not possible?](https://discourse.cmake.org/t/inject-eha-msvc-option-via-cxxflags-for-visual-studio-generator-not-possible/13014)

<div class="topic-metadata">

**Author:** [@YN\_Slb](https://discourse.cmake.org/u/YN_Slb)\
**Replies:** 0\
**Last updated:** [November 21, 2024, 3:01pm UTC](https://discourse.cmake.org/t/inject-eha-msvc-option-via-cxxflags-for-visual-studio-generator-not-possible/13014 "2024-11-21T15:01:17Z")

</div>

Per Microsoft documentation (/EH (Exception handling model) | Microsoft Learn), /EHa overrides both /EHs and /EHc arguments But, when these options are not provided by CMake to compiler directly - because of using Vi…

---

## [Best way to preserve downloaded files with \`ExternalProject\_Add()\`](https://discourse.cmake.org/t/best-way-to-preserve-downloaded-files-with-externalproject-add/12995)

<div class="topic-metadata">

**Author:** [@yashi](https://discourse.cmake.org/u/yashi)\
**Replies:** 0\
**Last updated:** [November 20, 2024, 7:24am UTC](https://discourse.cmake.org/t/best-way-to-preserve-downloaded-files-with-externalproject-add/12995 "2024-11-20T07:24:39Z")

</div>

I’m using multiple ExternalProject\_Add() calls with URL to manage my dependencies. While it works fine, the specified files are downloaded into my build directory. When I want to perform a clean build, I usually remove …

---

## [Problem with FetchContent dependencies when using XYZ\_DIR (XYZ\_ROOT works)](https://discourse.cmake.org/t/problem-with-fetchcontent-dependencies-when-using-xyz-dir-xyz-root-works/12987)

<div class="topic-metadata">

**Author:** [@eXpl0it3r](https://discourse.cmake.org/u/eXpl0it3r)\
**Replies:** 1\
**Last updated:** [November 19, 2024, 7:31pm UTC](https://discourse.cmake.org/t/problem-with-fetchcontent-dependencies-when-using-xyz-dir-xyz-root-works/12987 "2024-11-19T19:31:31Z")

</div>

For SFML we’re attempting to move away from checked-in binaries to using FetchContent and building the dependencies on-the-fly. This seems to work pretty well, expect in the case when consuming SFML via find\_package whi…

---

## [What is / Is there a relation between exporting symbols and public methods and shared libraries?](https://discourse.cmake.org/t/what-is-is-there-a-relation-between-exporting-symbols-and-public-methods-and-shared-libraries/12734)

<div class="topic-metadata">

**Author:** [@BenEngbers](https://discourse.cmake.org/u/BenEngbers)\
**Replies:** 3\
**Last updated:** [November 19, 2024, 8:37pm UTC](https://discourse.cmake.org/t/what-is-is-there-a-relation-between-exporting-symbols-and-public-methods-and-shared-libraries/12734 "2024-11-19T20:37:15Z")

</div>

I started with a simple CMakeLists.txt for creating a shared library. After developing working source code in Eclipse, I copied that source code to a new directory, generated a shared library there and then linked the li…

---

## [Proper way to install library with external dependencies ?](https://discourse.cmake.org/t/proper-way-to-install-library-with-external-dependencies/12992)

<div class="topic-metadata">

**Author:** [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)\
**Replies:** 0\
**Last updated:** [November 19, 2024, 7:10pm UTC](https://discourse.cmake.org/t/proper-way-to-install-library-with-external-dependencies/12992 "2024-11-19T19:10:24Z")

</div>

Hello My library (odbc++) has a public dependency on ODBC32.dll, I can successfully use: find\_library(ODBC\_LIBRARY\_PATH "ODBC32") target\_link\_libraries(odbc++ PUBLIC "${ODBC\_LIBRARY\_PATH}") and cmake would find the a…

---

## [what is the function \`set\`](https://discourse.cmake.org/t/what-is-the-function-set/12988)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 1\
**Last updated:** [November 19, 2024, 10:45am UTC](https://discourse.cmake.org/t/what-is-the-function-set/12988 "2024-11-19T10:45:07Z")

</div>

set just set the variable. Why does it not only declare but also work for add\_executable? Because I try to comment the line and the build will fail. And EXAMPLE\_SRCS\_WINDOWS was only used on here. I don’t see anywhere…

---

## [Building a combined static library](https://discourse.cmake.org/t/building-a-combined-static-library/12962)

<div class="topic-metadata">

**Author:** [@zaufi](https://discourse.cmake.org/u/zaufi)\
**Replies:** 3\
**Last updated:** [November 18, 2024, 3:23pm UTC](https://discourse.cmake.org/t/building-a-combined-static-library/12962 "2024-11-18T15:23:53Z")

</div>

I have a project that builds a static library. It depends on a dozen other projects (some of 'em are mine, also building static libraries) that look up through find\_package() and have imported targets. Giving a build opt…

---

## [Difference between define\_property and set\_property](https://discourse.cmake.org/t/difference-between-define-property-and-set-property/12981)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 6\
**Last updated:** [November 18, 2024, 12:49pm UTC](https://discourse.cmake.org/t/difference-between-define-property-and-set-property/12981 "2024-11-18T12:49:57Z")

</div>

Hello, I am reading a CMake code with: define\_property(GLOBAL PROPERTY SomeLib\_INCLUDED BRIEF\_DOCS "Some doc" FULL\_DOCS "Some full doc") get\_property(INCLUDED GLOBAL PROPERTY SomeLib\_INCLUDED SET) if(NOT INCLUDED) s…

---

## [CMake 3.31: Replacement for add\_custom\_command(TARGET ... USES\_TERMINAL)?](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 7\
**Last updated:** [November 16, 2024, 9:19pm UTC](https://discourse.cmake.org/t/cmake-3-31-replacement-for-add-custom-command-target-uses-terminal/12935 "2024-11-16T21:19:15Z")

</div>

CMake 3.31 complains that USES\_TERMINAL is not valid with add\_custom\_command(TARGET...) CMake Warning (dev) at etc/cmake/benchmark\_helpers.cmake:24 (add\_custom\_command): The following keywords are not supported when u…

---

## [\<PackageName\>\_ROOT vs \<PackageName\>\_ROOT\_DIR](https://discourse.cmake.org/t/packagename-root-vs-packagename-root-dir/12931)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 4\
**Last updated:** [November 16, 2024, 8:59pm UTC](https://discourse.cmake.org/t/packagename-root-vs-packagename-root-dir/12931 "2024-11-16T20:59:50Z")

</div>

Hello, there is \<PackageName\>\_ROOT\_DIR variable mentioned in the documentation and I’m not sure I understand why should this variable be used if there is already automatic CMake handling done by \<PackageName\>\_ROOT variab…

---

## [No way retrieve the value of the --prefix argument at install-time?](https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974)

<div class="topic-metadata">

**Author:** [@jcm](https://discourse.cmake.org/u/jcm)\
**Replies:** 1\
**Last updated:** [November 15, 2024, 9:09pm UTC](https://discourse.cmake.org/t/no-way-retrieve-the-value-of-the-prefix-argument-at-install-time/12974 "2024-11-15T21:09:02Z")

</div>

I have a project that, if a CMAKE\_INSTALL\_PREFIX is provided at configure/generation-time, provides that prefix to the project code to help out with certain search paths and file storage logic. I wanted to provide a war…

---

## [What's the best method to retrieve include files from Git ?](https://discourse.cmake.org/t/whats-the-best-method-to-retrieve-include-files-from-git/12973)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 0\
**Last updated:** [November 15, 2024, 3:12pm UTC](https://discourse.cmake.org/t/whats-the-best-method-to-retrieve-include-files-from-git/12973 "2024-11-15T15:12:51Z")

</div>

Hello, I have a Git repository where there are two directories. The first one contain only .h file. I have two needs (especially the first one): I want to download them in comsusing projects. ExternalProject\_Add() ?…

---

## [Relocatable package that correctly handles the included directories...is it possible?](https://discourse.cmake.org/t/relocatable-package-that-correctly-handles-the-included-directories-is-it-possible/12955)

<div class="topic-metadata">

**Author:** [@JtTest](https://discourse.cmake.org/u/JtTest)\
**Replies:** 0\
**Last updated:** [November 12, 2024, 2:21pm UTC](https://discourse.cmake.org/t/relocatable-package-that-correctly-handles-the-included-directories-is-it-possible/12955 "2024-11-12T14:21:39Z")

</div>

Hi there, I have realized a Linux library fooLib that provides some functions to be used with alsa-lib data types. I want cmake to configure the compilation of the library and also to create a relocatable package that u…

---

## [Exit with custom status code](https://discourse.cmake.org/t/exit-with-custom-status-code/12944)

<div class="topic-metadata">

**Author:** [@tomoyo255](https://discourse.cmake.org/u/tomoyo255)\
**Replies:** 3\
**Last updated:** [November 12, 2024, 9:08am UTC](https://discourse.cmake.org/t/exit-with-custom-status-code/12944 "2024-11-12T09:08:07Z")

</div>

Hello, I would like to know if there’s a way to exit at will from a cmake CMakeLists.txt with a status code of my choice. If the current cmake list corresponds to one of a subdirectory suggesting a nested execution, it…

---

## [using build preset with ExternalProject\_Add](https://discourse.cmake.org/t/using-build-preset-with-externalproject-add/12902)

<div class="topic-metadata">

**Author:** [@fws](https://discourse.cmake.org/u/fws)\
**Replies:** 15\
**Last updated:** [November 9, 2024, 9:08pm UTC](https://discourse.cmake.org/t/using-build-preset-with-externalproject-add/12902 "2024-11-09T21:08:58Z")

</div>

Hello, for a part of my project I use a qnx compiler that needs QNX\_HOST and QNX\_TARGET environment variables to be set. To archive that I use cmake --preset for configuration and for building the project is build for…

---

## [set the resource.rc file](https://discourse.cmake.org/t/set-the-resource-rc-file/12925)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 0\
**Last updated:** [November 9, 2024, 1:28pm UTC](https://discourse.cmake.org/t/set-the-resource-rc-file/12925 "2024-11-09T13:28:31Z")

</div>

How does the EXAMPLE\_RESOURCES\_SRCS\_WINDOWS work? The code just set the varibale and it was only used on here. If I comment the win/resource.rc, it will build fail.

---

## [CMake Clang C++20 Modules possible Mismatch](https://discourse.cmake.org/t/cmake-clang-c-20-modules-possible-mismatch/12921)

<div class="topic-metadata">

**Author:** [@Kelarov](https://discourse.cmake.org/u/Kelarov)\
**Replies:** 1\
**Last updated:** [November 9, 2024, 1:10am UTC](https://discourse.cmake.org/t/cmake-clang-c-20-modules-possible-mismatch/12921 "2024-11-09T01:10:56Z")

</div>

Hi, all. I am trying out C++20 Modules as well as CMake’s experimental support for import std; and have come across something curious. It’s about what clang calls “internal module partition unit” and cppreference calls…

---

## [IMPORTED\_LOCATION not set for imported target "opencv\_core".](https://discourse.cmake.org/t/imported-location-not-set-for-imported-target-opencv-core/9162)

<div class="topic-metadata">

**Author:** [@tspdx](https://discourse.cmake.org/u/tspdx)\
**Replies:** 3\
**Last updated:** [November 6, 2024, 8:18pm UTC](https://discourse.cmake.org/t/imported-location-not-set-for-imported-target-opencv-core/9162 "2024-11-06T20:18:52Z")

</div>

I’m cross-compiling a Linux library for ARM using dockcross and linking to OpenCV. OpenCV builds and installs successfully, but configuring my library gives me errors like this: CMake Error in build/\_deps/mylib-src/CMak…

---

## [Problem specifying Install Prefix](https://discourse.cmake.org/t/problem-specifying-install-prefix/12897)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 2\
**Last updated:** [November 5, 2024, 5:35pm UTC](https://discourse.cmake.org/t/problem-specifying-install-prefix/12897 "2024-11-05T17:35:05Z")

</div>

I wrote: set(CMAKE\_INSTALL\_PREFIX ${CMAKE\_SOURCE\_DIR}/${CMAKE\_VS\_PLATFORM\_NAME}/$\<CONFIG\>) message ("Install prefix set to: " ${CMAKE\_INSTALL\_PREFIX}) Which reported: Install prefix set to: C:/Users/amonra/Documents/G…

---

## [Building a shared library that depends on a shared library produced by GraalVM's native-image](https://discourse.cmake.org/t/building-a-shared-library-that-depends-on-a-shared-library-produced-by-graalvms-native-image/12879)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 2\
**Last updated:** [November 5, 2024, 3:35pm UTC](https://discourse.cmake.org/t/building-a-shared-library-that-depends-on-a-shared-library-produced-by-graalvms-native-image/12879 "2024-11-05T15:35:51Z")

</div>

I’m working on a project where we have a C++ shared library which is (effectively) an API wrapper around our Java library, which is compiled down to C using GraalVM’s native-image tool. The library is cross-platform, ta…

---

## [How to specify the name of the file to generate pre-compiled headers?](https://discourse.cmake.org/t/how-to-specify-the-name-of-the-file-to-generate-pre-compiled-headers/12887)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 1\
**Last updated:** [November 2, 2024, 9:22pm UTC](https://discourse.cmake.org/t/how-to-specify-the-name-of-the-file-to-generate-pre-compiled-headers/12887 "2024-11-02T21:22:24Z")

</div>

I have this in my CMakeList file: target\_precompile\_headers(DeepSkyStacker PRIVATE stdafx.h ) I also have an existing file to generate the pre-compiled headers called stdafx.cpp However CMake creates a file called c…

---

## [Problems linking](https://discourse.cmake.org/t/problems-linking/12885)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 4\
**Last updated:** [November 2, 2024, 2:44pm UTC](https://discourse.cmake.org/t/problems-linking/12885 "2024-11-02T14:44:41Z")

</div>

My project uses some prebuilt lib files which are stored in C:\\Users\\amonra\\Documents\\GitHub\\DSS\\libs\\Win64\\DebugLibs and C:\\Users\\amonra\\Documents\\GitHub\\DSS\\libs\\Win64\\ReleaseLibs so for example exiv2d.lib is in th…

---

## [Error install cxx-module on VS 2022](https://discourse.cmake.org/t/error-install-cxx-module-on-vs-2022/12774)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 3\
**Last updated:** [October 18, 2024, 7:08pm UTC](https://discourse.cmake.org/t/error-install-cxx-module-on-vs-2022/12774 "2024-10-18T19:08:10Z")

</div>

With this cmake example I got this error on Windows CI 0s Run cmake --install build --config Release --prefix stagedir -- Installing: D:/a/cmake-init-modules/cmake-init-modules/stagedir/lib/Algo.lib -- Installing: D:/a…

---

## [Generate for VS2022 sets Character Set to "Use Multi-Byte Character Set"](https://discourse.cmake.org/t/generate-for-vs2022-sets-character-set-to-use-multi-byte-character-set/12870)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 4\
**Last updated:** [October 31, 2024, 1:39pm UTC](https://discourse.cmake.org/t/generate-for-vs2022-sets-character-set-to-use-multi-byte-character-set/12870 "2024-10-31T13:39:27Z")

</div>

Which I don’t want - I want it to be set to “Not Set” as I don’t want the \_MBCS define to be generated by Visual Studio. How can I stop this please?

---

## [How to use ctest --build-and-test for single and multi config generators?](https://discourse.cmake.org/t/how-to-use-ctest-build-and-test-for-single-and-multi-config-generators/12868)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 3\
**Last updated:** [October 31, 2024, 9:52am UTC](https://discourse.cmake.org/t/how-to-use-ctest-build-and-test-for-single-and-multi-config-generators/12868 "2024-10-31T09:52:25Z")

</div>

I found a problem wenn generate a visual studio project instead a ninja project: The CMAKE\_BUILD\_TYPE is not set and I must use the --build-config options! diff --git a/src/beman/execution26/tests/CMakeLists.txt b/src/…

---

## [Generating intermediate assembly files during compilation](https://discourse.cmake.org/t/generating-intermediate-assembly-files-during-compilation/12867)

<div class="topic-metadata">

**Author:** [@reimu](https://discourse.cmake.org/u/reimu)\
**Replies:** 0\
**Last updated:** [October 30, 2024, 7:30pm UTC](https://discourse.cmake.org/t/generating-intermediate-assembly-files-during-compilation/12867 "2024-10-30T19:30:50Z")

</div>

Hi, I want to make CMake generate intermediate assembly files for my C/C++ source code files and assemble them into object files in two distinct steps, and I want to know the most correct way of doing this. If this req…

---

## [Make some library's code private some consumers, but public for tests](https://discourse.cmake.org/t/make-some-librarys-code-private-some-consumers-but-public-for-tests/10886)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 6\
**Last updated:** [October 30, 2024, 12:21am UTC](https://discourse.cmake.org/t/make-some-librarys-code-private-some-consumers-but-public-for-tests/10886 "2024-10-30T00:21:39Z")

</div>

Hello, I made a library project, and followed the classical pattern, where I put the implementation details in a src directory, and the interface in a include/MyLib directory. So the external consumers see what is expo…

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

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