# Code

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

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

**Page:** 47

---

## [Linking to curlcpp (a C++ curl wrapper)](https://discourse.cmake.org/t/linking-to-curlcpp-a-c-curl-wrapper/5677)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 9\
**Last updated:** [May 20, 2022, 10:22pm UTC](https://discourse.cmake.org/t/linking-to-curlcpp-a-c-curl-wrapper/5677 "2022-05-20T22:22:33Z")

</div>

I’m trying to link curlcpp, a C++ curl wrapper, to a library of my own. My idea was to: FetchContent\_Declare both curl and curlcpp. FetchContent\_MakeAvailable both of them as well. Link libcurl.lib and curlcpp lib to …

---

## [How for a binary executable to locate a config file?](https://discourse.cmake.org/t/how-for-a-binary-executable-to-locate-a-config-file/5591)

<div class="topic-metadata">

**Author:** [@Ronald](https://discourse.cmake.org/u/Ronald)\
**Replies:** 5\
**Last updated:** [May 20, 2022, 1:07pm UTC](https://discourse.cmake.org/t/how-for-a-binary-executable-to-locate-a-config-file/5591 "2022-05-20T13:07:17Z")

</div>

When developing the config file is in one path, and after installation the config file is in another path. It’s a binary who locates the config file, so configure\_file will not help. How to locate the config file in bo…

---

## [How to run script after a project creation.](https://discourse.cmake.org/t/how-to-run-script-after-a-project-creation/5687)

<div class="topic-metadata">

**Author:** [@Abraham](https://discourse.cmake.org/u/Abraham)\
**Replies:** 3\
**Last updated:** [May 20, 2022, 9:48am UTC](https://discourse.cmake.org/t/how-to-run-script-after-a-project-creation/5687 "2022-05-20T09:48:15Z")

</div>

Hi, We are using CMake to perform a migration of C/C++ code from Windows to Linux. It is a project composed of many libraries and highly dependent on Windows, so the migration is done little by little. One of the need…

---

## [Use cases for IMPORTED\_LINK\_DEPENDENT\_LIBRARIES](https://discourse.cmake.org/t/use-cases-for-imported-link-dependent-libraries/5662)

<div class="topic-metadata">

**Author:** [@friendlyanon](https://discourse.cmake.org/u/friendlyanon)\
**Replies:** 6\
**Last updated:** [May 20, 2022, 8:55am UTC](https://discourse.cmake.org/t/use-cases-for-imported-link-dependent-libraries/5662 "2022-05-20T08:55:12Z")

</div>

I stumbled into this property while looking at generated export sets and I’m curious what it is used for exactly. @ben.boeckel helpfully pointed me at commit 2cff26fa52cf9043f00d1efaaf31ab93e2db22e8 added by @brad.king …

---

## [CMake FILE\_SET for HEADER when using DESTINATION](https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692)

<div class="topic-metadata">

**Author:** [@RFRIEDM-Trimble](https://discourse.cmake.org/u/RFRIEDM-Trimble)\
**Replies:** 1\
**Last updated:** [May 19, 2022, 5:39am UTC](https://discourse.cmake.org/t/cmake-file-set-for-header-when-using-destination/5692 "2022-05-19T05:39:46Z")

</div>

Hello, I’m trying to migrate a multi-target library from CMake3.14 to CMake v3.23.1 to take advantage of the new FILE\_SET feature. I’ve purchased a copy of the 14th edition of Professional CMake and followed along the n…

---

## [JOB\_POOLS vs ninja jobs flag arg?](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 3\
**Last updated:** [May 18, 2022, 1:01pm UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652 "2022-05-18T13:01:31Z")

</div>

How is JOB\_POOL\_COMPILE and JOB\_POOL\_LINK different from -j flag passed to ninja on command line?

---

## [FetchContent\_Populate with custom unpacker](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 4\
**Last updated:** [May 18, 2022, 11:56am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679 "2022-05-18T11:56:10Z")

</div>

How to use FetchContent\_Populate and a custom unpack function? In my case there is a nested tar archive that needs to be unpacked.

---

## [Expand generator expression and add double qoutes aroung include dirs](https://discourse.cmake.org/t/expand-generator-expression-and-add-double-qoutes-aroung-include-dirs/5669)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 1\
**Last updated:** [May 13, 2022, 10:46pm UTC](https://discourse.cmake.org/t/expand-generator-expression-and-add-double-qoutes-aroung-include-dirs/5669 "2022-05-13T22:46:31Z")

</div>

Hi, I need to generate file with include dirs (taken from documentation): file(GENERATE OUTPUT ${config\_file} CONTENT "$\<$\<BOOL:$\<TARGET\_PROPERTY:${MY\_TARGET},INCLUDE\_DIRECTORIES\>\>: -I$\<JOIN:$\<TARGET\_PROPERTY:${MY…

---

## [How to check whether a source file exists, even if generated?](https://discourse.cmake.org/t/how-to-check-whether-a-source-file-exists-even-if-generated/5615)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 7\
**Last updated:** [May 12, 2022, 11:40pm UTC](https://discourse.cmake.org/t/how-to-check-whether-a-source-file-exists-even-if-generated/5615 "2022-05-12T23:40:09Z")

</div>

Is there a way to check whether a file exists either on disk or as a GENERATED file? Calling get\_source\_file\_properties on a non-existent file without a custom command defined for it results in a fatal error.

---

## [Excluding a subdirectory from FetchContent](https://discourse.cmake.org/t/excluding-a-subdirectory-from-fetchcontent/5660)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 2\
**Last updated:** [May 12, 2022, 4:36pm UTC](https://discourse.cmake.org/t/excluding-a-subdirectory-from-fetchcontent/5660 "2022-05-12T16:36:02Z")

</div>

I’m using FetchContent to add PDF-Writer to my project. This PDF-Writer project contains a series of subfolders for different libraries (Jpeg, Zlib…) and for the main library (PDFWriter). However, it also adds a test ex…

---

## [Pre compile header issue](https://discourse.cmake.org/t/pre-compile-header-issue/5650)

<div class="topic-metadata">

**Author:** [@Iamniki](https://discourse.cmake.org/u/Iamniki)\
**Replies:** 2\
**Last updated:** [May 11, 2022, 10:54am UTC](https://discourse.cmake.org/t/pre-compile-header-issue/5650 "2022-05-11T10:54:56Z")

</div>

Hi everyone, I have a very big project which compilation takes 40-60 mins with 4 threads. So I am trying to optimize it. I have pch.hpp and its ProjectRoot/deps\_header/cmakelists.txt is here option(BUILD\_USING\_PCH "Bui…

---

## [How to build for Win32 by default when using Visual Studio 2019 generator?](https://discourse.cmake.org/t/how-to-build-for-win32-by-default-when-using-visual-studio-2019-generator/5640)

<div class="topic-metadata">

**Author:** [@Artalus](https://discourse.cmake.org/u/Artalus)\
**Replies:** 2\
**Last updated:** [May 11, 2022, 8:38am UTC](https://discourse.cmake.org/t/how-to-build-for-win32-by-default-when-using-visual-studio-2019-generator/5640 "2022-05-11T08:38:07Z")

</div>

a.k.a. "How to force architecture of the build in the project itself?" I am currently porting to CMake a VS project that can be built only as 32-bit application. Yet for modern VS versions the default bitness is “same-a…

---

## [FetchContent\_Declare: should it re-fetch when the GIT\_SUBMODULES param changes?](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636)

<div class="topic-metadata">

**Author:** [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Replies:** 4\
**Last updated:** [May 9, 2022, 9:51pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-should-it-re-fetch-when-the-git-submodules-param-changes/5636 "2022-05-09T21:51:48Z")

</div>

I am modifying slightly a project called boost-cmake that I found on Github. In his project he grabs the boost tarball from jfrog.io, but I am instead using git to pull the overall project and selected submodules. Here…

---

## [linker errors - inflate already defined (assimp + freetype)](https://discourse.cmake.org/t/linker-errors-inflate-already-defined-assimp-freetype/5600)

<div class="topic-metadata">

**Author:** [@rystills](https://discourse.cmake.org/u/rystills)\
**Replies:** 2\
**Last updated:** [May 7, 2022, 5:31am UTC](https://discourse.cmake.org/t/linker-errors-inflate-already-defined-assimp-freetype/5600 "2022-05-07T05:31:59Z")

</div>

Hi there, I’m in the process of converting the following project from visual studio’s build system over to cmake: GitHub - rystills/RaiderEngine at switchToCmake The project relies on the following external dependencie…

---

## [Preset file grayed-out in the GUI](https://discourse.cmake.org/t/preset-file-grayed-out-in-the-gui/5621)

<div class="topic-metadata">

**Author:** [@BillH](https://discourse.cmake.org/u/BillH)\
**Replies:** 4\
**Last updated:** [May 6, 2022, 12:55pm UTC](https://discourse.cmake.org/t/preset-file-grayed-out-in-the-gui/5621 "2022-05-06T12:55:02Z")

</div>

I’m using the json presets feature for the first time. I’m having a problem with the CMake GUI. When I start-up the GUI and aim it for my source directory, it finds the json file, but it appears grayed-out in the Prese…

---

## [target\_compile\_definition build vs install phase](https://discourse.cmake.org/t/target-compile-definition-build-vs-install-phase/5618)

<div class="topic-metadata">

**Author:** [@Pacific](https://discourse.cmake.org/u/Pacific)\
**Replies:** 1\
**Last updated:** [May 5, 2022, 1:07pm UTC](https://discourse.cmake.org/t/target-compile-definition-build-vs-install-phase/5618 "2022-05-05T13:07:26Z")

</div>

Trying to add definition to executable as shown below. target\_compile\_definitions(definitionTest PUBLIC $\<INSTALL\_INTERFACE:EXAMPLE\_ASSETS\_PATH="install time path"\> $\<BUILD\_INTERFACE:EXAMPLE\_ASSETS\_P…

---

## [CUDA build error](https://discourse.cmake.org/t/cuda-build-error/5610)

<div class="topic-metadata">

**Author:** [@Jakub\_Mitura](https://discourse.cmake.org/u/Jakub_Mitura)\
**Replies:** 3\
**Last updated:** [May 5, 2022, 5:35am UTC](https://discourse.cmake.org/t/cuda-build-error/5610 "2022-05-05T05:35:31Z")

</div>

Hello In cmake build I have error that was not present in case when I had compiled it as visual studio project atomicAdd\_block is undefined I had found in stack overflow that one should set CMAKE\_CUDA\_ARCHITECTURES to…

---

## [Convention for install component names](https://discourse.cmake.org/t/convention-for-install-component-names/5608)

<div class="topic-metadata">

**Author:** [@jcfr](https://discourse.cmake.org/u/jcfr)\
**Replies:** 2\
**Last updated:** [May 4, 2022, 8:13am UTC](https://discourse.cmake.org/t/convention-for-install-component-names/5608 "2022-05-04T08:13:06Z")

</div>

The install command supports passing the COMPONENT option. The book Mastering CMake references suggest to use title case referencing Runtime and Development. The documentation suggests different conventions (either low…

---

## [online documentation for exact command references is missing](https://discourse.cmake.org/t/online-documentation-for-exact-command-references-is-missing/5586)

<div class="topic-metadata">

**Author:** [@Joe\_Nosay](https://discourse.cmake.org/u/Joe_Nosay)\
**Replies:** 1\
**Last updated:** [May 3, 2022, 5:41pm UTC](https://discourse.cmake.org/t/online-documentation-for-exact-command-references-is-missing/5586 "2022-05-03T17:41:04Z")

</div>

Source code using cmake does not include the command line for installing the binary into the standard $DIRECTORY/bin location. Where would a reference to these commands exist?

---

## [Cmake doesn't pickup where the required executable is (FLEX)](https://discourse.cmake.org/t/cmake-doesnt-pickup-where-the-required-executable-is-flex/5588)

<div class="topic-metadata">

**Author:** [@Rellotscrewdriver](https://discourse.cmake.org/u/Rellotscrewdriver)\
**Replies:** 2\
**Last updated:** [May 3, 2022, 11:18am UTC](https://discourse.cmake.org/t/cmake-doesnt-pickup-where-the-required-executable-is-flex/5588 "2022-05-03T11:18:52Z")

</div>

Hi, I’m trying to conifigure a third-party project using cmake 3.23 which requires FLEX, and I have both of them on my machine and for some reason it doesn’t pick up where they are, telling me that it couldn’t find f…

---

## [Need more than one local source directory in ExternalProject](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514)

<div class="topic-metadata">

**Author:** [@drlangnh](https://discourse.cmake.org/u/drlangnh)\
**Replies:** 2\
**Last updated:** [May 2, 2022, 7:56pm UTC](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514 "2022-05-02T19:56:24Z")

</div>

I have a project consisting of a CMake “external project” that creates a custom target for a Microchip PIC MCU. I would like to extend this project to build an additional custom target for a second MCU in the same famil…

---

## [Linking a lib file in cmake](https://discourse.cmake.org/t/linking-a-lib-file-in-cmake/5515)

<div class="topic-metadata">

**Author:** [@fardeen9983](https://discourse.cmake.org/u/fardeen9983)\
**Replies:** 2\
**Last updated:** [May 2, 2022, 8:18am UTC](https://discourse.cmake.org/t/linking-a-lib-file-in-cmake/5515 "2022-05-02T08:18:57Z")

</div>

Hi all, am very new to CMake so pardon me if get something wrong. I have a .dll, .lib, and .h which I want to add to my CMake project and use in cpp code. Here’s my project structure. I tried adding the lib referenc…

---

## [Advice on CMake code (total newbie here)](https://discourse.cmake.org/t/advice-on-cmake-code-total-newbie-here/5575)

<div class="topic-metadata">

**Author:** [@angelv](https://discourse.cmake.org/u/angelv)\
**Replies:** 0\
**Last updated:** [April 29, 2022, 4:47pm UTC](https://discourse.cmake.org/t/advice-on-cmake-code-total-newbie-here/5575 "2022-04-29T16:47:18Z")

</div>

Hello, I just wrote my first CMake code today, after reading part of the CMake tutorial yesterday and while it does work so far, I was hoping to get some advice from more experienced CMakes users, since I’m sure the cod…

---

## [Advice on how to compile same framework with n files f\_i each generating m\_i targets.](https://discourse.cmake.org/t/advice-on-how-to-compile-same-framework-with-n-files-f-i-each-generating-m-i-targets/5547)

<div class="topic-metadata">

**Author:** [@useredsa](https://discourse.cmake.org/u/useredsa)\
**Replies:** 7\
**Last updated:** [April 29, 2022, 3:02pm UTC](https://discourse.cmake.org/t/advice-on-how-to-compile-same-framework-with-n-files-f-i-each-generating-m-i-targets/5547 "2022-04-29T15:02:47Z")

</div>

Hello, Until now, I was using Makefiles, but I have decided to use CMake for the first time for a new project. The project is a framework for studying branch predictors. It should allow to generate different binaries u…

---

## [How to not append an extension to OUTPUT\_NAME automatically?](https://discourse.cmake.org/t/how-to-not-append-an-extension-to-output-name-automatically/5571)

<div class="topic-metadata">

**Author:** [@mscofield0](https://discourse.cmake.org/u/mscofield0)\
**Replies:** 1\
**Last updated:** [April 29, 2022, 12:11pm UTC](https://discourse.cmake.org/t/how-to-not-append-an-extension-to-output-name-automatically/5571 "2022-04-29T12:11:21Z")

</div>

Hi, I need to output a library and executable with a custom extension, but currently if I specify the extension within the OUTPUT\_NAME string, CMake automatically appends another extension on that string. I don’t want th…

---

## [ctest and MPI parallel googletests](https://discourse.cmake.org/t/ctest-and-mpi-parallel-googletests/5557)

<div class="topic-metadata">

**Author:** [@FG-TUM](https://discourse.cmake.org/u/FG-TUM)\
**Replies:** 4\
**Last updated:** [April 28, 2022, 10:57am UTC](https://discourse.cmake.org/t/ctest-and-mpi-parallel-googletests/5557 "2022-04-28T10:57:37Z")

</div>

The Goal My goal is to create tests with googleTest that make use of MPI, add them via gtest\_discover\_tests(), and execute them via ctest. I have seen posts where people use add\_test to add the MPI executer manually to …

---

## [How to build external deps once and use multiple times?](https://discourse.cmake.org/t/how-to-build-external-deps-once-and-use-multiple-times/5553)

<div class="topic-metadata">

**Author:** [@Iamniki](https://discourse.cmake.org/u/Iamniki)\
**Replies:** 2\
**Last updated:** [April 28, 2022, 8:43am UTC](https://discourse.cmake.org/t/how-to-build-external-deps-once-and-use-multiple-times/5553 "2022-04-28T08:43:37Z")

</div>

Lets consider myself as newbie, First, I would say all these are working completely fine, Here everytime I build, all deps will compile again. So I want to build all deps and keep its built file(headers and libraries) in…

---

## [Suspected bug with PCH REUSE\_FROM with Visual Studio 2017](https://discourse.cmake.org/t/suspected-bug-with-pch-reuse-from-with-visual-studio-2017/5520)

<div class="topic-metadata">

**Author:** [@JMH](https://discourse.cmake.org/u/JMH)\
**Replies:** 1\
**Last updated:** [April 28, 2022, 2:49am UTC](https://discourse.cmake.org/t/suspected-bug-with-pch-reuse-from-with-visual-studio-2017/5520 "2022-04-28T02:49:37Z")

</div>

I have a complex project using CMake 3.22.2. To optimize the compilation time, I want to use precompiled headers. It works fine with Linux/ RedHat7 / gcc but fails with Winserver 2016 / Visual Studio 2017. For Windows co…

---

## [CMAKE\_OSX\_ARCHITECTURES and separate files for certain architectures?](https://discourse.cmake.org/t/cmake-osx-architectures-and-separate-files-for-certain-architectures/5561)

<div class="topic-metadata">

**Author:** [@pweiskircher](https://discourse.cmake.org/u/pweiskircher)\
**Replies:** 2\
**Last updated:** [April 28, 2022, 1:03am UTC](https://discourse.cmake.org/t/cmake-osx-architectures-and-separate-files-for-certain-architectures/5561 "2022-04-28T01:03:58Z")

</div>

Hi there! I found myself needing to compile a library today with M1 support. Googling a little, I found CMAKE\_OSX\_ARCHITECTURES. This worked great for most of our code! But then I came across our libjpeg\_turbo dependen…

---

## [Building multiple versions of a library](https://discourse.cmake.org/t/building-multiple-versions-of-a-library/5539)

<div class="topic-metadata">

**Author:** [@Steven\_Atkinson](https://discourse.cmake.org/u/Steven_Atkinson)\
**Replies:** 1\
**Last updated:** [April 27, 2022, 6:56pm UTC](https://discourse.cmake.org/t/building-multiple-versions-of-a-library/5539 "2022-04-27T18:56:45Z")

</div>

I’m looking for a best practice to build a library multiple times with different sets of defines. This is an old legacy library recently converted to cmake. The project is a single library and builds on multiple platfor…

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

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