# Code

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

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

**Page:** 7

---

## [I How to solve MSB8066 error encountered during cmake compilation?](https://discourse.cmake.org/t/i-how-to-solve-msb8066-error-encountered-during-cmake-compilation/15154)

<div class="topic-metadata">

**Author:** [@vicissitude123](https://discourse.cmake.org/u/vicissitude123)\
**Replies:** 3\
**Last updated:** [September 6, 2025, 6:09pm UTC](https://discourse.cmake.org/t/i-how-to-solve-msb8066-error-encountered-during-cmake-compilation/15154 "2025-09-06T18:09:47Z")

</div>

“D:\\OpenCV\\opencv-4.12.0\\VTK-9.3.1vs\\CMakeFiles\\908bb35add7358600b32c3098aaedf76\\vtkDepthPeelingPassIntermediateFS.h.rule;D:\\OpenCV\\opencv-4.12.0\\VTK-9.3.1vs\\CMakeFiles\\908bb35add7358600b32c3098aaedf76\\vtkEDLBilateralFil…

---

## [install(TARGETS...RUNTIME\_DEPENDENCIES...): file Could not resolve runtime dependencies for other targets](https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150)

<div class="topic-metadata">

**Author:** [@Anton\_Kryukov](https://discourse.cmake.org/u/Anton_Kryukov)\
**Replies:** 1\
**Last updated:** [September 6, 2025, 5:18pm UTC](https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150 "2025-09-06T17:18:07Z")

</div>

I am using CMake 3.31 and the Visual Studio generator in this example, but I don’t think it should matter for the problem that I am facing. My project has many targets T1, T2,… All targets have install rules install(TA…

---

## [error: source file is not valid UTF-8](https://discourse.cmake.org/t/error-source-file-is-not-valid-utf-8/10148)

<div class="topic-metadata">

**Author:** [@shokarta](https://discourse.cmake.org/u/shokarta)\
**Replies:** 3\
**Last updated:** [September 4, 2025, 7:41am UTC](https://discourse.cmake.org/t/error-source-file-is-not-valid-utf-8/10148 "2025-09-04T07:41:12Z")

</div>

Hello, so the situation is: from Win10 64 I run Virtual Machine where the guest is MacOS, From Win10 I share a folder with all projects (sources as well as builds folders). When opening projects and run Cmake which crea…

---

## [Invoking compiler in custom command with properties from a target](https://discourse.cmake.org/t/invoking-compiler-in-custom-command-with-properties-from-a-target/15145)

<div class="topic-metadata">

**Author:** [@rleigh](https://discourse.cmake.org/u/rleigh)\
**Replies:** 1\
**Last updated:** [September 4, 2025, 5:18am UTC](https://discourse.cmake.org/t/invoking-compiler-in-custom-command-with-properties-from-a-target/15145 "2025-09-04T05:18:21Z")

</div>

Hi folks, What I’m trying to do is to run the C or C++ preprocessor with -E for each source file associated with a target (using the ninja generator). While I could potentially do this via compile\_commands.json I’d pre…

---

## [Can't reuse PCH generated when compiling a library](https://discourse.cmake.org/t/cant-reuse-pch-generated-when-compiling-a-library/15107)

<div class="topic-metadata">

**Author:** [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Replies:** 11\
**Last updated:** [September 3, 2025, 1:08pm UTC](https://discourse.cmake.org/t/cant-reuse-pch-generated-when-compiling-a-library/15107 "2025-09-03T13:08:01Z")

</div>

I am trying to use precompiled headers in my project, but I’m finding a strange issue. I put together a simple reproducer, where I have a header which I want to precompile when building a shared library (lib1) and then r…

---

## [Equivalent of INTERFACE for set\_target\_properties](https://discourse.cmake.org/t/equivalent-of-interface-for-set-target-properties/15141)

<div class="topic-metadata">

**Author:** [@rdong8](https://discourse.cmake.org/u/rdong8)\
**Replies:** 1\
**Last updated:** [September 1, 2025, 10:04pm UTC](https://discourse.cmake.org/t/equivalent-of-interface-for-set-target-properties/15141 "2025-09-01T22:04:41Z")

</div>

add\_library(config INTERFACE) set\_target\_properties(config PROPERTIES COMPILE\_WARNING\_AS\_ERROR ON LINK\_WARNING\_AS\_ERROR ON ) add\_executable(exec PRIVATE main.cpp) target\_link\_libraries(exec PRIV…

---

## [protobuf\_generate() seems to be generating incorrect paths. Usage error or bug?](https://discourse.cmake.org/t/protobuf-generate-seems-to-be-generating-incorrect-paths-usage-error-or-bug/15112)

<div class="topic-metadata">

**Author:** [@GarrettK](https://discourse.cmake.org/u/GarrettK)\
**Replies:** 2\
**Last updated:** [August 27, 2025, 4:34pm UTC](https://discourse.cmake.org/t/protobuf-generate-seems-to-be-generating-incorrect-paths-usage-error-or-bug/15112 "2025-08-27T16:34:21Z")

</div>

I’m working on a larger project which currently performs in-tree out-of-build protobuf generation. I’m looking at converting to using in-build protobuf generation with CMake’s support. Unfortunately, I’m running into iss…

---

## [Having trouble getting TEST\_LAUNCHER to work](https://discourse.cmake.org/t/having-trouble-getting-test-launcher-to-work/15093)

<div class="topic-metadata">

**Author:** [@chriskot870](https://discourse.cmake.org/u/chriskot870)\
**Replies:** 1\
**Last updated:** [August 27, 2025, 7:57am UTC](https://discourse.cmake.org/t/having-trouble-getting-test-launcher-to-work/15093 "2025-08-27T07:57:57Z")

</div>

TEST\_LAUNCHER requires 3.29 and my version in /usr/bin. I downloaded the newest cmake and installed in /usr/local/bin. /usr/local/bin/cmake --version cmake version 4.1.0 CMake suite maintained and supported by Kitware…

---

## [CMAKE\_CXX\_CPPCHECK - scope leak](https://discourse.cmake.org/t/cmake-cxx-cppcheck-scope-leak/15114)

<div class="topic-metadata">

**Author:** [@Mathias\_B](https://discourse.cmake.org/u/Mathias_B)\
**Replies:** 0\
**Last updated:** [August 27, 2025, 7:31am UTC](https://discourse.cmake.org/t/cmake-cxx-cppcheck-scope-leak/15114 "2025-08-27T07:31:13Z")

</div>

Hello, I am using CMake 4.1.0 with the following generators : Unix Makefiles on Linux MSYS Makefiles on Windows These are used to build a C++ project. My filetree looks like this : Toplevel: - CMakeLists.txt …

---

## [FetchContent a directory but add a subdirectory](https://discourse.cmake.org/t/fetchcontent-a-directory-but-add-a-subdirectory/8603)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 17\
**Last updated:** [August 22, 2025, 4:54am UTC](https://discourse.cmake.org/t/fetchcontent-a-directory-but-add-a-subdirectory/8603 "2025-08-22T04:54:42Z")

</div>

I have some code using git submodules that is: Working on a full checkout of the highs library, let’s say in deps/highs. Calling add\_subdirectory(deps/highs/src). The deps/highs/src/CMakeLists.txt file contains refere…

---

## [CMake Tutorial Step 3 Exercise 2](https://discourse.cmake.org/t/cmake-tutorial-step-3-exercise-2/15046)

<div class="topic-metadata">

**Author:** [@Kyuhyun\_Park](https://discourse.cmake.org/u/Kyuhyun_Park)\
**Replies:** 0\
**Last updated:** [August 18, 2025, 8:24pm UTC](https://discourse.cmake.org/t/cmake-tutorial-step-3-exercise-2/15046 "2025-08-18T20:24:49Z")

</div>

I am trying to get some help on a CMake tutorial, Step 3, Exercise 2 https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Usage%20Requirements%20for%20a%20Library.html#exercise-2-setting-the-c-standard-with-inter…

---

## [compiler options after LINK\_FLAGS and](https://discourse.cmake.org/t/compiler-options-after-link-flags-and/15071)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 3\
**Last updated:** [August 19, 2025, 8:58pm UTC](https://discourse.cmake.org/t/compiler-options-after-link-flags-and/15071 "2025-08-19T20:58:16Z")

</div>

I am sure I did something stupid but one of these things also appears to be platform specific. I don’t generally create cmake scripts for shared libraries from scratch, but am trying for a new project now. Created an em…

---

## [add\_test() assumes test executable is first string after COMMAND](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012)

<div class="topic-metadata">

**Author:** [@chriskot870](https://discourse.cmake.org/u/chriskot870)\
**Replies:** 5\
**Last updated:** [August 16, 2025, 10:43pm UTC](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012 "2025-08-16T22:43:47Z")

</div>

I am using cmake through vscode to cross-compile from a Ubuntu host to a Raspberry Pi Zero 2W target. I need to run the tests on the remote host. I created the following add\_test: add\_test( NAME UnitsPressureTests W…

---

## [Qt6 and CMake - Unable to Link Library (R3DSDK)](https://discourse.cmake.org/t/qt6-and-cmake-unable-to-link-library-r3dsdk/14973)

<div class="topic-metadata">

**Author:** [@bayetan](https://discourse.cmake.org/u/bayetan)\
**Replies:** 14\
**Last updated:** [August 10, 2025, 12:37pm UTC](https://discourse.cmake.org/t/qt6-and-cmake-unable-to-link-library-r3dsdk/14973 "2025-08-10T12:37:54Z")

</div>

Hello All, New to CMkae and been struggling with try to build a simple CMake project to link to a library using Qt6 and CMake. Below is my CMakeList.txt and below that is the Compiler output. There seems to be many wa…

---

## [CMake presets: \`inherit\` makes it hard to include toolchain file](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784)

<div class="topic-metadata">

**Author:** [@flodin](https://discourse.cmake.org/u/flodin)\
**Replies:** 5\
**Last updated:** [August 8, 2025, 11:16am UTC](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784 "2025-08-08T11:16:02Z")

</div>

Hi, We have a CMake structure where there is a common platform which can be built by itself or included via different sub-components. Since the platform is always used by the sub-components we thought it a good fit to …

---

## [No executable in Visual Studio despite the CMake compiling](https://discourse.cmake.org/t/no-executable-in-visual-studio-despite-the-cmake-compiling/14895)

<div class="topic-metadata">

**Author:** [@FabianDim](https://discourse.cmake.org/u/FabianDim)\
**Replies:** 6\
**Last updated:** [August 6, 2025, 6:53pm UTC](https://discourse.cmake.org/t/no-executable-in-visual-studio-despite-the-cmake-compiling/14895 "2025-08-06T18:53:08Z")

</div>

full repo: https\[delete me\]://github.com/FabianDim/InvokeInvoiceSystem I have attempted to refactor my code to have two cmake files, I put it in the CMakeList.txt as a subdir. The CMake build generates in VS and display…

---

## [Unexpected behavior when using target\_sources](https://discourse.cmake.org/t/unexpected-behavior-when-using-target-sources/14926)

<div class="topic-metadata">

**Author:** [@Idono](https://discourse.cmake.org/u/Idono)\
**Replies:** 4\
**Last updated:** [August 6, 2025, 6:25pm UTC](https://discourse.cmake.org/t/unexpected-behavior-when-using-target-sources/14926 "2025-08-06T18:25:11Z")

</div>

Hi. I’m relatively new to cmake and learning it mostly doing small projects. I’ve got some questions related to target\_sources. My understanding of it is that if i omit source files in add\_library i should be able to ad…

---

## [QNX SDP 8 Compiler flag \`-lang-c++\` now marked as deprecated](https://discourse.cmake.org/t/qnx-sdp-8-compiler-flag-lang-c-now-marked-as-deprecated/12695)

<div class="topic-metadata">

**Author:** [@jcurl](https://discourse.cmake.org/u/jcurl)\
**Replies:** 25\
**Last updated:** [August 4, 2025, 5:08pm UTC](https://discourse.cmake.org/t/qnx-sdp-8-compiler-flag-lang-c-now-marked-as-deprecated/12695 "2025-08-04T17:08:16Z")

</div>

I’m testing my CMake project (v3.16 to support at least Ubuntu 20.04 LTS and later). With QNX8, there are new warnings saying that “cc: warning - lang-c++ is deprecated”. This is documented by QNX at QNX Momentics IDE, …

---

## [CMake Qt project suddenly failing: “Cannot find source file” with duplicated file path after Git reset / vcpkg changes](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481)

<div class="topic-metadata">

**Author:** [@FabianDim](https://discourse.cmake.org/u/FabianDim)\
**Replies:** 2\
**Last updated:** [August 3, 2025, 3:45am UTC](https://discourse.cmake.org/t/cmake-qt-project-suddenly-failing-cannot-find-source-file-with-duplicated-file-path-after-git-reset-vcpkg-changes/14481 "2025-08-03T03:45:58Z")

</div>

Context: I have a CMake project that was working for building a Qt6 app using MSVC 2022, CMake, and vcpkg (manifest mode). I made some changes to try and get the project running fully via vcpkg, didn’t succeed, so I chec…

---

## [Example: GNU Patch from CMake](https://discourse.cmake.org/t/example-gnu-patch-from-cmake/4492)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 1\
**Last updated:** [August 1, 2025, 3:09pm UTC](https://discourse.cmake.org/t/example-gnu-patch-from-cmake/4492 "2025-08-01T15:09:27Z")

</div>

To patch files in one’s own project, or when using other projects via FetchContent etc., it’s possible to patch source/header/etc. using GNU Patch and add\_custom\_command() with the benefit of CMake canonical approach (tr…

---

## [variable scoping confusion..](https://discourse.cmake.org/t/variable-scoping-confusion/11425)

<div class="topic-metadata">

**Author:** [@duaneellis\_inno](https://discourse.cmake.org/u/duaneellis_inno)\
**Replies:** 3\
**Last updated:** [August 1, 2025, 10:45am UTC](https://discourse.cmake.org/t/variable-scoping-confusion/11425 "2025-08-01T10:45:22Z")

</div>

I am totally confused about the set() command and variable scoping. I am trying to refactor a number of things into smaller reusable cmake things and when I do - things go wrong - really wrong. For example - I want to …

---

## [Populate include directories from sub\_directory to all of parts of the project. How?](https://discourse.cmake.org/t/populate-include-directories-from-sub-directory-to-all-of-parts-of-the-project-how/14449)

<div class="topic-metadata">

**Author:** [@alexandr](https://discourse.cmake.org/u/alexandr)\
**Replies:** 20\
**Last updated:** [July 31, 2025, 6:43am UTC](https://discourse.cmake.org/t/populate-include-directories-from-sub-directory-to-all-of-parts-of-the-project-how/14449 "2025-07-31T06:43:33Z")

</div>

Hello all! My project have this structure: Application (add\_executable) | – Library 1 (add\_subdirectory in application and add\_library in library) | – Library 2 (add\_subdirectory in application and add\_library in lib…

---

## [ExternalProject\_Add + autotools](https://discourse.cmake.org/t/externalproject-add-autotools/14475)

<div class="topic-metadata">

**Author:** [@moi15moi](https://discourse.cmake.org/u/moi15moi)\
**Replies:** 0\
**Last updated:** [July 31, 2025, 12:56am UTC](https://discourse.cmake.org/t/externalproject-add-autotools/14475 "2025-07-31T00:56:56Z")

</div>

I have this CMakeLists.txt file. The goal of this CMakeLists.txt is simply to have a shared library that contain all libass dependencies. To do so, we use libass-cmake. It build libass and it’s dependencies. Here is how…

---

## [Python\_SOABI should match version of find\_package(Python3 VERSION)](https://discourse.cmake.org/t/python-soabi-should-match-version-of-find-package-python3-version/14452)

<div class="topic-metadata">

**Author:** [@fabian\_schutze](https://discourse.cmake.org/u/fabian_schutze)\
**Replies:** 1\
**Last updated:** [July 28, 2025, 9:25am UTC](https://discourse.cmake.org/t/python-soabi-should-match-version-of-find-package-python3-version/14452 "2025-07-28T09:25:42Z")

</div>

The following CMake statement: find\_package(Python3 3.11 EXACT COMPONENTS Development Interpreter REQUIRED) message("The extension suffix is: ${Python\_SOABI}") Produces: The extension suffix is: cpython-312-x86\_64-lin…

---

## [Why does install() raise an error when RESOURCE is given a directory but CMake happily builds the app bundle?](https://discourse.cmake.org/t/why-does-install-raise-an-error-when-resource-is-given-a-directory-but-cmake-happily-builds-the-app-bundle/11374)

<div class="topic-metadata">

**Author:** [@MarkCallow](https://discourse.cmake.org/u/MarkCallow)\
**Replies:** 3\
**Last updated:** [July 27, 2025, 11:49am UTC](https://discourse.cmake.org/t/why-does-install-raise-an-error-when-resource-is-given-a-directory-but-cmake-happily-builds-the-app-bundle/11374 "2025-07-27T11:49:58Z")

</div>

One of the items I add to the RESOURCE property for my macOS app bundle is a directory. CMake happily creates the bundle with that directory and its hierarchy in the “Resources” directory. The app works fine. However wh…

---

## [configure files based on target](https://discourse.cmake.org/t/configure-files-based-on-target/14451)

<div class="topic-metadata">

**Author:** [@walliscode](https://discourse.cmake.org/u/walliscode)\
**Replies:** 0\
**Last updated:** [July 26, 2025, 6:55pm UTC](https://discourse.cmake.org/t/configure-files-based-on-target/14451 "2025-07-26T18:55:05Z")

</div>

I’m storing data for unit tests in its own test\_data/ directory (mimicing the /data in the project directory). Currently i pass directory paths to the code using getDataDirectory() in a paths.h/paths.cpp.in file and use…

---

## [How to get the default suffix of executables?](https://discourse.cmake.org/t/how-to-get-the-default-suffix-of-executables/11476)

<div class="topic-metadata">

**Author:** [@ikspress](https://discourse.cmake.org/u/ikspress)\
**Replies:** 1\
**Last updated:** [July 25, 2025, 4:04pm UTC](https://discourse.cmake.org/t/how-to-get-the-default-suffix-of-executables/11476 "2025-07-25T16:04:10Z")

</div>

After modifying CMAKE\_SHARED\_LIBRARY\_PREFIX in CMakeLists.txt, how can I retrieve the default suffix of executables?

---

## [Code generation for multiple targets](https://discourse.cmake.org/t/code-generation-for-multiple-targets/11461)

<div class="topic-metadata">

**Author:** [@semushin-s](https://discourse.cmake.org/u/semushin-s)\
**Replies:** 1\
**Last updated:** [July 25, 2025, 3:43pm UTC](https://discourse.cmake.org/t/code-generation-for-multiple-targets/11461 "2025-07-25T15:43:53Z")

</div>

I have several executable targets AppA, AppB … And several libs LibA, LibB, LibC… which one or several executables depend on. Normal way of doing code generation is attaching custom command dependency to each lib and i…

---

## [Report Caller location?](https://discourse.cmake.org/t/report-caller-location/11436)

<div class="topic-metadata">

**Author:** [@duaneellis\_inno](https://discourse.cmake.org/u/duaneellis_inno)\
**Replies:** 1\
**Last updated:** [July 25, 2025, 3:27pm UTC](https://discourse.cmake.org/t/report-caller-location/11436 "2025-07-25T15:27:58Z")

</div>

I am trying to refactor a number of things in our CMAKE code As a RESULT - I have a number of ‘assert-like’ functions for example, assert\_ENV\_VAR\_DEFINED( NAME OUTVAR ) This verifies that the NAMED env var exists …

---

## [CMake Error messages in a more clickable way.](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431)

<div class="topic-metadata">

**Author:** [@duaneellis\_inno](https://discourse.cmake.org/u/duaneellis_inno)\
**Replies:** 2\
**Last updated:** [July 25, 2025, 2:52pm UTC](https://discourse.cmake.org/t/cmake-error-messages-in-a-more-clickable-way/11431 "2025-07-25T14:52:46Z")

</div>

When running CMAKE - it will sometimes print a message like this: CMake Error at foo/board-bar/CMakeLists.txt:117: Question #1 - Is there a way to tell CMAKE to print the ABSOLUTE path to the file instead? Question #2 …

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

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