# Code

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

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

**Page:** 36

---

## [What's the best practice for a project that runs on ARM MCU while do unittest on PC?](https://discourse.cmake.org/t/whats-the-best-practice-for-a-project-that-runs-on-arm-mcu-while-do-unittest-on-pc/7913)

<div class="topic-metadata">

**Author:** [@cy18](https://discourse.cmake.org/u/cy18)\
**Replies:** 2\
**Last updated:** [April 16, 2023, 2:57am UTC](https://discourse.cmake.org/t/whats-the-best-practice-for-a-project-that-runs-on-arm-mcu-while-do-unittest-on-pc/7913 "2023-04-16T02:57:21Z")

</div>

I am currently working on a project that runs on an ARM Cortex-M4 MCU using the arm-none-eabi-gcc toolchain. However, the unit tests for this project are based on the regular gcc toolchain and run on a PC. Initially, I …

---

## [Clarification on PUBLIC/PRIVATE with target\_source\_group](https://discourse.cmake.org/t/clarification-on-public-private-with-target-source-group/7845)

<div class="topic-metadata">

**Author:** [@jasonaylward](https://discourse.cmake.org/u/jasonaylward)\
**Replies:** 4\
**Last updated:** [April 10, 2023, 1:11pm UTC](https://discourse.cmake.org/t/clarification-on-public-private-with-target-source-group/7845 "2023-04-10T13:11:47Z")

</div>

I’ve read over the documentation and a few threads on when and why use PRIVATE over PUBLIC when adding files to a target but I still don’t really get it. I see that I have a library XYZ and if I say target\_sources(XYZ …

---

## [Cmake not able to resolve external static library symbols](https://discourse.cmake.org/t/cmake-not-able-to-resolve-external-static-library-symbols/4545)

<div class="topic-metadata">

**Author:** [@rbirari](https://discourse.cmake.org/u/rbirari)\
**Replies:** 1\
**Last updated:** [April 7, 2023, 2:38am UTC](https://discourse.cmake.org/t/cmake-not-able-to-resolve-external-static-library-symbols/4545 "2023-04-07T02:38:37Z")

</div>

I am using CMake to build TI C2000 project where I am importing 3 TI libraries libc.a, driverlib.lib and driverlib\_coff.lib. These libraries are added by importing them as shown in below. Moreover, I am able to build 3…

---

## [Best practices for a clean Xcode project](https://discourse.cmake.org/t/best-practices-for-a-clean-xcode-project/7836)

<div class="topic-metadata">

**Author:** [@jasonaylward](https://discourse.cmake.org/u/jasonaylward)\
**Replies:** 1\
**Last updated:** [April 7, 2023, 12:00am UTC](https://discourse.cmake.org/t/best-practices-for-a-clean-xcode-project/7836 "2023-04-07T00:00:25Z")

</div>

Hi, I’m working on building out a CMake configuration from a C++ library that was originally built as an Xcode project. I’m trying to compare the original project with the Xcode project that CMake generates to be sure t…

---

## [Race condition for -E create\_symlink duplicate calls](https://discourse.cmake.org/t/race-condition-for-e-create-symlink-duplicate-calls/7827)

<div class="topic-metadata">

**Author:** [@dwarwick](https://discourse.cmake.org/u/dwarwick)\
**Replies:** 6\
**Last updated:** [April 5, 2023, 9:53pm UTC](https://discourse.cmake.org/t/race-condition-for-e-create-symlink-duplicate-calls/7827 "2023-04-05T21:53:53Z")

</div>

CMake will happily write over the same symlink. If we have two targets, Target1 and Target2, which are in the same CMakeLists.txt (and therefore the same binary dir) add\_custom\_command( TARGET Target1 COMMAND ${CMAK…

---

## [How do I know when I can read the CMakeCache.txt](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811)

<div class="topic-metadata">

**Author:** [@eriols](https://discourse.cmake.org/u/eriols)\
**Replies:** 2\
**Last updated:** [April 3, 2023, 1:11pm UTC](https://discourse.cmake.org/t/how-do-i-know-when-i-can-read-the-cmakecache-txt/7811 "2023-04-03T13:11:46Z")

</div>

If I within cmake want to know when the CMakeCache file from the configure step is ready to be read, what would be a good way to do this? I was looking at using cmake\_language DEFER DIRECTORY ${CMAKE\_SOURCE\_DIR} CALL my…

---

## [Remove items from CMAKE\_EXE\_LINKER\_FLAGS\_INIT](https://discourse.cmake.org/t/remove-items-from-cmake-exe-linker-flags-init/7785)

<div class="topic-metadata">

**Author:** [@ingolf](https://discourse.cmake.org/u/ingolf)\
**Replies:** 1\
**Last updated:** [April 3, 2023, 11:34am UTC](https://discourse.cmake.org/t/remove-items-from-cmake-exe-linker-flags-init/7785 "2023-04-03T11:34:30Z")

</div>

Hi, how can I remove certain link options of a specific executable which initially came from CMAKE\_EXE\_LINKER\_FLAGS\_INIT? For instance, the CMake configuration for the Android platform defines CMAKE\_EXE\_LINKER\_FLAGS\_IN…

---

## [Trouble Linking Against Netgen](https://discourse.cmake.org/t/trouble-linking-against-netgen/7695)

<div class="topic-metadata">

**Author:** [@npss](https://discourse.cmake.org/u/npss)\
**Replies:** 1\
**Last updated:** [April 3, 2023, 11:16am UTC](https://discourse.cmake.org/t/trouble-linking-against-netgen/7695 "2023-04-03T11:16:11Z")

</div>

Hello, I am attempting to compile netgen’s nglib (GitHub - NGSolve/netgen) with OCCT for usage as a shared library on Windows. I want to be able to mesh a STEP file from within an occt based application using netgen. I …

---

## [How to build with OpenCM3 + FreeRTOS + CMake to ARM CM4?](https://discourse.cmake.org/t/how-to-build-with-opencm3-freertos-cmake-to-arm-cm4/4532)

<div class="topic-metadata">

**Author:** [@jalexfranca](https://discourse.cmake.org/u/jalexfranca)\
**Replies:** 3\
**Last updated:** [March 26, 2023, 3:06pm UTC](https://discourse.cmake.org/t/how-to-build-with-opencm3-freertos-cmake-to-arm-cm4/4532 "2023-03-26T15:06:19Z")

</div>

I am trying to program an ARM STM32F407 on an STM32F4Discovery board. First, I built a project with OpenCM3 + CMakeLists.txt. It worked! The LED flashed. :wink: Now, I’m trying to make the same project with OpenCM3 + Fre…

---

## [cmake for torchtext](https://discourse.cmake.org/t/cmake-for-torchtext/7770)

<div class="topic-metadata">

**Author:** [@Toocic](https://discourse.cmake.org/u/Toocic)\
**Replies:** 0\
**Last updated:** [March 26, 2023, 11:25am UTC](https://discourse.cmake.org/t/cmake-for-torchtext/7770 "2023-03-26T11:25:20Z")

</div>

How to install torchtext in cmake project on windows 10? Error CMake Error at X:\\Programming\\C++\\Tests\\TestPyTorch1\\CMakeLists.txt:11 (find\_package): By not providing “FindTorchText.cmake” in CMAKE\_MODULE\_PATH this pr…

---

## [Get a CMake macro to use in a condition](https://discourse.cmake.org/t/get-a-cmake-macro-to-use-in-a-condition/7761)

<div class="topic-metadata">

**Author:** [@Dr-Itachi](https://discourse.cmake.org/u/Dr-Itachi)\
**Replies:** 11\
**Last updated:** [March 25, 2023, 4:36pm UTC](https://discourse.cmake.org/t/get-a-cmake-macro-to-use-in-a-condition/7761 "2023-03-25T16:36:26Z")

</div>

Hi. I would like to make a choice between 2 files to pass to the compiler options according to a macro defined in compile\_definitions of CMake. How to get this macro in a variable for example and test it please?

---

## [FindPackage in config mode.](https://discourse.cmake.org/t/findpackage-in-config-mode/7766)

<div class="topic-metadata">

**Author:** [@Ramesh\_Santhanam1](https://discourse.cmake.org/u/Ramesh_Santhanam1)\
**Replies:** 5\
**Last updated:** [March 25, 2023, 9:03am UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766 "2023-03-25T09:03:32Z")

</div>

Greetings I would like alter the search paths when doing Find Package in config mode. Is that possible? Thanks Ramesh

---

## [Create CMakeLists for my application ( the application is already working on Visual Studio )](https://discourse.cmake.org/t/create-cmakelists-for-my-application-the-application-is-already-working-on-visual-studio/7764)

<div class="topic-metadata">

**Author:** [@Zaoui\_Douaa](https://discourse.cmake.org/u/Zaoui_Douaa)\
**Replies:** 1\
**Last updated:** [March 24, 2023, 11:23pm UTC](https://discourse.cmake.org/t/create-cmakelists-for-my-application-the-application-is-already-working-on-visual-studio/7764 "2023-03-24T23:23:18Z")

</div>

\#Minimum version to use cmake\_minimum\_required(VERSION 3.12) # using c++11 set(CMAKE\_CXX\_STANDARD 11) # Répertoire de sortie pour les bibliothèques et les archives en mode Release set(CMAKE\_ARCHIVE\_OUTPUT\_DIRECTORY\_RELEA…

---

## [Creating an .ipa from .app for iOS using CMake](https://discourse.cmake.org/t/creating-an-ipa-from-app-for-ios-using-cmake/5942)

<div class="topic-metadata">

**Author:** [@Karan\_Dixit](https://discourse.cmake.org/u/Karan_Dixit)\
**Replies:** 7\
**Last updated:** [March 22, 2023, 2:19pm UTC](https://discourse.cmake.org/t/creating-an-ipa-from-app-for-ios-using-cmake/5942 "2023-03-22T14:19:05Z")

</div>

We are building an application that would be cross-platform and hence using CMake as the build system.While building for iOS/iPadOS/tvOS etc, when add\_executable is done with MACOSX\_BUNDLE, CMake generates a .app. Is the…

---

## [shm\_open shm\_unlink not found](https://discourse.cmake.org/t/shm-open-shm-unlink-not-found/7749)

<div class="topic-metadata">

**Author:** [@a\_lex12](https://discourse.cmake.org/u/a_lex12)\
**Replies:** 7\
**Last updated:** [March 22, 2023, 1:41pm UTC](https://discourse.cmake.org/t/shm-open-shm-unlink-not-found/7749 "2023-03-22T13:41:22Z")

</div>

I am new to CMake and trying to build a project for aarch64 armv8 from Termux on my android phone. I am running into this error: gcc -o ex main.c -lc main.c:19:10: warning: call to undeclared function ‘shm\_open’; ISO C…

---

## [Can you obtain the entire compiler/Linker command line?](https://discourse.cmake.org/t/can-you-obtain-the-entire-compiler-linker-command-line/7728)

<div class="topic-metadata">

**Author:** [@mfarver](https://discourse.cmake.org/u/mfarver)\
**Replies:** 2\
**Last updated:** [March 22, 2023, 12:56pm UTC](https://discourse.cmake.org/t/can-you-obtain-the-entire-compiler-linker-command-line/7728 "2023-03-22T12:56:52Z")

</div>

To append a CRC to my microcontroller application I need to run the linker twice. I have it doing all the build steps and calculating the CRC from the artifacts, but I’m struggling with how to run the linker a second t…

---

## [A @ variable reference on a line by itself, what does it mean and where can @ variable references occur?](https://discourse.cmake.org/t/a-variable-reference-on-a-line-by-itself-what-does-it-mean-and-where-can-variable-references-occur/7734)

<div class="topic-metadata">

**Author:** [@EricGT](https://discourse.cmake.org/u/EricGT)\
**Replies:** 4\
**Last updated:** [March 22, 2023, 12:17pm UTC](https://discourse.cmake.org/t/a-variable-reference-on-a-line-by-itself-what-does-it-mean-and-where-can-variable-references-occur/7734 "2023-03-22T12:17:29Z")

</div>

Creating a parser for CMake files and used the CMake files from the CMake GitHub repository for testing. In run\_nvcc.cmake this line failed @CUDA\_HOST\_FLAGS@ The syntax page from the web documentation does not note …

---

## [CMake files before prepocessing, details needed.](https://discourse.cmake.org/t/cmake-files-before-prepocessing-details-needed/7735)

<div class="topic-metadata">

**Author:** [@EricGT](https://discourse.cmake.org/u/EricGT)\
**Replies:** 1\
**Last updated:** [March 21, 2023, 2:25pm UTC](https://discourse.cmake.org/t/cmake-files-before-prepocessing-details-needed/7735 "2023-03-21T14:25:07Z")

</div>

In creating a CMake parser for various reasons am finding that the syntax for CMake file only applies after substitution of the variables occurs. With other programming languages such as C there is a C preprocessor with …

---

## [Install static library while preserving extended attributes on macOS](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694)

<div class="topic-metadata">

**Author:** [@jviotti](https://discourse.cmake.org/u/jviotti)\
**Replies:** 3\
**Last updated:** [March 17, 2023, 5:00pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694 "2023-03-17T17:00:06Z")

</div>

I have a project that generates static libraries, which need to be code-signed, as the package including them needs to get notarized. I have a set of custom targets that correctly sign the static libraries, and that wor…

---

## [GeneratorExpression: \`TARGET\_FILE\` for \`add\_custom\_target\`](https://discourse.cmake.org/t/generatorexpression-target-file-for-add-custom-target/7690)

<div class="topic-metadata">

**Author:** [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Replies:** 3\
**Last updated:** [March 16, 2023, 6:41pm UTC](https://discourse.cmake.org/t/generatorexpression-target-file-for-add-custom-target/7690 "2023-03-16T18:41:00Z")

</div>

Assuming add\_custom\_taget generates only 1 file, it would be sometimes useful to expose what is the name/location of that file, e.g.: add\_custom\_target(CustomTarget COMMAND compute\_version.sh COMMAND ${CMAKE\_COMMAND} …

---

## [dSYM file not copied when archiving](https://discourse.cmake.org/t/dsym-file-not-copied-when-archiving/7691)

<div class="topic-metadata">

**Author:** [@m\_g](https://discourse.cmake.org/u/m_g)\
**Replies:** 1\
**Last updated:** [March 16, 2023, 5:52pm UTC](https://discourse.cmake.org/t/dsym-file-not-copied-when-archiving/7691 "2023-03-16T17:52:59Z")

</div>

Hi, I use CMake to generate iOS/macOS Xcode projects for an app. When archiving to upload beta builds to TestFlight, the dSYMsdirectory in the .xcarchive is simply empty. The dSYM file is properly generated but it see…

---

## [CMake modules Documentation and Doxygen/breathe tutorial/docs](https://discourse.cmake.org/t/cmake-modules-documentation-and-doxygen-breathe-tutorial-docs/6471)

<div class="topic-metadata">

**Author:** [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Replies:** 2\
**Last updated:** [March 16, 2023, 9:51am UTC](https://discourse.cmake.org/t/cmake-modules-documentation-and-doxygen-breathe-tutorial-docs/6471 "2023-03-16T09:51:40Z")

</div>

Hello, it would be great if there will be any docs about proper CMake modules docs (pun not intended). E.g., how is better to document the Doxygen-like thinks like @brief, @param, @returns, @example, etc and how it int…

---

## [adding libmodbus to CMakeLists.text file](https://discourse.cmake.org/t/adding-libmodbus-to-cmakelists-text-file/7681)

<div class="topic-metadata">

**Author:** [@Bob\_Thomas](https://discourse.cmake.org/u/Bob_Thomas)\
**Replies:** 0\
**Last updated:** [March 15, 2023, 5:30am UTC](https://discourse.cmake.org/t/adding-libmodbus-to-cmakelists-text-file/7681 "2023-03-15T05:30:08Z")

</div>

Hello, I am working on a C++ application that will run on Ubuntu 22.04. I am using Jetbrain’s C/C++ IDE called “CLion”. My application is working fine and now I wish to incorporate libmodbus into it. However, I don’t kn…

---

## [Control what is installed / packaged](https://discourse.cmake.org/t/control-what-is-installed-packaged/3778)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 8\
**Last updated:** [March 15, 2023, 4:32am UTC](https://discourse.cmake.org/t/control-what-is-installed-packaged/3778 "2023-03-15T04:32:10Z")

</div>

Hello, I’ve writtem some install logic and cpack logic for my application. It generally works, but it literally installs everything. I use FetchContent whenever possible so all my dependencies are subdirectories. If I …

---

## [combine cmakelist](https://discourse.cmake.org/t/combine-cmakelist/7624)

<div class="topic-metadata">

**Author:** [@fawad](https://discourse.cmake.org/u/fawad)\
**Replies:** 1\
**Last updated:** [March 15, 2023, 1:07am UTC](https://discourse.cmake.org/t/combine-cmakelist/7624 "2023-03-15T01:07:24Z")

</div>

I have a root directroy with a list of projects in subfolder and a cmakelist.txt file with some code, then in the subfolder their are more folders and a cmakelist.txt, then in the subfolder i have a project file and its …

---

## [makefile problem](https://discourse.cmake.org/t/makefile-problem/7677)

<div class="topic-metadata">

**Author:** [@Mnasri\_Jassem](https://discourse.cmake.org/u/Mnasri_Jassem)\
**Replies:** 0\
**Last updated:** [March 14, 2023, 1:19pm UTC](https://discourse.cmake.org/t/makefile-problem/7677 "2023-03-14T13:19:03Z")

</div>

hello comm i have created a cmakelist for a keil project , the makefile generation was done successfully , but while adding the make command it appears this error ( In file included from /home/jassem/Downloads/frimware…

---

## [Generator Expressions in \<LANG\>\_CPPCHECK Property or CMAKE\_\<LANG\>\_CPPCHECK Variable](https://discourse.cmake.org/t/generator-expressions-in-lang-cppcheck-property-or-cmake-lang-cppcheck-variable/7670)

<div class="topic-metadata">

**Author:** [@stenny.schober](https://discourse.cmake.org/u/stenny.schober)\
**Replies:** 2\
**Last updated:** [March 13, 2023, 7:31pm UTC](https://discourse.cmake.org/t/generator-expressions-in-lang-cppcheck-property-or-cmake-lang-cppcheck-variable/7670 "2023-03-13T19:31:20Z")

</div>

is it possible to use generator expressions like $\<TARGET\_PROPERTY:COMPILE\_DEFINITIONS\> or $\<TARGET\_PROPERTY:INCLUDE\_DIRECTORIES\> in the definition of the \<LANG\>\_CPPCHECK or similar target properties? If yes, would it al…

---

## [Duplicated Targets](https://discourse.cmake.org/t/duplicated-targets/7666)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 1\
**Last updated:** [March 13, 2023, 7:22pm UTC](https://discourse.cmake.org/t/duplicated-targets/7666 "2023-03-13T19:22:55Z")

</div>

Hi, I have the problem that in two projects I use with FetchContent that a duplicated uninstall target exists. I cannot really control these projects. Even fixing it somehow it not quite realistic as it wouldn’t be back…

---

## [What thumps a path into a shared library?](https://discourse.cmake.org/t/what-thumps-a-path-into-a-shared-library/7643)

<div class="topic-metadata">

**Author:** [@anon74639460](https://discourse.cmake.org/u/anon74639460)\
**Replies:** 2\
**Last updated:** [March 12, 2023, 7:13pm UTC](https://discourse.cmake.org/t/what-thumps-a-path-into-a-shared-library/7643 "2023-03-12T19:13:55Z")

</div>

This ought to be stupid simple but I’m slamming my head against the wall to find it. Fork of CopperSpice project with RPM branch so I can package the library in RPM form now that I have Debian working. I tried to be the…

---

## [flag to force windows to build as x64 instead of x86?](https://discourse.cmake.org/t/flag-to-force-windows-to-build-as-x64-instead-of-x86/7648)

<div class="topic-metadata">

**Author:** [@jsoneaday](https://discourse.cmake.org/u/jsoneaday)\
**Replies:** 3\
**Last updated:** [March 11, 2023, 1:13am UTC](https://discourse.cmake.org/t/flag-to-force-windows-to-build-as-x64-instead-of-x86/7648 "2023-03-11T01:13:02Z")

</div>

Hello I have a x64 windows machine with visual studio 2022 and when I try and compile c++ code it runs the build as x86. Is there some flag to force x64 build?

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

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