# Code

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

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

**Page:** 52

---

## [How to modify this CMakeLists.txt?](https://discourse.cmake.org/t/how-to-modify-this-cmakelists-txt/4707)

<div class="topic-metadata">

**Author:** [@greendragon](https://discourse.cmake.org/u/greendragon)\
**Replies:** 0\
**Last updated:** [December 18, 2021, 3:52pm UTC](https://discourse.cmake.org/t/how-to-modify-this-cmakelists-txt/4707 "2021-12-18T15:52:39Z")

</div>

I have a C++ project on a Linux VM. The project runs fine in Visual C++ on my Win8.1. The project has pngs. On the VM cmake … and make work but the program stops when it has to render the pngs. This is the error I get…

---

## [CMake fails to build simplest possible example](https://discourse.cmake.org/t/cmake-fails-to-build-simplest-possible-example/4702)

<div class="topic-metadata">

**Author:** [@jspaceboots](https://discourse.cmake.org/u/jspaceboots)\
**Replies:** 2\
**Last updated:** [December 18, 2021, 12:31am UTC](https://discourse.cmake.org/t/cmake-fails-to-build-simplest-possible-example/4702 "2021-12-18T00:31:36Z")

</div>

Apologies in advance for how simple this is, very new to CMake and can’t get the simplest possible example working. I’ve got a project consisting of a single .c file (main.c), the contents of which are: #include \<stdio…

---

## [How to make cmake use -shared -dlink](https://discourse.cmake.org/t/how-to-make-cmake-use-shared-dlink/4669)

<div class="topic-metadata">

**Author:** [@jgphpc](https://discourse.cmake.org/u/jgphpc)\
**Replies:** 2\
**Last updated:** [December 17, 2021, 12:55pm UTC](https://discourse.cmake.org/t/how-to-make-cmake-use-shared-dlink/4669 "2021-12-17T12:55:38Z")

</div>

Hi, This is my first post here. I am trying to write a CMakeLists.txt that will build a HIP test code (hipify from cuda): hipcc --offload-arch=gfx908 -fPIC -fgpu-rdc -std=c++17 -w -c domain/util.cu hipcc --offload-a…

---

## [How to define variable？](https://discourse.cmake.org/t/how-to-define-variable/4683)

<div class="topic-metadata">

**Author:** [@wang\_yali](https://discourse.cmake.org/u/wang_yali)\
**Replies:** 2\
**Last updated:** [December 16, 2021, 6:01pm UTC](https://discourse.cmake.org/t/how-to-define-variable/4683 "2021-12-16T18:01:46Z")

</div>

---

## [Relative including cmake scripts in a subproject](https://discourse.cmake.org/t/relative-including-cmake-scripts-in-a-subproject/4638)

<div class="topic-metadata">

**Author:** [@mcopik](https://discourse.cmake.org/u/mcopik)\
**Replies:** 3\
**Last updated:** [December 17, 2021, 7:44am UTC](https://discourse.cmake.org/t/relative-including-cmake-scripts-in-a-subproject/4638 "2021-12-17T07:44:42Z")

</div>

HI! I have the following problem: I’m fetching and building a few dependencies that should ship with my applications, primarily header-only and static libraries. I’m using FetchContent for that and it has been working g…

---

## [How do I integrate zlib with my build?](https://discourse.cmake.org/t/how-do-i-integrate-zlib-with-my-build/4658)

<div class="topic-metadata">

**Author:** [@MrZoraman](https://discourse.cmake.org/u/MrZoraman)\
**Replies:** 4\
**Last updated:** [December 15, 2021, 8:29pm UTC](https://discourse.cmake.org/t/how-do-i-integrate-zlib-with-my-build/4658 "2021-12-15T20:29:41Z")

</div>

zlib is built with cmake, and if I add\_subdirectory it, it generates a required header zconf.h which it puts in the binary dir. Other projects that depend on zlib like libpng ask for the include dir of zlib (Could NOT fi…

---

## [Run cmake within cmake to initialize dependencies?](https://discourse.cmake.org/t/run-cmake-within-cmake-to-initialize-dependencies/4674)

<div class="topic-metadata">

**Author:** [@MrZoraman](https://discourse.cmake.org/u/MrZoraman)\
**Replies:** 2\
**Last updated:** [December 15, 2021, 6:41pm UTC](https://discourse.cmake.org/t/run-cmake-within-cmake-to-initialize-dependencies/4674 "2021-12-15T18:41:37Z")

</div>

I want to initialize my project’s dependencies. I know there’s FetchContent which will download the dependency and then add it as a subdirectory for my build. Some dependencies don’t play nice with this though since the…

---

## [Method to force a rerun of cmake](https://discourse.cmake.org/t/method-to-force-a-rerun-of-cmake/4665)

<div class="topic-metadata">

**Author:** [@scottaronbloom](https://discourse.cmake.org/u/scottaronbloom)\
**Replies:** 3\
**Last updated:** [December 15, 2021, 12:13am UTC](https://discourse.cmake.org/t/method-to-force-a-rerun-of-cmake/4665 "2021-12-15T00:13:24Z")

</div>

In the same manner that all CMakeLists.txt (and other) files cause an out of date mode for the cmake system itself, where if you modify one of the cmake files, cmake is automatically re-run. In visual studio this is par…

---

## [file manipulation at configure time or generate time?](https://discourse.cmake.org/t/file-manipulation-at-configure-time-or-generate-time/4655)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 2\
**Last updated:** [December 13, 2021, 10:49pm UTC](https://discourse.cmake.org/t/file-manipulation-at-configure-time-or-generate-time/4655 "2021-12-13T22:49:00Z")

</div>

It’s not immediately obvious which functions run at which time. For example file(WRITE | APPEND) runs at configure time, file(CONFIGURE) at generate time. This code runs at configure time: file(WRITE eval.cmake ...) in…

---

## [SDL2\_image not found](https://discourse.cmake.org/t/sdl2-image-not-found/4652)

<div class="topic-metadata">

**Author:** [@greendragon](https://discourse.cmake.org/u/greendragon)\
**Replies:** 1\
**Last updated:** [December 13, 2021, 10:45pm UTC](https://discourse.cmake.org/t/sdl2-image-not-found/4652 "2021-12-13T22:45:24Z")

</div>

Hello, I am trying to run the github project found at the link on the bottom of the page below: When I run the project at cmake … I get the following error: The C compiler identification is GNU 5.5.0 – The CXX comp…

---

## [Using CURL library in windows](https://discourse.cmake.org/t/using-curl-library-in-windows/4650)

<div class="topic-metadata">

**Author:** [@xhustango](https://discourse.cmake.org/u/xhustango)\
**Replies:** 2\
**Last updated:** [December 13, 2021, 4:35pm UTC](https://discourse.cmake.org/t/using-curl-library-in-windows/4650 "2021-12-13T16:35:07Z")

</div>

Hey there, I am developing a project in windows 10, I need the curl library for building some part of my project. At the moment, curl is installed on the machine, I can use PowerShell to use curl. The issue I have it’s…

---

## [Using ifelse in cmake](https://discourse.cmake.org/t/using-ifelse-in-cmake/4622)

<div class="topic-metadata">

**Author:** [@Vitaly\_Starkov](https://discourse.cmake.org/u/Vitaly_Starkov)\
**Replies:** 1\
**Last updated:** [December 11, 2021, 7:17pm UTC](https://discourse.cmake.org/t/using-ifelse-in-cmake/4622 "2021-12-11T19:17:16Z")

</div>

hi! I am a technical writer and I have a book that works approximately as follows: set(Installation\_Name Installation/Chapter1.md Installation/Chapter2.md ) add\_custom\_command(OUTPUT Installation\_Output COMMAND cat…

---

## [wx/msw/hand.cur not found](https://discourse.cmake.org/t/wx-msw-hand-cur-not-found/4631)

<div class="topic-metadata">

**Author:** [@Mauro\_Ziliani](https://discourse.cmake.org/u/Mauro_Ziliani)\
**Replies:** 1\
**Last updated:** [December 9, 2021, 5:39pm UTC](https://discourse.cmake.org/t/wx-msw-hand-cur-not-found/4631 "2021-12-09T17:39:43Z")

</div>

Hi all. I try to compile with MinGW 8.1.0 an app based on wx 3.1.5. I get the following error. C:\\Qt\\Tools\\mingw810\_32\\bin\\windres.exe: can’t open cursor file \`wx/msw/hand.cur’: Permission denied This is the verbose …

---

## [How to get version from header in Find Module?](https://discourse.cmake.org/t/how-to-get-version-from-header-in-find-module/4625)

<div class="topic-metadata">

**Author:** [@szhorvat](https://discourse.cmake.org/u/szhorvat)\
**Replies:** 1\
**Last updated:** [December 8, 2021, 7:34pm UTC](https://discourse.cmake.org/t/how-to-get-version-from-header-in-find-module/4625 "2021-12-08T19:34:42Z")

</div>

When writing a new Find Module, what is the recommended way to extract the library version from a C header file? As an example, this FindGLPK module uses regexes to do it. This seems messy and fragile to me, and I am wo…

---

## [Exclude auto-generated source files from the build?](https://discourse.cmake.org/t/exclude-auto-generated-source-files-from-the-build/4624)

<div class="topic-metadata">

**Author:** [@amzh](https://discourse.cmake.org/u/amzh)\
**Replies:** 2\
**Last updated:** [December 8, 2021, 3:37pm UTC](https://discourse.cmake.org/t/exclude-auto-generated-source-files-from-the-build/4624 "2021-12-08T15:37:21Z")

</div>

Hello, during the project build I have files generated by an external python script, that script is used on both Windows and macOS. I need to exclude a certain file from the Xcode build. Is there a way to do that via c…

---

## [Consecutive target\_link\_libraries with and without PUBLIC](https://discourse.cmake.org/t/consecutive-target-link-libraries-with-and-without-public/3592)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 5\
**Last updated:** [September 3, 2021, 9:23am UTC](https://discourse.cmake.org/t/consecutive-target-link-libraries-with-and-without-public/3592 "2021-09-03T09:23:03Z")

</div>

cmake requires consecutive target\_link\_libraries invocations to use same syntax. E.g. the following will not work; target\_link\_libraries(target PUBLIC A) target\_link\_libraries(target B) Any way to get around that?

---

## [Warning when JSON strings are stored in a cache variable](https://discourse.cmake.org/t/warning-when-json-strings-are-stored-in-a-cache-variable/4599)

<div class="topic-metadata">

**Author:** [@mbee](https://discourse.cmake.org/u/mbee)\
**Replies:** 8\
**Last updated:** [December 8, 2021, 9:35am UTC](https://discourse.cmake.org/t/warning-when-json-strings-are-stored-in-a-cache-variable/4599 "2021-12-08T09:35:07Z")

</div>

I need to manage some values coming from the strings JSON API in a cache variable. This triggers the following warning: CMake Warning: Value of pb\_json\_arm contained a newline; truncating How can I get rid of this wa…

---

## [Using a function keyword in a generator expression](https://discourse.cmake.org/t/using-a-function-keyword-in-a-generator-expression/4601)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 2\
**Last updated:** [December 6, 2021, 10:52am UTC](https://discourse.cmake.org/t/using-a-function-keyword-in-a-generator-expression/4601 "2021-12-06T10:52:01Z")

</div>

What’s the correct syntax for using a function argument as a conditional operator in a generator expression? The example below encapsulates what I’m trying to achieve, but the syntax here doesn’t work, and neither do var…

---

## [Using object libraries to build a library for distribution.](https://discourse.cmake.org/t/using-object-libraries-to-build-a-library-for-distribution/4574)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 6\
**Last updated:** [December 3, 2021, 8:51pm UTC](https://discourse.cmake.org/t/using-object-libraries-to-build-a-library-for-distribution/4574 "2021-12-03T20:51:18Z")

</div>

Situation: We have a complex code base with lots of smallish libraries generated by CMake. For internal use, we can just link against these libraries. However, we also want to provide a public library for 3rd parties …

---

## [Call find\_file from a cmake function?](https://discourse.cmake.org/t/call-find-file-from-a-cmake-function/4588)

<div class="topic-metadata">

**Author:** [@amzh](https://discourse.cmake.org/u/amzh)\
**Replies:** 3\
**Last updated:** [December 3, 2021, 12:03pm UTC](https://discourse.cmake.org/t/call-find-file-from-a-cmake-function/4588 "2021-12-03T12:03:12Z")

</div>

Hello, I’m having trouble making my function FIND\_THIRD\_PARTY\_LIB work. Inside it I call find\_file but the parameter holding the result doesn’t renew apparently because If the full path to a file is found the result…

---

## [Clarification: Shared object (DLL) copying](https://discourse.cmake.org/t/clarification-shared-object-dll-copying/4557)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 9\
**Last updated:** [December 2, 2021, 7:50am UTC](https://discourse.cmake.org/t/clarification-shared-object-dll-copying/4557 "2021-12-02T07:50:35Z")

</div>

Over the decades, a lot has been written about associating a DLL with an executable and getting that DLL into install directories, or getting that DLL into ctest directories. I’m trying to modernize a 14 year old CMakeL…

---

## [FindBoost.cmake with python 3.10](https://discourse.cmake.org/t/findboost-cmake-with-python-3-10/4586)

<div class="topic-metadata">

**Author:** [@MM77](https://discourse.cmake.org/u/MM77)\
**Replies:** 0\
**Last updated:** [December 1, 2021, 4:58pm UTC](https://discourse.cmake.org/t/findboost-cmake-with-python-3-10/4586 "2021-12-01T16:58:27Z")

</div>

Looking at the regexps here FindBoost.cmake there is accounting only for 2 digit versions of python Also the extra back slash is confusing alexander.grund@tu-dresden.de perhaps you have an idea how to extend to 2 dig…

---

## [find\_package, Config mode: won't find library](https://discourse.cmake.org/t/find-package-config-mode-wont-find-library/4573)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 5\
**Last updated:** [December 1, 2021, 10:59am UTC](https://discourse.cmake.org/t/find-package-config-mode-wont-find-library/4573 "2021-12-01T10:59:36Z")

</div>

We equipped a library package with a \*Config.cmake file, following step 11 of the CMake tutorial. Yet our downstream software fails to find the library. Our package is called “formfactor” \[mlz / libformfactor · GitLab\]…

---

## [Generator expressions for IMPORTED\_IMPLIB/LOCATION properties?](https://discourse.cmake.org/t/generator-expressions-for-imported-implib-location-properties/4564)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 1\
**Last updated:** [November 28, 2021, 9:59am UTC](https://discourse.cmake.org/t/generator-expressions-for-imported-implib-location-properties/4564 "2021-11-28T09:59:51Z")

</div>

CMake 3.21: I’m trying to wrap fmod with a SHARED IMPORTED target and support Windows builds. The .lib name depends on bitness and build type, as does the dll, but the IMPORTED\_IMPLIB and IMPORTED\_LOCATION properties do…

---

## [Is there a "$/", an easy "path-separator" variable?](https://discourse.cmake.org/t/is-there-a-an-easy-path-separator-variable/4562)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 3\
**Last updated:** [November 28, 2021, 9:53am UTC](https://discourse.cmake.org/t/is-there-a-an-easy-path-separator-variable/4562 "2021-11-28T09:53:08Z")

</div>

Does CMake have some (easy) way to inject a platform-specific path separator? Something like “$/”? SET(DESTINATION\_DIR "${CMAKE\_CURRENT\_LIST\_DIR}$/..$/bin") Also … if there isn’t, it would be awesome if it could automa…

---

## [Copy file on every cmake command](https://discourse.cmake.org/t/copy-file-on-every-cmake-command/4561)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 1\
**Last updated:** [November 28, 2021, 12:29am UTC](https://discourse.cmake.org/t/copy-file-on-every-cmake-command/4561 "2021-11-28T00:29:27Z")

</div>

I use VS Code together with compile\_commands.json and my extension / language server needs to know where the compile\_commands.json lives. The problem is that I use multiple build directories / presets and therefore the …

---

## [Any advice on bridging the gap between cargo and CPack?](https://discourse.cmake.org/t/any-advice-on-bridging-the-gap-between-cargo-and-cpack/4542)

<div class="topic-metadata">

**Author:** [@arclight](https://discourse.cmake.org/u/arclight)\
**Replies:** 0\
**Last updated:** [November 24, 2021, 2:32pm UTC](https://discourse.cmake.org/t/any-advice-on-bridging-the-gap-between-cargo-and-cpack/4542 "2021-11-24T14:32:47Z")

</div>

Has anyone used CMake/CPack to package compiled Rust applications, and if so, how did you obtain the locations of the compiled executables? I have a simple standalone Rust project that I’d like to package into an instal…

---

## [Problem enabling 64 bit Fortran compilation on Windows using Intel OneAPI with Cmake on Windows](https://discourse.cmake.org/t/problem-enabling-64-bit-fortran-compilation-on-windows-using-intel-oneapi-with-cmake-on-windows/4541)

<div class="topic-metadata">

**Author:** [@Vishwa\_C](https://discourse.cmake.org/u/Vishwa_C)\
**Replies:** 1\
**Last updated:** [November 24, 2021, 1:58pm UTC](https://discourse.cmake.org/t/problem-enabling-64-bit-fortran-compilation-on-windows-using-intel-oneapi-with-cmake-on-windows/4541 "2021-11-24T13:58:44Z")

</div>

Hi, I am trying to enable 64 bit integer size for a sample hello world kind of Fortran test code, in an MPI setup. OS: Windows 10 Compiler used: Intel OneAPI 2021.3.0 MPI: Intel MPI using a CmakeLists file to compil…

---

## [CMAKE\_COMPILER\_IS\_MINGW removed?](https://discourse.cmake.org/t/cmake-compiler-is-mingw-removed/4539)

<div class="topic-metadata">

**Author:** [@Scott\_Michel](https://discourse.cmake.org/u/Scott_Michel)\
**Replies:** 1\
**Last updated:** [November 24, 2021, 3:44am UTC](https://discourse.cmake.org/t/cmake-compiler-is-mingw-removed/4539 "2021-11-24T03:44:10Z")

</div>

Just noticed that CMAKE\_COMPILER\_IS\_MINGW disappeared between the 3.21.4 and 3.22 releases. Was this a feature? Reason for asking: The libsdl CMake build depends on CMAKE\_COMPILER\_IS\_MINGW to detect whether to nag the d…

---

## [No way to create Xcode sub-projects?](https://discourse.cmake.org/t/no-way-to-create-xcode-sub-projects/4525)

<div class="topic-metadata">

**Author:** [@amzh](https://discourse.cmake.org/u/amzh)\
**Replies:** 1\
**Last updated:** [November 24, 2021, 2:24am UTC](https://discourse.cmake.org/t/no-way-to-create-xcode-sub-projects/4525 "2021-11-24T02:24:36Z")

</div>

Hello, documentation says that The Visual Studio Generators create a .sln file for each directory whose CMakeLists.txt file calls the project() command. hence we can easily have a sub-projects tree in IDE, is there…

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

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