# Usage

**URL:** https://discourse.cmake.org/c/usage/12.md?page=4

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

**Page:** 5

---

## [Best practices for dependency management in a nested library / superproject setup (FetchContent vs. find\_package)](https://discourse.cmake.org/t/best-practices-for-dependency-management-in-a-nested-library-superproject-setup-fetchcontent-vs-find-package/15127)

<div class="topic-metadata">

**Author:** [@StormLord07](https://discourse.cmake.org/u/StormLord07)\
**Replies:** 7\
**Last updated:** [December 28, 2025, 7:58am UTC](https://discourse.cmake.org/t/best-practices-for-dependency-management-in-a-nested-library-superproject-setup-fetchcontent-vs-find-package/15127 "2025-12-28T07:58:11Z")

</div>

Hello, My team and I really like the versatility of FetchContent and we use it almost everywhere. We’ve built up a fair number of internal libraries to increase development speed, so things feel like Lego blocks now. Th…

---

## [Presets - combine env/cache variables from multiple presets](https://discourse.cmake.org/t/presets-combine-env-cache-variables-from-multiple-presets/15369)

<div class="topic-metadata">

**Author:** [@Andrej730](https://discourse.cmake.org/u/Andrej730)\
**Replies:** 1\
**Last updated:** [December 24, 2025, 10:42am UTC](https://discourse.cmake.org/t/presets-combine-env-cache-variables-from-multiple-presets/15369 "2025-12-24T10:42:59Z")

</div>

Is it possible to somehow combine the same env/cache variable from two presets into a single value? Ideally, the goal is to define CMAKE\_PREFIX\_PATH cache variable based on values from multiple presets. Or at least defin…

---

## [Generic way to enable cpp files multiprocessing for any project (MSBuild)](https://discourse.cmake.org/t/generic-way-to-enable-cpp-files-multiprocessing-for-any-project-msbuild/15422)

<div class="topic-metadata">

**Author:** [@Andrej730](https://discourse.cmake.org/u/Andrej730)\
**Replies:** 0\
**Last updated:** [December 24, 2025, 8:41am UTC](https://discourse.cmake.org/t/generic-way-to-enable-cpp-files-multiprocessing-for-any-project-msbuild/15422 "2025-12-24T08:41:43Z")

</div>

\-j flag in cmake --build enabled multiprocessing for different Visual Studio projects (e.g. different targets), but typically user needs multiprocessing for different .cpp files and projects, not just projects. Providin…

---

## [Could not find any instance of Visual Studio](https://discourse.cmake.org/t/could-not-find-any-instance-of-visual-studio/15377)

<div class="topic-metadata">

**Author:** [@JRR](https://discourse.cmake.org/u/JRR)\
**Replies:** 3\
**Last updated:** [December 23, 2025, 3:51pm UTC](https://discourse.cmake.org/t/could-not-find-any-instance-of-visual-studio/15377 "2025-12-23T15:51:00Z")

</div>

Hello, I am trying to use cmake 3.23.5 with Visual Studio 2026 to create a Visual Studio 2022 project. Why am I doing this? At work we use cmake 3.23.5 and VS2022. I want to investigate something at home, but Micro…

---

## [Visual Studio out of tree build tree and .git directory](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413)

<div class="topic-metadata">

**Author:** [@David\_Hunter](https://discourse.cmake.org/u/David_Hunter)\
**Replies:** 2\
**Last updated:** [December 23, 2025, 3:44pm UTC](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413 "2025-12-23T15:44:07Z")

</div>

I generate a Visual Studio project out of tree in some build directory from some source directory. The project uses Git so the source directory has a .git directory. If I open the resultant Visual Studio solution it doe…

---

## [How can I preserve paths if importing one CMakePresets.json into another?](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380)

<div class="topic-metadata">

**Author:** [@dograt](https://discourse.cmake.org/u/dograt)\
**Replies:** 6\
**Last updated:** [December 22, 2025, 8:01am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380 "2025-12-22T08:01:40Z")

</div>

Let’s say I have a build infrastructure repository, containing a cmake/common\_presets.json, and various toolchain files that are referenced in this file’s presets, e.g.: { "name": "toolchain-gcc", "hidden": true, …

---

## [Cross compilation with Renesas ccrx compiler](https://discourse.cmake.org/t/cross-compilation-with-renesas-ccrx-compiler/15326)

<div class="topic-metadata">

**Author:** [@gildas\_Allain](https://discourse.cmake.org/u/gildas_Allain)\
**Replies:** 2\
**Last updated:** [December 19, 2025, 10:59am UTC](https://discourse.cmake.org/t/cross-compilation-with-renesas-ccrx-compiler/15326 "2025-12-19T10:59:46Z")

</div>

Hi, I was pleased to learn about the support for the Renesas CCRX compiler since version 4.1 but I am still encountering difficulties setting it up. My crosstoolchain file defines the compiler path and other stuff ...…

---

## [Ubuntu: installing multiple CMake versions](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 3\
**Last updated:** [December 16, 2025, 6:14am UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402 "2025-12-16T06:14:29Z")

</div>

This is related to: Windows: how to have multiple CMake versions installed? In my case, I’d like to use update-alternatives to switch between versions. The default one was installed through sudo apt install cmake which…

---

## [Can CMake patch RPATH in existing binaries?](https://discourse.cmake.org/t/can-cmake-patch-rpath-in-existing-binaries/9424)

<div class="topic-metadata">

**Author:** [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Replies:** 3\
**Last updated:** [December 14, 2025, 7:17pm UTC](https://discourse.cmake.org/t/can-cmake-patch-rpath-in-existing-binaries/9424 "2025-12-14T19:17:46Z")

</div>

CMake can patch RPATH within install(TARGETS ...). Can we also do this manually like: set\_rpath("libsepp.so" "\\$ORIGIN") Reason: I want to patch libs that are IMPORTED. I cannot install them. PS: I have found internal…

---

## [Compile Tesseract-OCR for Android ARM64 use x86\_64-linux-gnu headers](https://discourse.cmake.org/t/compile-tesseract-ocr-for-android-arm64-use-x86-64-linux-gnu-headers/15373)

<div class="topic-metadata">

**Author:** [@pol2095](https://discourse.cmake.org/u/pol2095)\
**Replies:** 4\
**Last updated:** [December 14, 2025, 11:14am UTC](https://discourse.cmake.org/t/compile-tesseract-ocr-for-android-arm64-use-x86-64-linux-gnu-headers/15373 "2025-12-14T11:14:11Z")

</div>

Hello, When I configure a Tesseract-OCR project for Android arm64-v8a on Ubuntu, I use the following settings : set(CMAKE\_TOOLCHAIN\_FILE /home/user/SDKs/android\_ndk/android\_ndk\_clang/build/cmake/android.toolchain.cmake…

---

## [Looking for a command line packaging tutorial for Windows 10](https://discourse.cmake.org/t/looking-for-a-command-line-packaging-tutorial-for-windows-10/15353)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 10\
**Last updated:** [December 12, 2025, 4:44pm UTC](https://discourse.cmake.org/t/looking-for-a-command-line-packaging-tutorial-for-windows-10/15353 "2025-12-12T16:44:06Z")

</div>

All, Just looking for someone to point me to a step-by-step tutorial for a command line CMake build not using mingw, WSL, or any other non-native Windows emulators, to build and package a C/C++ library under Windows 10. …

---

## [Unexpected VS2022 build flag changes with CMake 4.1](https://discourse.cmake.org/t/unexpected-vs2022-build-flag-changes-with-cmake-4-1/15324)

<div class="topic-metadata">

**Author:** [@kwaegel](https://discourse.cmake.org/u/kwaegel)\
**Replies:** 6\
**Last updated:** [December 8, 2025, 4:02pm UTC](https://discourse.cmake.org/t/unexpected-vs2022-build-flag-changes-with-cmake-4-1/15324 "2025-12-08T16:02:55Z")

</div>

I recently tried upgrading CMake and got an unexpected build failure with Visual Studio 2022 suddenly returning LNK1189 (\>65k symbols) for a large private project. After a bunch of testing different versions, it looks li…

---

## [Distributing C++20 modules as source](https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246)

<div class="topic-metadata">

**Author:** [@anarthal](https://discourse.cmake.org/u/anarthal)\
**Replies:** 6\
**Last updated:** [December 8, 2025, 8:38am UTC](https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246 "2025-12-08T08:38:06Z")

</div>

Hi all, This is a follow-up of Advice on C++20 modules (Boost) - #13 by ben.boeckel. I’m writing a proof of concept with Boost, where every library becomes a module. Just to illustrate, this is would be the CMake code …

---

## [compile tesseract add\_library error on Windows](https://discourse.cmake.org/t/compile-tesseract-add-library-error-on-windows/15365)

<div class="topic-metadata">

**Author:** [@pol2095](https://discourse.cmake.org/u/pol2095)\
**Replies:** 1\
**Last updated:** [December 7, 2025, 4:53pm UTC](https://discourse.cmake.org/t/compile-tesseract-add-library-error-on-windows/15365 "2025-12-07T16:53:16Z")

</div>

Hello, When I compile Teseract on Windows, I have this sw message error in VisualStudio CMake : CMake Error at out/build/x64-Release/.sw/cmake/CMakeLists.txt:1706 (add\_library): add\_library cannot create ALIAS target…

---

## [Header-only libraries and C++20 modules](https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680)

<div class="topic-metadata">

**Author:** [@anarthal](https://discourse.cmake.org/u/anarthal)\
**Replies:** 13\
**Last updated:** [December 7, 2025, 3:06am UTC](https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680 "2025-12-07T03:06:07Z")

</div>

When installing a header-only library with a C++20 module interface, with something like: add\_library(mylib) target\_sources(mylib PUBLIC FILE\_SET CXX\_MODULES FILES mylib.cppm FILE\_SET HEADERS FILES m…

---

## [Indirect expansion of environment and cache variables](https://discourse.cmake.org/t/indirect-expansion-of-environment-and-cache-variables/15363)

<div class="topic-metadata">

**Author:** [@Andrej730](https://discourse.cmake.org/u/Andrej730)\
**Replies:** 2\
**Last updated:** [December 5, 2025, 11:04am UTC](https://discourse.cmake.org/t/indirect-expansion-of-environment-and-cache-variables/15363 "2025-12-05T11:04:03Z")

</div>

See example below. For usual vars it’s possible to store their names in variables and then retrieve them using ${${VAR}}. But is it possibile for env variables? Tried to store it as ENV{TEST\_ON} and retrieve it with ${…

---

## [Best practice for coexisting release/debug installations](https://discourse.cmake.org/t/best-practice-for-coexisting-release-debug-installations/15361)

<div class="topic-metadata">

**Author:** [@Andrej730](https://discourse.cmake.org/u/Andrej730)\
**Replies:** 2\
**Last updated:** [December 4, 2025, 11:24am UTC](https://discourse.cmake.org/t/best-practice-for-coexisting-release-debug-installations/15361 "2025-12-04T11:24:02Z")

</div>

What’s the best general practice for creating installation where Release and Debug binaries can coexist? Simplest way would be to have them in separate folders, but that requires changing path prefix/roots when you wan…

---

## [Bug?: Link options get lost when adding a generator expression in a post build step](https://discourse.cmake.org/t/bug-link-options-get-lost-when-adding-a-generator-expression-in-a-post-build-step/15350)

<div class="topic-metadata">

**Author:** [@itavero](https://discourse.cmake.org/u/itavero)\
**Replies:** 1\
**Last updated:** [December 4, 2025, 9:28am UTC](https://discourse.cmake.org/t/bug-link-options-get-lost-when-adding-a-generator-expression-in-a-post-build-step/15350 "2025-12-04T09:28:38Z")

</div>

Last week I ran into a weird issue, which I think is a bug in CMake (but the instructions for reporting bugs state to first validate that it is not expected behavior on the Discourse). We had a custom function that adds…

---

## [Compiler flags lost when cross-compiling](https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360)

<div class="topic-metadata">

**Author:** [@bobjohnson](https://discourse.cmake.org/u/bobjohnson)\
**Replies:** 1\
**Last updated:** [December 3, 2025, 9:48pm UTC](https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360 "2025-12-03T21:48:09Z")

</div>

Hello, I am trying to cross-compile Ceres-solver for an ARM system. I have created a toolchain file with settings based on a known, working configuration. When I try to cross-compile Ceres-solver using my toolchain:cma…

---

## [trouble compiling dlib within my own project](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 2\
**Last updated:** [November 27, 2025, 8:14am UTC](https://discourse.cmake.org/t/trouble-compiling-dlib-within-my-own-project/15347 "2025-11-27T08:14:19Z")

</div>

Hi, So far I used dlib by compiling and installing a standalone version which I imported through find\_package. But I’m needing now to compile it directly inside my project, in order to propagate some specific compilati…

---

## [Alternative entry points down in the directory hierarchy](https://discourse.cmake.org/t/alternative-entry-points-down-in-the-directory-hierarchy/15342)

<div class="topic-metadata">

**Author:** [@alexshpilkin](https://discourse.cmake.org/u/alexshpilkin)\
**Replies:** 0\
**Last updated:** [November 24, 2025, 6:32pm UTC](https://discourse.cmake.org/t/alternative-entry-points-down-in-the-directory-hierarchy/15342 "2025-11-24T18:32:21Z")

</div>

Suppose I have the following directory hierarchy: include/ \<common utility headers\> src/ aexe/ \<sources and private headers of aexe\> bexe/ \<sources and private headers of bexe\> clib/ …

---

## [CMake & CPack with multiple packages on a monorepo](https://discourse.cmake.org/t/cmake-cpack-with-multiple-packages-on-a-monorepo/15340)

<div class="topic-metadata">

**Author:** [@w124513](https://discourse.cmake.org/u/w124513)\
**Replies:** 0\
**Last updated:** [November 24, 2025, 11:09am UTC](https://discourse.cmake.org/t/cmake-cpack-with-multiple-packages-on-a-monorepo/15340 "2025-11-24T11:09:41Z")

</div>

Hello everyone, we are building our packages on a monorepo which contains a set of common components and some specific components used only for specific packages. To be more specific: assume we have three components A,…

---

## [FASTBuild -- drop in replacement for Ninja?](https://discourse.cmake.org/t/fastbuild-drop-in-replacement-for-ninja/15335)

<div class="topic-metadata">

**Author:** [@johan556](https://discourse.cmake.org/u/johan556)\
**Replies:** 6\
**Last updated:** [November 22, 2025, 9:29pm UTC](https://discourse.cmake.org/t/fastbuild-drop-in-replacement-for-ninja/15335 "2025-11-22T21:29:01Z")

</div>

I got curious to try the new generator FASTBuild supported by the latest release-candidate of CMake 4.2. I have a codebase of ~2M lines of code that have used CMake + Ninja on Linux for many years. When building with -G…

---

## [add-compile-options use for alternatives](https://discourse.cmake.org/t/add-compile-options-use-for-alternatives/15337)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 0\
**Last updated:** [November 21, 2025, 9:53pm UTC](https://discourse.cmake.org/t/add-compile-options-use-for-alternatives/15337 "2025-11-21T21:53:21Z")

</div>

add\_compile\_options(/Ob2) on windows will cause msvc to complain on every file that you’re overriding the string(APPEND CMAKE\_${lang}\_FLAGS\_RELWITHDEBINFO\_INIT "${\_MD}${\_Zi} /O2 /Ob1 /DNDEBUG") in the base cmake config. …

---

## [CMake Build Error: Could NOT find MPI\_CXX](https://discourse.cmake.org/t/cmake-build-error-could-not-find-mpi-cxx/14402)

<div class="topic-metadata">

**Author:** [@Eledmunds](https://discourse.cmake.org/u/Eledmunds)\
**Replies:** 1\
**Last updated:** [November 20, 2025, 10:21pm UTC](https://discourse.cmake.org/t/cmake-build-error-could-not-find-mpi-cxx/14402 "2025-11-20T22:21:32Z")

</div>

Hi there, I am trying to create a docker image with a GPU-enabled version of LAMMPS. In the Dockerfile, I am trying to use CMake to build LAMMPS but am facing an error where by CMake cannot find MPI\_CXX. The error spec…

---

## [need help with cmake code to use Lua](https://discourse.cmake.org/t/need-help-with-cmake-code-to-use-lua/15320)

<div class="topic-metadata">

**Author:** [@solomoncyj](https://discourse.cmake.org/u/solomoncyj)\
**Replies:** 1\
**Last updated:** [November 20, 2025, 3:58pm UTC](https://discourse.cmake.org/t/need-help-with-cmake-code-to-use-lua/15320 "2025-11-20T15:58:39Z")

</div>

code: if (CHATTERINO\_PLUGINS) find\_package(Sol2 REQUIRED) find\_package(Lua 5.4) if (NOT Lua\_FOUND) set(LUA\_INCLUDE\_DIRS "${CMAKE\_SOURCE\_DIR}/lib/lua/src") add\_subdirectory(lib/lua) else…

---

## [CMake Automatically Links Each New C File with Previous File - Have to Delete Cache for Every New File (CLion)](https://discourse.cmake.org/t/cmake-automatically-links-each-new-c-file-with-previous-file-have-to-delete-cache-for-every-new-file-clion/15293)

<div class="topic-metadata">

**Author:** [@Kunal](https://discourse.cmake.org/u/Kunal)\
**Replies:** 4\
**Last updated:** [November 20, 2025, 9:31am UTC](https://discourse.cmake.org/t/cmake-automatically-links-each-new-c-file-with-previous-file-have-to-delete-cache-for-every-new-file-clion/15293 "2025-11-20T09:31:56Z")

</div>

Note: I’m new to coding and CMake, so I might be missing something obvious. Please be patient with me! I’m working on a C programming practice project in CLion where I have multiple independent .c files (q1.c, q2.c, q3.…

---

## [\`CMAKE\_CXX\_FLAGS\_INIT\` vs env \`CXXFLAGS\` for appending flags](https://discourse.cmake.org/t/cmake-cxx-flags-init-vs-env-cxxflags-for-appending-flags/15332)

<div class="topic-metadata">

**Author:** [@Andrej730](https://discourse.cmake.org/u/Andrej730)\
**Replies:** 0\
**Last updated:** [November 20, 2025, 5:36am UTC](https://discourse.cmake.org/t/cmake-cxx-flags-init-vs-env-cxxflags-for-appending-flags/15332 "2025-11-20T05:36:18Z")

</div>

Any idea if it’s okay to use CMAKE\_CXX\_FLAGS\_INIT to provide extra compilation flags when running cmake from command line? It seems the recommended way to do it is to set CXXFLAGS environment variable, but I wanted to a…

---

## [CMake, Flang, and fPIC](https://discourse.cmake.org/t/cmake-flang-and-fpic/15316)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 7\
**Last updated:** [November 17, 2025, 6:44pm UTC](https://discourse.cmake.org/t/cmake-flang-and-fpic/15316 "2025-11-17T18:44:20Z")

</div>

To the gurus here: Is there anything “special” I need to do to enable fPIC/fPIE with Flang? I ask because this simple project: cmake\_minimum\_required(VERSION 3.24) project(test LANGUAGES Fortran) set(CMAKE\_POSITION\_IND…

---

## [Guideline for code coverage](https://discourse.cmake.org/t/guideline-for-code-coverage/167)

<div class="topic-metadata">

**Author:** [@Adem\_Budak](https://discourse.cmake.org/u/Adem_Budak)\
**Replies:** 3\
**Last updated:** [November 16, 2025, 10:11pm UTC](https://discourse.cmake.org/t/guideline-for-code-coverage/167 "2025-11-16T22:11:48Z")

</div>

Hello everyone, After jumping around the some CMake documentation, Github sample project and Stackoverflow, I think it’s best to ask here for correct usage of the CMake to get coverage report using GCov and Lcov. Any p…

[Previous page](https://discourse.cmake.org/c/usage/12.md?page=3)

[Next page](https://discourse.cmake.org/c/usage/12.md?page=5)
