# Code

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

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

**Page:** 46

---

## [how to automatically collect the created target?](https://discourse.cmake.org/t/how-to-automatically-collect-the-created-target/5868)

<div class="topic-metadata">

**Author:** [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)\
**Replies:** 2\
**Last updated:** [June 18, 2022, 11:21am UTC](https://discourse.cmake.org/t/how-to-automatically-collect-the-created-target/5868 "2022-06-18T11:21:53Z")

</div>

I want to generate myself package using cmake, and a essential code is: install(TARGETS packageA packgeB ... RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) The packageA packageB .…

---

## [CGAL and its key dependency using ExternalProject\_Add](https://discourse.cmake.org/t/cgal-and-its-key-dependency-using-externalproject-add/5884)

<div class="topic-metadata">

**Author:** [@petrasvestartas](https://discourse.cmake.org/u/petrasvestartas)\
**Replies:** 2\
**Last updated:** [June 17, 2022, 2:29pm UTC](https://discourse.cmake.org/t/cgal-and-its-key-dependency-using-externalproject-add/5884 "2022-06-17T14:29:57Z")

</div>

The CMake command below downloads CGAL from github: Release CGAL-5.4.1 · CGAL/cgal · GitHub It downloads the source files but it does not download GMP and MPFR libraries, for Windows 64bits as is seen in release structu…

---

## [cmake generated package cause bug while the source code is correct](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876)

<div class="topic-metadata">

**Author:** [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)\
**Replies:** 2\
**Last updated:** [June 17, 2022, 1:07am UTC](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876 "2022-06-17T01:07:32Z")

</div>

I have implement some code, and want to generate myself package. My CMakeLists.txt looks like: ... install(TARGETS pA pB ... EXPORT SustaoBasic RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION l…

---

## [We would like to learn how to generate documentation for targets](https://discourse.cmake.org/t/we-would-like-to-learn-how-to-generate-documentation-for-targets/5880)

<div class="topic-metadata">

**Author:** [@kz7000](https://discourse.cmake.org/u/kz7000)\
**Replies:** 3\
**Last updated:** [June 16, 2022, 10:06pm UTC](https://discourse.cmake.org/t/we-would-like-to-learn-how-to-generate-documentation-for-targets/5880 "2022-06-16T22:06:14Z")

</div>

Hello, We would like to document selected targets in our cmake file. For example, the envisioned usage might look something like this: mkdir build cd build cmake .. make doc This will then print out nicely formatted …

---

## [how to generate ITK\_INCLUDE\_DIRS when packaging myself module?](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865)

<div class="topic-metadata">

**Author:** [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)\
**Replies:** 6\
**Last updated:** [June 16, 2022, 7:46pm UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865 "2022-06-16T19:46:04Z")

</div>

I am packaging myself module by cmake. My CMakeLists.txt is: install( TARGETS pA pB EXPORT SustaoBasic RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) install(DIRECTORY package/ DESTINAT…

---

## [Is it possible to customize the include path of a file?](https://discourse.cmake.org/t/is-it-possible-to-customize-the-include-path-of-a-file/5841)

<div class="topic-metadata">

**Author:** [@dwarwick](https://discourse.cmake.org/u/dwarwick)\
**Replies:** 5\
**Last updated:** [June 16, 2022, 7:45pm UTC](https://discourse.cmake.org/t/is-it-possible-to-customize-the-include-path-of-a-file/5841 "2022-06-16T19:45:05Z")

</div>

Assume I have a directory structure like Libs/ Foo/ File.h File.cpp CMakeLists.txt Bar/ File2.h File2.cpp CMakeLists.txt I want the include paths for files to be …

---

## [How to add different target types for different configuration\_types for Visual Studio generator?](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860)

<div class="topic-metadata">

**Author:** [@Revbrte](https://discourse.cmake.org/u/Revbrte)\
**Replies:** 4\
**Last updated:** [June 16, 2022, 3:22pm UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860 "2022-06-16T15:22:33Z")

</div>

How to add different target\_types for configuration\_types, eq:Release - Executable AA\_Release(custom\_config) - Static\_library How to configure so that when we open the solution file in visual studio, in properties we …

---

## [Control build parallelism within ExternalProject\_Add](https://discourse.cmake.org/t/control-build-parallelism-within-externalproject-add/5864)

<div class="topic-metadata">

**Author:** [@bthomasz](https://discourse.cmake.org/u/bthomasz)\
**Replies:** 3\
**Last updated:** [June 14, 2022, 11:07pm UTC](https://discourse.cmake.org/t/control-build-parallelism-within-externalproject-add/5864 "2022-06-14T23:07:40Z")

</div>

Hi, I am working on a project to build&package 3rd party dependencies for an application, by calling ExternalProject\_Add exclusively. This runs in linux vm-s using both Ninja and Unix Makefile generators. The problem: …

---

## [IN\_LIST generator-expression does not work as expected](https://discourse.cmake.org/t/in-list-generator-expression-does-not-work-as-expected/5853)

<div class="topic-metadata">

**Author:** [@kevin-peng-hao](https://discourse.cmake.org/u/kevin-peng-hao)\
**Replies:** 7\
**Last updated:** [June 14, 2022, 2:34am UTC](https://discourse.cmake.org/t/in-list-generator-expression-does-not-work-as-expected/5853 "2022-06-14T02:34:34Z")

</div>

Hi, I have a piece of code like this: set(SOME\_LIST member\_a meber\_b) set(TEST\_STRING member\_a) if (${TEST\_STRING} IN\_LIST SOME\_LIST) target\_sources(a\_library PRIVATE some\_code\_a.c ) else() …

---

## [unkown CMake command idf\_blahblah](https://discourse.cmake.org/t/unkown-cmake-command-idf-blahblah/5835)

<div class="topic-metadata">

**Author:** [@xXWesleyXx\_eckz](https://discourse.cmake.org/u/xXWesleyXx_eckz)\
**Replies:** 6\
**Last updated:** [June 13, 2022, 8:03am UTC](https://discourse.cmake.org/t/unkown-cmake-command-idf-blahblah/5835 "2022-06-13T08:03:08Z")

</div>

Hello Everyone. This is my first post on this forum so please be patient if it’s not formulated the way ya’ll are used to, please tell me if you’re missing info and I will try to deliver. First off I if anyone has a si…

---

## [Use CMake to do work other than building application](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824)

<div class="topic-metadata">

**Author:** [@ygao88](https://discourse.cmake.org/u/ygao88)\
**Replies:** 3\
**Last updated:** [June 9, 2022, 3:37pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824 "2022-06-09T15:37:17Z")

</div>

Hi, Is it proper/possible to use CMake to do work other than building code? For example, we need to generate sw package which includes pulling files from SVN, encrypt files and make tar balls. Regards, Winston

---

## [i try to type findw3m.cmake for the last snort](https://discourse.cmake.org/t/i-try-to-type-findw3m-cmake-for-the-last-snort/5794)

<div class="topic-metadata">

**Author:** [@Azaretdodo](https://discourse.cmake.org/u/Azaretdodo)\
**Replies:** 5\
**Last updated:** [June 8, 2022, 1:56pm UTC](https://discourse.cmake.org/t/i-try-to-type-findw3m-cmake-for-the-last-snort/5794 "2022-06-08T13:56:29Z")

</div>

hello, the code i have type here below : # - Find w3m # this module looks for w3m # # w3m: # \*\_FOUND - if false, don't attempt to use above command # to build: # html (single or chunked) - w3m needed # text - w3m need…

---

## [CPack wix and required components group](https://discourse.cmake.org/t/cpack-wix-and-required-components-group/5822)

<div class="topic-metadata">

**Author:** [@dr\_ppetrov](https://discourse.cmake.org/u/dr_ppetrov)\
**Replies:** 0\
**Last updated:** [June 8, 2022, 11:02am UTC](https://discourse.cmake.org/t/cpack-wix-and-required-components-group/5822 "2022-06-08T11:02:09Z")

</div>

I am using cmake/cpack with Wix to generate .msi installers for windows. Recently I introduced optional components are part of the installer. However, I faced quite a limitation, while the call to cpack\_add\_component al…

---

## [Omit targets that are not supported by compiler](https://discourse.cmake.org/t/omit-targets-that-are-not-supported-by-compiler/5809)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 2\
**Last updated:** [June 7, 2022, 7:22am UTC](https://discourse.cmake.org/t/omit-targets-that-are-not-supported-by-compiler/5809 "2022-06-07T07:22:49Z")

</div>

We have projects that build on a variety of platforms. I’ve added some extension code that requires some C++11 features not supported by one of the platforms, but I don’t mind if the code doesn’t build on that platform. …

---

## [Migrating a configurable autotools-based build to CMake](https://discourse.cmake.org/t/migrating-a-configurable-autotools-based-build-to-cmake/5784)

<div class="topic-metadata">

**Author:** [@vkn](https://discourse.cmake.org/u/vkn)\
**Replies:** 4\
**Last updated:** [June 7, 2022, 12:01am UTC](https://discourse.cmake.org/t/migrating-a-configurable-autotools-based-build-to-cmake/5784 "2022-06-07T00:01:06Z")

</div>

I originally posted this on StackOverflow, I figured it would be helpful to post it here, too. I am migrating a large legacy codebase from autotools to CMake, and we have some behaviour that we’d like to preserve. Howev…

---

## [Escaping $ in add\_custom\_command](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807)

<div class="topic-metadata">

**Author:** [@Mario\_Not64](https://discourse.cmake.org/u/Mario_Not64)\
**Replies:** 2\
**Last updated:** [June 6, 2022, 7:19pm UTC](https://discourse.cmake.org/t/escaping-in-add-custom-command/5807 "2022-06-06T19:19:23Z")

</div>

Hello, This is a simplied case: add\_custom\_comand( COMMAND ls $(echo -l) VERBATIM ) In the real case VERBATIM is required because the COMMAND has lots of other arguments that requires it. Because of VERBATIM, the $…

---

## [forcing FIND\_LIBRARY to find static libs on Unix (linux and macOS)](https://discourse.cmake.org/t/forcing-find-library-to-find-static-libs-on-unix-linux-and-macos/5801)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 1\
**Last updated:** [June 6, 2022, 12:04am UTC](https://discourse.cmake.org/t/forcing-find-library-to-find-static-libs-on-unix-linux-and-macos/5801 "2022-06-06T00:04:33Z")

</div>

I am wondering if there is a cmake variable to force FIND\_LIBRARY to use static libraries instead of shared ones. I know this might not be possible on Windows with MSVC where both the static libraries and the DLL stubs …

---

## [Set cmake env variable](https://discourse.cmake.org/t/set-cmake-env-variable/5771)

<div class="topic-metadata">

**Author:** [@whatheway](https://discourse.cmake.org/u/whatheway)\
**Replies:** 17\
**Last updated:** [June 5, 2022, 4:52pm UTC](https://discourse.cmake.org/t/set-cmake-env-variable/5771 "2022-06-05T16:52:53Z")

</div>

I have a stackoverflow topic that summarizes everything I think I need to set the env variable but it isn’t working with any way I try. I’ve tried: $ENV={JASPER\_LIBRARIES} $ENV={JASPER\_INCLUDE\_DIR} $ENV={JPEG\_INCLUD…

---

## [UPDATED w/Minimal Example - Having trouble setting flags for custom build type](https://discourse.cmake.org/t/updated-w-minimal-example-having-trouble-setting-flags-for-custom-build-type/5782)

<div class="topic-metadata">

**Author:** [@Chrinkus](https://discourse.cmake.org/u/Chrinkus)\
**Replies:** 2\
**Last updated:** [June 4, 2022, 4:27pm UTC](https://discourse.cmake.org/t/updated-w-minimal-example-having-trouble-setting-flags-for-custom-build-type/5782 "2022-06-04T16:27:30Z")

</div>

Minimum example: I’ve whittled the problem down to the following minimal example: CMakeLists.txt cmake\_minimum\_required(VERSION 3.18) …

---

## [Best practice(s) for "isolating" dependencies pulled with FetchContent](https://discourse.cmake.org/t/best-practice-s-for-isolating-dependencies-pulled-with-fetchcontent/5773)

<div class="topic-metadata">

**Author:** [@oblivioncth](https://discourse.cmake.org/u/oblivioncth)\
**Replies:** 8\
**Last updated:** [June 3, 2022, 6:05pm UTC](https://discourse.cmake.org/t/best-practice-s-for-isolating-dependencies-pulled-with-fetchcontent/5773 "2022-06-03T18:05:55Z")

</div>

This in-part has been discussed before, though in a very scattered manner, so I wanted to seek clarification of what I’ve come to find here, all in one place. In this situation there is a lib, and several applications t…

---

## [GoogleTest crash when using CMake/XCode/arm64](https://discourse.cmake.org/t/googletest-crash-when-using-cmake-xcode-arm64/5766)

<div class="topic-metadata">

**Author:** [@fry](https://discourse.cmake.org/u/fry)\
**Replies:** 11\
**Last updated:** [June 3, 2022, 2:15pm UTC](https://discourse.cmake.org/t/googletest-crash-when-using-cmake-xcode-arm64/5766 "2022-06-03T14:15:39Z")

</div>

This is a really weird problem and I am not even sure it is a CMake issue… I was able to reproduce the issue with the simplest project possible and it’s 100% reproducible. The project contains 1 file with 1 GoogleTest: #…

---

## [Fetching from github with depth setting](https://discourse.cmake.org/t/fetching-from-github-with-depth-setting/5781)

<div class="topic-metadata">

**Author:** [@josesimoes](https://discourse.cmake.org/u/josesimoes)\
**Replies:** 7\
**Last updated:** [June 3, 2022, 6:48am UTC](https://discourse.cmake.org/t/fetching-from-github-with-depth-setting/5781 "2022-06-03T06:48:19Z")

</div>

When calling FetchContent\_Declare to github, is there a way to tell CMake to do a shallow clone (using depth option) or specify the depth of what to fetch from github? Sometimes there are huge repos with dependencies of…

---

## [Create and activate Python conda environment with CMake](https://discourse.cmake.org/t/create-and-activate-python-conda-environment-with-cmake/5777)

<div class="topic-metadata">

**Author:** [@wigging](https://discourse.cmake.org/u/wigging)\
**Replies:** 4\
**Last updated:** [June 2, 2022, 12:44am UTC](https://discourse.cmake.org/t/create-and-activate-python-conda-environment-with-cmake/5777 "2022-06-02T00:44:37Z")

</div>

I have the following in a CMakeLists.txt file. The goal is to use cmake to check if a Python conda environment named myenv is already installed and activate that environment. If the environment does not exist, then creat…

---

## [Compile error: undefined reference to class constructor even though it is included](https://discourse.cmake.org/t/compile-error-undefined-reference-to-class-constructor-even-though-it-is-included/5761)

<div class="topic-metadata">

**Author:** [@Coziyu](https://discourse.cmake.org/u/Coziyu)\
**Replies:** 2\
**Last updated:** [May 31, 2022, 2:21am UTC](https://discourse.cmake.org/t/compile-error-undefined-reference-to-class-constructor-even-though-it-is-included/5761 "2022-05-31T02:21:18Z")

</div>

Hey there! I am a beginner learning how to use CMake in my VSCode C++ projects and I’m having some issues getting my code to compile properly. Intellisense doesn’t give me any errors. When using CMake to build my proje…

---

## [Ask FetchContent\_Declare to dowload to ${project\_SOURCE\_DIR}/\<subdir\>](https://discourse.cmake.org/t/ask-fetchcontent-declare-to-dowload-to-project-source-dir-subdir/5743)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 1\
**Last updated:** [May 27, 2022, 11:22pm UTC](https://discourse.cmake.org/t/ask-fetchcontent-declare-to-dowload-to-project-source-dir-subdir/5743 "2022-05-27T23:22:20Z")

</div>

I’m using FetchContent to get CryptoPP into my project. The point is that ${cryptopp\_SOURCE\_DIR} already contains .h and .cpp files. I would like to tell FetchContent to download the package to a ${cryptopp\_SOURCE\_DIR}…

---

## [Pitfalls of the include\_directories function](https://discourse.cmake.org/t/pitfalls-of-the-include-directories-function/5734)

<div class="topic-metadata">

**Author:** [@MrSplat](https://discourse.cmake.org/u/MrSplat)\
**Replies:** 1\
**Last updated:** [May 26, 2022, 1:36pm UTC](https://discourse.cmake.org/t/pitfalls-of-the-include-directories-function/5734 "2022-05-26T13:36:03Z")

</div>

Hi guys, I am currently working as part of a team porting a ~20 year old project from a pure Makefile based system to using CMake. We are mostly complete, however I have been having a sometimes intense debate with one …

---

## [Install an external project BEFORE configuring subdirs](https://discourse.cmake.org/t/install-an-external-project-before-configuring-subdirs/5709)

<div class="topic-metadata">

**Author:** [@Hameer\_Spire](https://discourse.cmake.org/u/Hameer_Spire)\
**Replies:** 3\
**Last updated:** [May 24, 2022, 5:57am UTC](https://discourse.cmake.org/t/install-an-external-project-before-configuring-subdirs/5709 "2022-05-24T05:57:33Z")

</div>

Hello! I’m using xtensor and xtensor-python in my projects. I’d like it very much if I could somehow pecify that these need to be installed before my project is configured. I’d also like to do this superbuild-style, like…

---

## [TARGET\_RUNTIME\_DLLS produces a malformed post-build copy command](https://discourse.cmake.org/t/target-runtime-dlls-produces-a-malformed-post-build-copy-command/4398)

<div class="topic-metadata">

**Author:** [@Eugene](https://discourse.cmake.org/u/Eugene)\
**Replies:** 7\
**Last updated:** [May 23, 2022, 6:48pm UTC](https://discourse.cmake.org/t/target-runtime-dlls-produces-a-malformed-post-build-copy-command/4398 "2022-05-23T18:48:03Z")

</div>

Let’s say I have two targets that I am working on Windows. Both of those targets include this CmakeLists.txt file as it is where the main executable is created for both of them. I use a visual studio generator for both o…

---

## [CPack Debian Multi-Arch control file tag](https://discourse.cmake.org/t/cpack-debian-multi-arch-control-file-tag/1753)

<div class="topic-metadata">

**Author:** [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Replies:** 8\
**Last updated:** [May 22, 2022, 2:33pm UTC](https://discourse.cmake.org/t/cpack-debian-multi-arch-control-file-tag/1753 "2022-05-22T14:33:49Z")

</div>

I need to set the Debian control file tag “Multi-Arch: foreign”. I don’t see CPACK\_DEBIAN variable to do this.

---

## [VSCode's variable substitution doesn't seen to work in CMakeLists.txt (Absolute paths works)](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701)

<div class="topic-metadata">

**Author:** [@Coziyu](https://discourse.cmake.org/u/Coziyu)\
**Replies:** 2\
**Last updated:** [May 21, 2022, 6:54pm UTC](https://discourse.cmake.org/t/vscodes-variable-substitution-doesnt-seen-to-work-in-cmakelists-txt-absolute-paths-works/5701 "2022-05-21T18:54:07Z")

</div>

Hey! I am a beginner learning how to use CMake in my VSCode C++ projects and I ran into some issues trying to figure out how to get CMake to include headers. Mainly, ${workspaceFolder} doesn’t seem to be substituting th…

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

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