# Code

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

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

**Page:** 17

---

## [test case for internal library (PUBLIC and PRIVATE)](https://discourse.cmake.org/t/test-case-for-internal-library-public-and-private/12707)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 0\
**Last updated:** [October 8, 2024, 7:04am UTC](https://discourse.cmake.org/t/test-case-for-internal-library-public-and-private/12707 "2024-10-08T07:04:47Z")

</div>

I reference two project and add some dependent library. The cmake tell us that using PRIVATE to protect our code Background main project bar foo library The bar execution will use the foo library where foo use s…

---

## [How to incorporate app icon files for iOS into Xcode 14?](https://discourse.cmake.org/t/how-to-incorporate-app-icon-files-for-ios-into-xcode-14/7386)

<div class="topic-metadata">

**Author:** [@paul.masristone](https://discourse.cmake.org/u/paul.masristone)\
**Replies:** 17\
**Last updated:** [October 7, 2024, 5:39pm UTC](https://discourse.cmake.org/t/how-to-incorporate-app-icon-files-for-ios-into-xcode-14/7386 "2024-10-07T17:39:13Z")

</div>

I have previously published my Qt app using Qt 5 + qmake. I am now ready to release a new version using Qt 6 + CMake. (I am using Qt 6.4.2 and CMake 3.24.2) However I am struggling to get app icons into Xcode 14.2 in a…

---

## [BUILD\_SHARED\_LIBS Release and Debug](https://discourse.cmake.org/t/build-shared-libs-release-and-debug/12699)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 1\
**Last updated:** [October 7, 2024, 6:00am UTC](https://discourse.cmake.org/t/build-shared-libs-release-and-debug/12699 "2024-10-07T06:00:19Z")

</div>

mkdir build cd build cmake -DBUILD\_SHARED\_LIBS Debug .. cmake -DBUILD\_SHARED\_LIBS Release .. If I already build with debug, and then build release without any make clean or delete folder. Does Debug affect the release…

---

## [Make Linker Script Available To An Upstream Dependency](https://discourse.cmake.org/t/make-linker-script-available-to-an-upstream-dependency/12688)

<div class="topic-metadata">

**Author:** [@Scruffmeister](https://discourse.cmake.org/u/Scruffmeister)\
**Replies:** 2\
**Last updated:** [October 6, 2024, 1:02pm UTC](https://discourse.cmake.org/t/make-linker-script-available-to-an-upstream-dependency/12688 "2024-10-06T13:02:14Z")

</div>

I have a linker script (link1.ld) in depL that I need to use in depA. Please could someone explain to me how make depL make the link1.ld script available to depA so that the following works: target\_link\_options(depA PR…

---

## [import std; in cmake 3.30](https://discourse.cmake.org/t/import-std-in-cmake-3-30/10885)

<div class="topic-metadata">

**Author:** [@John\_Fourkiotis](https://discourse.cmake.org/u/John_Fourkiotis)\
**Replies:** 3\
**Last updated:** [October 4, 2024, 8:56am UTC](https://discourse.cmake.org/t/import-std-in-cmake-3-30/10885 "2024-10-04T08:56:44Z")

</div>

I’m trying to follow the information mentioned about importing std using MSVC but I get the following error during project generation: -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22000. -- The C…

---

## [undefined variable is defined](https://discourse.cmake.org/t/undefined-variable-is-defined/12666)

<div class="topic-metadata">

**Author:** [@gbburkhardt](https://discourse.cmake.org/u/gbburkhardt)\
**Replies:** 2\
**Last updated:** [October 1, 2024, 11:07pm UTC](https://discourse.cmake.org/t/undefined-variable-is-defined/12666 "2024-10-01T23:07:44Z")

</div>

cmake version 3.28.1 MinGW: MSYS\_NT-10.0-22631 DESKTOP-UH4OPKD 3.4.10.x86\_64 2023-12-22 10:06 UTC x86\_64 Msys I’ve been debugging a problem related to CheckSymbolExists macro. It seems that the ‘try\_compile’ test is …

---

## [Inconsistencies with install() and relative path to GNUInstallDirs](https://discourse.cmake.org/t/inconsistencies-with-install-and-relative-path-to-gnuinstalldirs/12656)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 7\
**Last updated:** [October 2, 2024, 7:29am UTC](https://discourse.cmake.org/t/inconsistencies-with-install-and-relative-path-to-gnuinstalldirs/12656 "2024-10-02T07:29:04Z")

</div>

Hello, I’m just reading and adapting a project for the installation phase which uses the GNUInstallDirs module: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html The module documentation mentions some spe…

---

## [Import C++ Standard Library Headers on CMake 3.30](https://discourse.cmake.org/t/import-c-standard-library-headers-on-cmake-3-30/11354)

<div class="topic-metadata">

**Author:** [@04a](https://discourse.cmake.org/u/04a)\
**Replies:** 3\
**Last updated:** [September 29, 2024, 9:49pm UTC](https://discourse.cmake.org/t/import-c-standard-library-headers-on-cmake-3-30/11354 "2024-09-29T21:49:50Z")

</div>

Hi, I’m trying to write a CMakeLists to compile C++ code with import \<...\>;, like: // main.cpp import \<iostream\>; int main() { std::cout \<\< "Hello World" \<\< std::endl; return 0; } It can be compiled by a simple co…

---

## [Need help with CMAKE\_MSVC\_RUNTIME\_LIBRARY variable](https://discourse.cmake.org/t/need-help-with-cmake-msvc-runtime-library-variable/11780)

<div class="topic-metadata">

**Author:** [@AlifianK](https://discourse.cmake.org/u/AlifianK)\
**Replies:** 0\
**Last updated:** [September 26, 2024, 5:10pm UTC](https://discourse.cmake.org/t/need-help-with-cmake-msvc-runtime-library-variable/11780 "2024-09-26T17:10:25Z")

</div>

I tried building static libjxl with MSVC toolchain and clang with GNU-Like command by specifying -DCMAKE\_CXX\_COMPILER=clang++ in release mode, but it failed. I bisected the code and the issue started after this pull req…

---

## [try\_compile and genex in CMAKE\_MSVC\_RUNTIME\_LIBRARY](https://discourse.cmake.org/t/try-compile-and-genex-in-cmake-msvc-runtime-library/11757)

<div class="topic-metadata">

**Author:** [@t-b](https://discourse.cmake.org/u/t-b)\
**Replies:** 4\
**Last updated:** [September 25, 2024, 12:32pm UTC](https://discourse.cmake.org/t/try-compile-and-genex-in-cmake-msvc-runtime-library/11757 "2024-09-25T12:32:57Z")

</div>

On Windows 11, ninja 1.11.1 and cmake 3.30.3 with VS 2022. When I configure the following CMakeLists.txt cmake\_minimum\_required(VERSION 3.18...3.30 FATAL\_ERROR) set(CMAKE\_MSVC\_RUNTIME\_LIBRARY "MultiThreaded$\<$\<CONFIG:…

---

## [Module std.compat is not compiled with UTF8](https://discourse.cmake.org/t/module-std-compat-is-not-compiled-with-utf8/11764)

<div class="topic-metadata">

**Author:** [@JuliusCaesar](https://discourse.cmake.org/u/JuliusCaesar)\
**Replies:** 0\
**Last updated:** [September 25, 2024, 9:33am UTC](https://discourse.cmake.org/t/module-std-compat-is-not-compiled-with-utf8/11764 "2024-09-25T09:33:35Z")

</div>

Hey guys, I have been trying to work with import.std using this blogpost with latest MSVC17 For most files this works fine, however some headers cause an MSVC warning. "Warning incompatilbe environment when importing m…

---

## [Xcode problem with files which has vary configuration](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754)

<div class="topic-metadata">

**Author:** [@Gregor\_Smith](https://discourse.cmake.org/u/Gregor_Smith)\
**Replies:** 5\
**Last updated:** [September 24, 2024, 1:04pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754 "2024-09-24T13:04:26Z")

</div>

Hi everyone Below I present a example source code that I hav borrow from other topic but it is a good example of my problem. I do not know if it is a cmake problem or what but I cannot belive that this simple approach …

---

## [DEBUG\_POSTFIX (VS\_DOTNET\_TARGET\_FRAMEWORK\_VERSION vs DOTNET\_SDK)](https://discourse.cmake.org/t/debug-postfix-vs-dotnet-target-framework-version-vs-dotnet-sdk/11759)

<div class="topic-metadata">

**Author:** [@AlamoGrito](https://discourse.cmake.org/u/AlamoGrito)\
**Replies:** 1\
**Last updated:** [September 24, 2024, 10:40am UTC](https://discourse.cmake.org/t/debug-postfix-vs-dotnet-target-framework-version-vs-dotnet-sdk/11759 "2024-09-24T10:40:55Z")

</div>

I had the need to have C# code compiled to target the Microsoft .Net Framework, .Net6 or .Net8 depending on the CMake option selected. For the MS .Net Framework I’m setting the target property VS\_DOTNET\_TARGET\_FRAMEWOR…

---

## [libcurl options with external download](https://discourse.cmake.org/t/libcurl-options-with-external-download/11758)

<div class="topic-metadata">

**Author:** [@tabascounlimited](https://discourse.cmake.org/u/tabascounlimited)\
**Replies:** 0\
**Last updated:** [September 24, 2024, 6:24am UTC](https://discourse.cmake.org/t/libcurl-options-with-external-download/11758 "2024-09-24T06:24:15Z")

</div>

Hi For downloading external content CMake uses libcurl internally. However is it not possible to specify custom libcurl options that are otherwise not documented in file(URL) or ExternalProject for the resulting downloa…

---

## [add\_custom\_command() and failing COMMANDs](https://discourse.cmake.org/t/add-custom-command-and-failing-commands/11751)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 6\
**Last updated:** [September 23, 2024, 2:52pm UTC](https://discourse.cmake.org/t/add-custom-command-and-failing-commands/11751 "2024-09-23T14:52:49Z")

</div>

Hello, What is the expected behavior when one of the COMMANDs given to add\_custom\_command() fail ? Are the following commands processed ? Is there a log ? Does the CMake command return an error code ? Thanks.

---

## [Preventing the contents of a string being substituted](https://discourse.cmake.org/t/preventing-the-contents-of-a-string-being-substituted/11752)

<div class="topic-metadata">

**Author:** [@h-2](https://discourse.cmake.org/u/h-2)\
**Replies:** 4\
**Last updated:** [September 23, 2024, 2:31pm UTC](https://discourse.cmake.org/t/preventing-the-contents-of-a-string-being-substituted/11752 "2024-09-23T14:31:11Z")

</div>

I want to run awk with a script as argument. This is what I have done set(AWK\_SCRIPT \[=\[$1 == "TOTAL" && $4 == "100%" { exit 0; }; END { print "Line coverage is not 100%. Please see the HTML coverage report."; exit 1; }…

---

## [libssh2](https://discourse.cmake.org/t/libssh2/11753)

<div class="topic-metadata">

**Author:** [@MM77](https://discourse.cmake.org/u/MM77)\
**Replies:** 1\
**Last updated:** [September 23, 2024, 2:19pm UTC](https://discourse.cmake.org/t/libssh2/11753 "2024-09-23T14:19:50Z")

</div>

Google searches return references to FindLibSSH2.cmake however I can’t find it in the Modules directory of rpm install of cmake 3.27.7 any advice? is it part of the modules list for cmake?

---

## [Custom command not re-run when dependencies change](https://discourse.cmake.org/t/custom-command-not-re-run-when-dependencies-change/11596)

<div class="topic-metadata">

**Author:** [@Hannes\_Hauswedell](https://discourse.cmake.org/u/Hannes_Hauswedell)\
**Replies:** 11\
**Last updated:** [September 23, 2024, 1:18pm UTC](https://discourse.cmake.org/t/custom-command-not-re-run-when-dependencies-change/11596 "2024-09-23T13:18:24Z")

</div>

Hi, I have been trying to make this work for hours now, but I can’t find the problem. I have a command that generates a coverage report. Naturally, I want this report to be re-generated when the unit tests are updated…

---

## [SUFFIX is missing on windows](https://discourse.cmake.org/t/suffix-is-missing-on-windows/11734)

<div class="topic-metadata">

**Author:** [@noahdav](https://discourse.cmake.org/u/noahdav)\
**Replies:** 9\
**Last updated:** [September 22, 2024, 10:08pm UTC](https://discourse.cmake.org/t/suffix-is-missing-on-windows/11734 "2024-09-22T22:08:17Z")

</div>

Hi, I am trying to write a cmake script that copies the compiled binary to a build location. It tries to uses SUFFIX property to build up the destination path but on windows (I have not tried on other platforms) it ret…

---

## [Beginner: Ways of including source subfolders?](https://discourse.cmake.org/t/beginner-ways-of-including-source-subfolders/9773)

<div class="topic-metadata">

**Author:** [@SparkyNZ](https://discourse.cmake.org/u/SparkyNZ)\
**Replies:** 6\
**Last updated:** [September 20, 2024, 6:46pm UTC](https://discourse.cmake.org/t/beginner-ways-of-including-source-subfolders/9773 "2024-09-20T18:46:43Z")

</div>

Can CMake be used to dynamically pull in source file folders? I’m not talking about using libraries per se. Say for example I have a top level CMakeLists.txt file. I know I can explicitly include subfolder content like …

---

## [How to use XCODE\_SCHEME\_ARGUMENTS?](https://discourse.cmake.org/t/how-to-use-xcode-scheme-arguments/2332)

<div class="topic-metadata">

**Author:** [@sfp](https://discourse.cmake.org/u/sfp)\
**Replies:** 5\
**Last updated:** [September 20, 2024, 11:24am UTC](https://discourse.cmake.org/t/how-to-use-xcode-scheme-arguments/2332 "2024-09-20T11:24:38Z")

</div>

How do I set this property to specify some default arguments for an executable when using the Xcode generator? I have something like this: add\_executable (test test.c ...) if (CMAKE\_GENERATOR MATCHES "Xcode") set\_p…

---

## [Miss target\_include\_directories](https://discourse.cmake.org/t/miss-target-include-directories/11702)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 3\
**Last updated:** [September 20, 2024, 6:19am UTC](https://discourse.cmake.org/t/miss-target-include-directories/11702 "2024-09-20T06:19:35Z")

</div>

https://simpleitk.readthedocs.io/en/master/link\_CppCMake\_docs.html The project is not used target\_include\_directories I am confuse about when to use the target\_include\_directories

---

## [build the library with modern cmake](https://discourse.cmake.org/t/build-the-library-with-modern-cmake/11735)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 0\
**Last updated:** [September 20, 2024, 4:36am UTC](https://discourse.cmake.org/t/build-the-library-with-modern-cmake/11735 "2024-09-20T04:36:27Z")

</div>

Is it a good method to build .dll or .lib for modern cmake?

---

## [find\_package in config mode doesn't seem to be appropriately ignoring CMAKE\_IGNORE\_PREFIX\_PATH](https://discourse.cmake.org/t/find-package-in-config-mode-doesnt-seem-to-be-appropriately-ignoring-cmake-ignore-prefix-path/11727)

<div class="topic-metadata">

**Author:** [@jcm](https://discourse.cmake.org/u/jcm)\
**Replies:** 0\
**Last updated:** [September 19, 2024, 6:08pm UTC](https://discourse.cmake.org/t/find-package-in-config-mode-doesnt-seem-to-be-appropriately-ignoring-cmake-ignore-prefix-path/11727 "2024-09-19T18:08:57Z")

</div>

Bit confused about the behavior of CMAKE\_IGNORE\_PREFIX\_PATH. I’m on macOS and trying to exclude homebrew for a particular package (or in general). I’ve added an ignore prefix like so: list(APPEND CMAKE\_IGNORE\_PREFIX\_PAT…

---

## [Adding a package version to my library](https://discourse.cmake.org/t/adding-a-package-version-to-my-library/11725)

<div class="topic-metadata">

**Author:** [@imikejackson](https://discourse.cmake.org/u/imikejackson)\
**Replies:** 3\
**Last updated:** [September 19, 2024, 4:45pm UTC](https://discourse.cmake.org/t/adding-a-package-version-to-my-library/11725 "2024-09-19T16:45:18Z")

</div>

I have a library that I have created using C++ and CMake: EbsdLib. I have everything working well and everything installs but I have noticed that I cannot retrieve the current version of the library through the normal CM…

---

## [How to generate .pc (pkg-config) file supporting --prefix of the cmake --install?](https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109)

<div class="topic-metadata">

**Author:** [@Adam\_Badura](https://discourse.cmake.org/u/Adam_Badura)\
**Replies:** 11\
**Last updated:** [September 18, 2024, 11:48am UTC](https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109 "2024-09-18T11:48:32Z")

</div>

The typical approach It seems to me that the common way of generating a .pc (pkg-config) file is to use configure\_file command. For example, something like this: configure\_file( ${CMAKE\_CURRENT\_SOURCE\_DIR}/share/pk…

---

## [How can I build cppm in cmake environment?](https://discourse.cmake.org/t/how-can-i-build-cppm-in-cmake-environment/11717)

<div class="topic-metadata">

**Author:** [@David\_Lee](https://discourse.cmake.org/u/David_Lee)\
**Replies:** 1\
**Last updated:** [September 18, 2024, 5:34am UTC](https://discourse.cmake.org/t/how-can-i-build-cppm-in-cmake-environment/11717 "2024-09-18T05:34:50Z")

</div>

The code is simple. ├── \*\*CMakeLists.txt\*\* ├── \*\*Hello.cppm\*\* ├── Hello.out ├── Hello.pcm ├── README.md ├── \*\*Use.cpp\*\* └── \*\*build\*\* Hello.cppm module; #include \<iostream\> export module Hello; export void hello() { …

---

## [profraw file generation is corrupted if command strings are given automatic](https://discourse.cmake.org/t/profraw-file-generation-is-corrupted-if-command-strings-are-given-automatic/11714)

<div class="topic-metadata">

**Author:** [@Selviniah](https://discourse.cmake.org/u/Selviniah)\
**Replies:** 0\
**Last updated:** [September 17, 2024, 11:56pm UTC](https://discourse.cmake.org/t/profraw-file-generation-is-corrupted-if-command-strings-are-given-automatic/11714 "2024-09-17T23:56:24Z")

</div>

I generating profaw file with compiler option. If I run the executable, the executable will generate every time profraw file. I wanted to automate this process This way it perfectly works for executing twice the execut…

---

## [Issue between CMake, MPI, macOS (XCode 16?) and gcc](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 9\
**Last updated:** [September 17, 2024, 7:25pm UTC](https://discourse.cmake.org/t/issue-between-cmake-mpi-macos-xcode-16-and-gcc/11711 "2024-09-17T19:25:29Z")

</div>

All, I don’t know if this is a CMake issue or not, but it seems to be? To wit, I have a boring MPI C Hello World code and it builds just fine using either gcc or clang on the command line. First gcc: ❯ mpicc --version …

---

## [Introducing file dependencies](https://discourse.cmake.org/t/introducing-file-dependencies/11695)

<div class="topic-metadata">

**Author:** [@artu72](https://discourse.cmake.org/u/artu72)\
**Replies:** 3\
**Last updated:** [September 17, 2024, 4:45pm UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695 "2024-09-17T16:45:34Z")

</div>

In my project, a source file depends upon a VERSION\_Q\_FILE, that depends in turn upon the VERSION\_FILE. I have tryed to write the rules using add\_dependencies command, but I cannot formulate them correctly. Any suggests? …

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

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