# Code

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

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

**Page:** 62

---

## [Cannot find path to transitive library during linking (find\_package()/target\_link\_libraries())](https://discourse.cmake.org/t/cannot-find-path-to-transitive-library-during-linking-find-package-target-link-libraries/2921)

<div class="topic-metadata">

**Author:** [@JRR](https://discourse.cmake.org/u/JRR)\
**Replies:** 6\
**Last updated:** [March 10, 2021, 4:02pm UTC](https://discourse.cmake.org/t/cannot-find-path-to-transitive-library-during-linking-find-package-target-link-libraries/2921 "2021-03-10T16:02:44Z")

</div>

I am having trouble finding a grandchild library in a transitive link scenario that we have. Actually, I’m not even sure what the correct terminology for a lot of this is, so I may be overly detailed in the explanation. …

---

## [File dependencies not correct when depending on preprocesor macros](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925)

<div class="topic-metadata">

**Author:** [@liampower](https://discourse.cmake.org/u/liampower)\
**Replies:** 5\
**Last updated:** [March 9, 2021, 11:37am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925 "2021-03-09T11:37:31Z")

</div>

I am integrating a library that includes files based on C preprocessor macros. As an example: #if !defined(MBEDTLS\_CONFIG\_FILE) #include “mbedtls/config.h” #else #include MBEDTLS\_CONFIG\_FILE #endif In my CMAKE file…

---

## [ExternalProject\_Add error finding source directory](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922)

<div class="topic-metadata">

**Author:** [@kmilo9999](https://discourse.cmake.org/u/kmilo9999)\
**Replies:** 2\
**Last updated:** [March 9, 2021, 2:48am UTC](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922 "2021-03-09T02:48:01Z")

</div>

Hello, I am writing a C.I script for my c++ project, and I would like to use ExternalProject\_Add command to autodownload and build the dependencies. One of those is glew (graphics library) which I get from the url “h…

---

## [execute\_process ignoring options](https://discourse.cmake.org/t/execute-process-ignoring-options/2918)

<div class="topic-metadata">

**Author:** [@modelmanjohn](https://discourse.cmake.org/u/modelmanjohn)\
**Replies:** 3\
**Last updated:** [March 8, 2021, 4:17pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918 "2021-03-08T16:17:51Z")

</div>

Hello, I’m trying to get an execute\_process command working, and so far, it seems like its ignoring options of the command itself. The command I’m trying to run is: python3 -B file.py The -B option is the problem: it …

---

## [Choose between shared/static library after find\_package()](https://discourse.cmake.org/t/choose-between-shared-static-library-after-find-package/2910)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 2\
**Last updated:** [March 8, 2021, 12:55pm UTC](https://discourse.cmake.org/t/choose-between-shared-static-library-after-find-package/2910 "2021-03-08T12:55:07Z")

</div>

Hi, I’m writing project wich depends on HDF5. I’m looking for HDF5 via find\_package(HDF5 REQUIRED CONFIG). Then I need to chose between static or dynamic linking. Usually HDF5 provides hdf5-shared and hdf5-static targe…

---

## [doxygen\_add\_docs install output directory](https://discourse.cmake.org/t/doxygen-add-docs-install-output-directory/2904)

<div class="topic-metadata">

**Author:** [@Wirtos](https://discourse.cmake.org/u/Wirtos)\
**Replies:** 2\
**Last updated:** [March 7, 2021, 10:33am UTC](https://discourse.cmake.org/t/doxygen-add-docs-install-output-directory/2904 "2021-03-07T10:33:33Z")

</div>

I’m trying to install generated doxygen directory like this: set(DOXYGEN\_OUTPUT\_DIRECTORY "${CMAKE\_CURRENT\_BINARY\_DIR}/doxy") doxygen\_add\_docs( mylib\_docs include COMMENT "Generate docs" …

---

## [Redirecting input in ExternalProject\_Add PATCH\_COMMAND](https://discourse.cmake.org/t/redirecting-input-in-externalproject-add-patch-command/2779)

<div class="topic-metadata">

**Author:** [@mwilbur](https://discourse.cmake.org/u/mwilbur)\
**Replies:** 10\
**Last updated:** [March 6, 2021, 10:02pm UTC](https://discourse.cmake.org/t/redirecting-input-in-externalproject-add-patch-command/2779 "2021-03-06T22:02:08Z")

</div>

In the latest code on master, if the PATCH\_COMMAND includes a redirection ExternalProject\_Add( PATCH\_COMMAND patch -p1 \< some\_file ) the \< gets interpreted as an input to the command. Poking around, it looks like the …

---

## [Run a CMake script before INSTALL target](https://discourse.cmake.org/t/run-a-cmake-script-before-install-target/2890)

<div class="topic-metadata">

**Author:** [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Replies:** 4\
**Last updated:** [March 5, 2021, 2:31pm UTC](https://discourse.cmake.org/t/run-a-cmake-script-before-install-target/2890 "2021-03-05T14:31:43Z")

</div>

I would like to run a CMake script before the INSTALL target (optionally just before building the code). I have tried using the install(\[SCRIPT\] \<file\> \[...\]) functionality, but that runs during install, which is too la…

---

## [ARCHIVE\_EXTRACT problem](https://discourse.cmake.org/t/archive-extract-problem/2873)

<div class="topic-metadata">

**Author:** [@fizzyade](https://discourse.cmake.org/u/fizzyade)\
**Replies:** 5\
**Last updated:** [March 3, 2021, 8:36am UTC](https://discourse.cmake.org/t/archive-extract-problem/2873 "2021-03-03T08:36:22Z")

</div>

I have a library I need to integrate into my project, I can use file(DOWNLOAD …) to grab the tar ball and I can use file(ARCHIVE\_EXTRACT …) to extract the sources, the problem I have is that the tarball has a root folder…

---

## [CMake, setting a macro from a console program \[SOLVED\]](https://discourse.cmake.org/t/cmake-setting-a-macro-from-a-console-program-solved/2869)

<div class="topic-metadata">

**Author:** [@Jos](https://discourse.cmake.org/u/Jos)\
**Replies:** 15\
**Last updated:** [March 2, 2021, 4:49pm UTC](https://discourse.cmake.org/t/cmake-setting-a-macro-from-a-console-program-solved/2869 "2021-03-02T16:49:53Z")

</div>

Hi, I’m Making the portablity of a code to CMake. The code needs that CMake defines Macro with last short head from git. If I define the value maually, target\_compile\_definitions(LibDEFINES PRIVATE GITVER=3686e892 ) T…

---

## [Can a parent detect what a function has changed with set(... PARENT\_SCOPE)?](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864)

<div class="topic-metadata">

**Author:** [@axel](https://discourse.cmake.org/u/axel)\
**Replies:** 3\
**Last updated:** [March 2, 2021, 4:43pm UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864 "2021-03-02T16:43:45Z")

</div>

Can a parent detect what a function has changed with set(... PARENT\_SCOPE)? My use case is that I have multiple layer of function. Previously, func1() simply called func2() but now func1() calls func1\_a() which calls fu…

---

## [target\_include\_directories behavior with empty value](https://discourse.cmake.org/t/target-include-directories-behavior-with-empty-value/2867)

<div class="topic-metadata">

**Author:** [@shr-project](https://discourse.cmake.org/u/shr-project)\
**Replies:** 3\
**Last updated:** [March 2, 2021, 3:27pm UTC](https://discourse.cmake.org/t/target-include-directories-behavior-with-empty-value/2867 "2021-03-02T15:27:19Z")

</div>

I’ve already left a comment in commit which was ensuring clean INTERFACE\_INCLUDE\_DIRECTORIES: https://gitlab.kitware.com/cmake/cmake/-/commit/af81a3c31b206633742eb13d41c54a9bc807ffea That it doesn’t seem to work right …

---

## [Technical help required](https://discourse.cmake.org/t/technical-help-required/2865)

<div class="topic-metadata">

**Author:** [@SURAJ\_PATEL](https://discourse.cmake.org/u/SURAJ_PATEL)\
**Replies:** 5\
**Last updated:** [March 2, 2021, 10:11am UTC](https://discourse.cmake.org/t/technical-help-required/2865 "2021-03-02T10:11:24Z")

</div>

Hi Team, i am working on a project and created a build system using cmake. I want to use optimization on the selected code c files. Could you please let me know how to achieve that . Please send an example how to achiev…

---

## [Remove installed libs from windows path](https://discourse.cmake.org/t/remove-installed-libs-from-windows-path/2863)

<div class="topic-metadata">

**Author:** [@kmilo9999](https://discourse.cmake.org/u/kmilo9999)\
**Replies:** 1\
**Last updated:** [March 2, 2021, 12:55am UTC](https://discourse.cmake.org/t/remove-installed-libs-from-windows-path/2863 "2021-03-02T00:55:42Z")

</div>

A while ago I built and installed zlib from source code using cmake. I assume the CMAKE\_INSTALL\_PREFIX variable got set by default to: C:\\Program Files (x86)\\zlib Since then, all the projects that require zlib automa…

---

## [Using a header only library with FetchContents while build a static lib](https://discourse.cmake.org/t/using-a-header-only-library-with-fetchcontents-while-build-a-static-lib/2711)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 7\
**Last updated:** [March 1, 2021, 9:47pm UTC](https://discourse.cmake.org/t/using-a-header-only-library-with-fetchcontents-while-build-a-static-lib/2711 "2021-03-01T21:47:02Z")

</div>

Why must I install an header only lib which I only need at build time for my own library? Claus-iMac:example clausklein$ cmake -B build -S . -G Ninja -- The CXX compiler identification is AppleClang 12.0.0.12000032 -- D…

---

## [static and dynamic libraries, single compile](https://discourse.cmake.org/t/static-and-dynamic-libraries-single-compile/2855)

<div class="topic-metadata">

**Author:** [@Jay\_K](https://discourse.cmake.org/u/Jay_K)\
**Replies:** 13\
**Last updated:** [March 1, 2021, 8:25pm UTC](https://discourse.cmake.org/t/static-and-dynamic-libraries-single-compile/2855 "2021-03-01T20:25:18Z")

</div>

I am very new to cmake. I am not new to build systems. I have maintained signficant ones. I have a very custom build system. Very declarative, and embeds a little custom scripting language as an escape hatch. Nice b…

---

## [\`ctest --preset\` and Ctest Dashboard client](https://discourse.cmake.org/t/ctest-preset-and-ctest-dashboard-client/2858)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 0\
**Last updated:** [February 28, 2021, 4:42pm UTC](https://discourse.cmake.org/t/ctest-preset-and-ctest-dashboard-client/2858 "2021-02-28T16:42:59Z")

</div>

It looks like ctest --preset doesn’t take effect (silently ignored) with ctest -S Dashboard client. Is that the intended behavior?

---

## [Trying to write FindRecastNavigation.cmake to cover multiple libraries](https://discourse.cmake.org/t/trying-to-write-findrecastnavigation-cmake-to-cover-multiple-libraries/2841)

<div class="topic-metadata">

**Author:** [@psi29a](https://discourse.cmake.org/u/psi29a)\
**Replies:** 3\
**Last updated:** [February 25, 2021, 3:32pm UTC](https://discourse.cmake.org/t/trying-to-write-findrecastnavigation-cmake-to-cover-multiple-libraries/2841 "2021-02-25T15:32:27Z")

</div>

Hello! I’m struggling a bit and I’m hoping someone can help guide/educate me on how best to do this… I’m trying to figure how to get multiple libraries to be detected and exposed. I have it finding and exposing libRecas…

---

## [DEPRECATION "The CMAKE\_FORCE\_C\_COMPILER " clarification](https://discourse.cmake.org/t/deprecation-the-cmake-force-c-compiler-clarification/2814)

<div class="topic-metadata">

**Author:** [@udayakarthik\_g](https://discourse.cmake.org/u/udayakarthik_g)\
**Replies:** 3\
**Last updated:** [February 25, 2021, 2:46pm UTC](https://discourse.cmake.org/t/deprecation-the-cmake-force-c-compiler-clarification/2814 "2021-02-25T14:46:42Z")

</div>

Hello Sir/Madam, We are using Cmake compiler version 3.12.0. I am using the below cmake script for compilation. While I am compiling the code I got a warning like " message(DEPRECATION “The CMAKE\_FORCE\_C\_COMPI…

---

## [Problem with CMAKE\_AUTOUIC](https://discourse.cmake.org/t/problem-with-cmake-autouic/2780)

<div class="topic-metadata">

**Author:** [@amaclean](https://discourse.cmake.org/u/amaclean)\
**Replies:** 9\
**Last updated:** [February 23, 2021, 10:17pm UTC](https://discourse.cmake.org/t/problem-with-cmake-autouic/2780 "2021-02-23T22:17:27Z")

</div>

I am looking at rewriting some CMake scripts for Qt so Qt5 and Qt6 can be used, specifically those in the VTK Examples. I have run into a problem with Visual Studio and CMAKE\_AUTOUIC. If CMAKE\_AUTOUIC is set to ON, Visu…

---

## [One source to create multiple objects](https://discourse.cmake.org/t/one-source-to-create-multiple-objects/2819)

<div class="topic-metadata">

**Author:** [@odevel](https://discourse.cmake.org/u/odevel)\
**Replies:** 1\
**Last updated:** [February 23, 2021, 7:02pm UTC](https://discourse.cmake.org/t/one-source-to-create-multiple-objects/2819 "2021-02-23T19:02:58Z")

</div>

Hello, before I start with my question I’ll explain the background. In my C++ project I’ve one source file which is very heavy to compile (boost.spirit.x3) for a linker library of a project. Fortunately I can setup diff…

---

## [set target property project-wide](https://discourse.cmake.org/t/set-target-property-project-wide/2798)

<div class="topic-metadata">

**Author:** [@jwm](https://discourse.cmake.org/u/jwm)\
**Replies:** 4\
**Last updated:** [February 22, 2021, 6:50pm UTC](https://discourse.cmake.org/t/set-target-property-project-wide/2798 "2021-02-22T18:50:01Z")

</div>

I lifted my C++ backtrace utility from another project. There was even a note in the source code about requiring -rdynamic to use. Originally, we were using CMake 3.3. When I upgraded to 3.17, I was silently bitten by CM…

---

## [Anyway to automatically add include dir when using target\_link\_libraries?](https://discourse.cmake.org/t/anyway-to-automatically-add-include-dir-when-using-target-link-libraries/2811)

<div class="topic-metadata">

**Author:** [@psionic12](https://discourse.cmake.org/u/psionic12)\
**Replies:** 3\
**Last updated:** [February 22, 2021, 9:05am UTC](https://discourse.cmake.org/t/anyway-to-automatically-add-include-dir-when-using-target-link-libraries/2811 "2021-02-22T09:05:32Z")

</div>

Hi, when I wrote libraries, I was wondering is there anyway I can expose my headers automatically when someone using target\_link\_libraries to link my lib? Usually, when we use some libraries, even if most libraries offer…

---

## [Selecting lto\_70 CUDA architecture with Cmake](https://discourse.cmake.org/t/selecting-lto-70-cuda-architecture-with-cmake/2807)

<div class="topic-metadata">

**Author:** [@gridley](https://discourse.cmake.org/u/gridley)\
**Replies:** 1\
**Last updated:** [February 21, 2021, 5:00pm UTC](https://discourse.cmake.org/t/selecting-lto-70-cuda-architecture-with-cmake/2807 "2021-02-21T17:00:39Z")

</div>

The CUDA manual says that link-time device code optimization can be done on CUDA code now if we use a special architecture, e.g. 70\_lto. Previously I had been using compute\_70 for all CUDA targets in my project by the…

---

## [Help with cmake maximum version](https://discourse.cmake.org/t/help-with-cmake-maximum-version/2797)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 1\
**Last updated:** [February 19, 2021, 6:59am UTC](https://discourse.cmake.org/t/help-with-cmake-maximum-version/2797 "2021-02-19T06:59:53Z")

</div>

This is a dumb quick question I had with cmake\_minimum\_required. I was reading the help page and saw that it could specify a maximum version. I made a silly CMakeLists.txt: cmake\_minimum\_required(VERSION 3.7...3.15) pro…

---

## [CPack Debian dpkg-shlibdeps with components](https://discourse.cmake.org/t/cpack-debian-dpkg-shlibdeps-with-components/2781)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 9\
**Last updated:** [February 18, 2021, 9:28am UTC](https://discourse.cmake.org/t/cpack-debian-dpkg-shlibdeps-with-components/2781 "2021-02-18T09:28:54Z")

</div>

I’m trying to use CPACK\_DEBIAN\_PACKAGE\_SHLIBDEPS but I’m getting errors despite setting up my RPATH correctly. I think the issue is that I’m creating a componentized package and one of my executables depends on a librar…

---

## [Invalid or corrupt file in CMAKE build](https://discourse.cmake.org/t/invalid-or-corrupt-file-in-cmake-build/2795)

<div class="topic-metadata">

**Author:** [@Santosh](https://discourse.cmake.org/u/Santosh)\
**Replies:** 1\
**Last updated:** [February 18, 2021, 7:16am UTC](https://discourse.cmake.org/t/invalid-or-corrupt-file-in-cmake-build/2795 "2021-02-18T07:16:26Z")

</div>

Unable to include a library file in CMAKE build. Facing below issue. Code : cmake\_minimum\_required(VERSION 3.19) add\_library( cmnbase2 SHARED IMPORTED GLOBAL ) set\_property( TARGET cmnbase2 PROPERTY IMPORTED…

---

## [Problem with target\_precompile\_headers](https://discourse.cmake.org/t/problem-with-target-precompile-headers/2724)

<div class="topic-metadata">

**Author:** [@WOFST](https://discourse.cmake.org/u/WOFST)\
**Replies:** 8\
**Last updated:** [February 17, 2021, 8:19am UTC](https://discourse.cmake.org/t/problem-with-target-precompile-headers/2724 "2021-02-17T08:19:40Z")

</div>

I use the target\_precompile\_headers( REUSE\_FROM \<other\_target\>) for a Qt project,but happend a LINK200 failed,and my environment is： visual studio 2017 Qt 5.14.0(5.6.0 or 5.9.4 is also a failure) CMAKE 3.18.5(3.19 or 3…

---

## [How to use libraries conveniently on Windows](https://discourse.cmake.org/t/how-to-use-libraries-conveniently-on-windows/1469)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 15\
**Last updated:** [February 17, 2021, 12:07am UTC](https://discourse.cmake.org/t/how-to-use-libraries-conveniently-on-windows/1469 "2021-02-17T00:07:14Z")

</div>

Hi everyone, I’m currently trying to include a lib (soci) in my cmake projects. After days of hacking around, I got it working. But there are still a few problems, which I solve with ways I don’t like :wink: Maybe some…

---

## [string(JSON ... SET ...) example](https://discourse.cmake.org/t/string-json-set-example/2746)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 0\
**Last updated:** [February 12, 2021, 12:24am UTC](https://discourse.cmake.org/t/string-json-set-example/2746 "2021-02-12T00:24:27Z")

</div>

I’ve found the string(JSON ... GET) to be a great way to separate project data (urls, md5s, git tags) from code by reading in a json file with those parameters. Especially useful for projects with lots of FetchContent/Ex…

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

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