# Code

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

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

**Page:** 34

---

## [Difference between prefixed EXPORT\_NAME and NAMESPACE?](https://discourse.cmake.org/t/difference-between-prefixed-export-name-and-namespace/8251)

<div class="topic-metadata">

**Author:** [@SoilRos](https://discourse.cmake.org/u/SoilRos)\
**Replies:** 5\
**Last updated:** [June 7, 2023, 3:00pm UTC](https://discourse.cmake.org/t/difference-between-prefixed-export-name-and-namespace/8251 "2023-06-07T15:00:07Z")

</div>

What is the difference between setting scope of an exported target directly the EXPORT\_NAME vs setting the scope of an exported target with NAMESPACE? For example, let’s say I have a target named proj\_target which I wan…

---

## [Skipping an useless argument when invoking a command](https://discourse.cmake.org/t/skipping-an-useless-argument-when-invoking-a-command/8258)

<div class="topic-metadata">

**Author:** [@cher-nov](https://discourse.cmake.org/u/cher-nov)\
**Replies:** 3\
**Last updated:** [June 7, 2023, 2:47pm UTC](https://discourse.cmake.org/t/skipping-an-useless-argument-when-invoking-a-command/8258 "2023-06-07T14:47:34Z")

</div>

I want to call string(REGEX MATCH without the \<output\_variable\> argument, because I don’t need it in this particular case since I want to use CMAKE\_MATCH\_\<n\> variables instead. So my invocation line looks something like …

---

## [\`COMPILE\_DEFINITIONS\` with generator expression: "$\<${gcc\_like}:-Werror\>" "$\<${msvc}:-WX\>"](https://discourse.cmake.org/t/compile-definitions-with-generator-expression-gcc-like-werror-msvc-wx/8254)

<div class="topic-metadata">

**Author:** [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)\
**Replies:** 5\
**Last updated:** [June 7, 2023, 1:13pm UTC](https://discourse.cmake.org/t/compile-definitions-with-generator-expression-gcc-like-werror-msvc-wx/8254 "2023-06-07T13:13:13Z")

</div>

Attempts: set(gcc\_like "$\<COMPILE\_LANG\_AND\_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC\>") set(msvc "$\<COMPILE\_LANG\_AND\_ID:C,CXX,MSVC\>") try\_compile( FALL\_THROUGH\_SUPPORTED ${CMAKE\_BINARY\_DIR} SOU…

---

## [Option default value bug](https://discourse.cmake.org/t/option-default-value-bug/8270)

<div class="topic-metadata">

**Author:** [@Mapniv](https://discourse.cmake.org/u/Mapniv)\
**Replies:** 1\
**Last updated:** [June 6, 2023, 7:45pm UTC](https://discourse.cmake.org/t/option-default-value-bug/8270 "2023-06-06T19:45:29Z")

</div>

Hello, I think I found a bug in cmake. I was redirected here to find out if it is really a bug. Code: cmake\_minimum\_required(VERSION 3.10) project(test VERSION 0.0.0) option(BITS "Bits" 64) message(STATUS ${BITS}) Fi…

---

## [Minimal P/Invoke + net5.0 example ?](https://discourse.cmake.org/t/minimal-p-invoke-net5-0-example/7937)

<div class="topic-metadata">

**Author:** [@malaterre](https://discourse.cmake.org/u/malaterre)\
**Replies:** 5\
**Last updated:** [June 4, 2023, 3:24am UTC](https://discourse.cmake.org/t/minimal-p-invoke-net5-0-example/7937 "2023-06-04T03:24:44Z")

</div>

Hi there, I am trying to get a minimal P/Invoke project working under Visual Studio 2019 with cmake 3.26.3. Here is what my code looks like: $ touch foo.cs $ touch bar.cxx then: cmake\_minimum\_required(VERSION 3.26) pr…

---

## [linker cannot find openmp library on msys system](https://discourse.cmake.org/t/linker-cannot-find-openmp-library-on-msys-system/8167)

<div class="topic-metadata">

**Author:** [@bradbell](https://discourse.cmake.org/u/bradbell)\
**Replies:** 1\
**Last updated:** [June 2, 2023, 8:08pm UTC](https://discourse.cmake.org/t/linker-cannot-find-openmp-library-on-msys-system/8167 "2023-06-02T20:08:22Z")

</div>

I am using FIND\_PACKAGE(OpenMP) on mysy2 and then linking the necessary libraries using TARGET\_LINK\_LIBRARIES( target\_name ... ${OpenMP\_CXX\_LIBRARIES} ) This works find on most systems, but on msys2 I get the following…

---

## [Investigating /MP with MSVC](https://discourse.cmake.org/t/investigating-mp-with-msvc/8247)

<div class="topic-metadata">

**Author:** [@imrichardcole](https://discourse.cmake.org/u/imrichardcole)\
**Replies:** 1\
**Last updated:** [June 2, 2023, 12:28pm UTC](https://discourse.cmake.org/t/investigating-mp-with-msvc/8247 "2023-06-02T12:28:13Z")

</div>

Digging into the above, I noticed this file CMake/CompileFlags.cmake at master · Kitware/CMake · GitHub. Which at the very bottom has mention of /MP and how it’s controlled. What is the purpose of this file? Whilst it…

---

## [Code Signing macOs application](https://discourse.cmake.org/t/code-signing-macos-application/7275)

<div class="topic-metadata">

**Author:** [@tonygo](https://discourse.cmake.org/u/tonygo)\
**Replies:** 13\
**Last updated:** [June 2, 2023, 11:08am UTC](https://discourse.cmake.org/t/code-signing-macos-application/7275 "2023-06-02T11:08:37Z")

</div>

Hi :wave: I’m trying to code sign a macOs application through CMake with a certificate. I followed the approach mentioned in the book of @craig.scott, using -DCMAKE\_XCODE\_ATTRIBUTE\_DEVELOPMENT\_TEAM and -DCMAKE\_XCODE\_AT…

---

## [CMAKE\_STRIP arguments?](https://discourse.cmake.org/t/cmake-strip-arguments/6930)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 19\
**Last updated:** [June 2, 2023, 7:32am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930 "2023-06-02T07:32:27Z")

</div>

Is there a way to pass arguments to cmake strip (invoked via ninja install/strip)? Is appending them to CMAKE\_STRIP the correct approach? Can’t really find the docs to cmake stripping.

---

## [Executable not found for macos/clang/M1-arm64 but yes for macos/clang/x86\_64](https://discourse.cmake.org/t/executable-not-found-for-macos-clang-m1-arm64-but-yes-for-macos-clang-x86-64/8235)

<div class="topic-metadata">

**Author:** [@rturrado](https://discourse.cmake.org/u/rturrado)\
**Replies:** 5\
**Last updated:** [June 1, 2023, 11:11am UTC](https://discourse.cmake.org/t/executable-not-found-for-macos-clang-m1-arm64-but-yes-for-macos-clang-x86-64/8235 "2023-06-01T11:11:06Z")

</div>

Hi all, I’m adding a package to Conan Center. It builds correctly for macos/clang/x86\_64, but fails for macos/clang/M1-arm64. The error comes from this piece of code: cmake\_minimum\_required(VERSION 3.12 FATAL\_ERROR) a…

---

## [When running multiple cmake concurrently, "if (EXISTS xxx)" may be false while the file/folder exists.](https://discourse.cmake.org/t/when-running-multiple-cmake-concurrently-if-exists-xxx-may-be-false-while-the-file-folder-exists/8234)

<div class="topic-metadata">

**Author:** [@cy18](https://discourse.cmake.org/u/cy18)\
**Replies:** 6\
**Last updated:** [June 1, 2023, 1:52am UTC](https://discourse.cmake.org/t/when-running-multiple-cmake-concurrently-if-exists-xxx-may-be-false-while-the-file-folder-exists/8234 "2023-06-01T01:52:02Z")

</div>

My project have about 50 different targets with different configurations. I write a makefile to invoke multiple cmake to build all targets concurrently. With “make -j32 all”, I can make best use of my 16 core/32 threads …

---

## [Installation behavior of shared versus static libraries](https://discourse.cmake.org/t/installation-behavior-of-shared-versus-static-libraries/8236)

<div class="topic-metadata">

**Author:** [@neuroevolutus](https://discourse.cmake.org/u/neuroevolutus)\
**Replies:** 2\
**Last updated:** [June 1, 2023, 1:29am UTC](https://discourse.cmake.org/t/installation-behavior-of-shared-versus-static-libraries/8236 "2023-06-01T01:29:08Z")

</div>

▶ Context Question I am wondering why making a shared library would cause it to install once and show as up-to-date on subsequent invocations of cmake --install whereas using the default library type (which is ostensibly S…

---

## [FetchContent issue with find\_package and dependency chains](https://discourse.cmake.org/t/fetchcontent-issue-with-find-package-and-dependency-chains/8061)

<div class="topic-metadata">

**Author:** [@yah-nosh](https://discourse.cmake.org/u/yah-nosh)\
**Replies:** 2\
**Last updated:** [May 31, 2023, 6:25pm UTC](https://discourse.cmake.org/t/fetchcontent-issue-with-find-package-and-dependency-chains/8061 "2023-05-31T18:25:20Z")

</div>

Hi all, I’m working on a C++ project using CMake, where I manage all my third-party dependencies using FetchContent exclusively (i.e no other package manager is installed nor run). I use a combination of FetchContent\_D…

---

## [debug - step-into a library function](https://discourse.cmake.org/t/debug-step-into-a-library-function/8193)

<div class="topic-metadata">

**Author:** [@ygratz](https://discourse.cmake.org/u/ygratz)\
**Replies:** 2\
**Last updated:** [May 31, 2023, 5:53pm UTC](https://discourse.cmake.org/t/debug-step-into-a-library-function/8193 "2023-05-31T17:53:11Z")

</div>

Hi, I downloaded an open-source project (c++ project). It includes a library which has its own CMakeLists.txt. It also includes an example, with a main() and its own CMakeLists.txt. It includes: find\_package() targe…

---

## [Link only directly dependent SHARED libraries](https://discourse.cmake.org/t/link-only-directly-dependent-shared-libraries/8231)

<div class="topic-metadata">

**Author:** [@chapuni](https://discourse.cmake.org/u/chapuni)\
**Replies:** 3\
**Last updated:** [May 31, 2023, 1:29pm UTC](https://discourse.cmake.org/t/link-only-directly-dependent-shared-libraries/8231 "2023-05-31T13:29:34Z")

</div>

I would like; Properties for compilation shall be propagated transitively. (eg. target\_include\_directories(PUBLIC/INTERFACE) Libraries shall be specified as add\_library(SHARED). The linker shall use directly specified…

---

## [creating a macro that dynamically updates a custom target](https://discourse.cmake.org/t/creating-a-macro-that-dynamically-updates-a-custom-target/8067)

<div class="topic-metadata">

**Author:** [@Brian](https://discourse.cmake.org/u/Brian)\
**Replies:** 3\
**Last updated:** [May 29, 2023, 1:56pm UTC](https://discourse.cmake.org/t/creating-a-macro-that-dynamically-updates-a-custom-target/8067 "2023-05-29T13:56:23Z")

</div>

Hi All, I’m trying to write a macro that creates a custom target using the source and headers from other targets. from the build folder I would like to run for example cmake .. cmake --build . --target clang-format-dr…

---

## [Runtime Resource Copying with CMake as of 3.24](https://discourse.cmake.org/t/runtime-resource-copying-with-cmake-as-of-3-24/8205)

<div class="topic-metadata">

**Author:** [@kfsone](https://discourse.cmake.org/u/kfsone)\
**Replies:** 1\
**Last updated:** [May 29, 2023, 1:03pm UTC](https://discourse.cmake.org/t/runtime-resource-copying-with-cmake-as-of-3-24/8205 "2023-05-29T13:03:37Z")

</div>

(Runtime resources: dlls, dylibs, sos, etc, that need to be placed alongside executables to run) I’ve been trying to answer my own question since early Monday, so at this juncture I’m explicitly ignoring the plethora of…

---

## [Windows DLL with ALL symbols of dependent static libs](https://discourse.cmake.org/t/windows-dll-with-all-symbols-of-dependent-static-libs/8185)

<div class="topic-metadata">

**Author:** [@robiwano](https://discourse.cmake.org/u/robiwano)\
**Replies:** 3\
**Last updated:** [May 29, 2023, 1:01pm UTC](https://discourse.cmake.org/t/windows-dll-with-all-symbols-of-dependent-static-libs/8185 "2023-05-29T13:01:43Z")

</div>

I want to assemble a Windows DLL which depends on a plethora of internal and third-party static libraries to export ALL symbols of ALL libraries, but it seems nigh to impossible. I’ve tried target\_link\_libraries with WHO…

---

## [Ceres Build fails with: recipe for target 'internal/ceres/CMakeFiles/ceres\_internal.dir/cuda\_vector.cc.o' failed](https://discourse.cmake.org/t/ceres-build-fails-with-recipe-for-target-internal-ceres-cmakefiles-ceres-internal-dir-cuda-vector-cc-o-failed/8160)

<div class="topic-metadata">

**Author:** [@Nitin\_Bansal](https://discourse.cmake.org/u/Nitin_Bansal)\
**Replies:** 1\
**Last updated:** [May 29, 2023, 12:38pm UTC](https://discourse.cmake.org/t/ceres-build-fails-with-recipe-for-target-internal-ceres-cmakefiles-ceres-internal-dir-cuda-vector-cc-o-failed/8160 "2023-05-29T12:38:21Z")

</div>

Hello, I am looking to install ceres solver in a docker environment, using the following command: # Install Ceres Solver RUN git clone https://ceres-solver.googlesource.com/ceres-solver RUN mkdir -p ceres-solver/build W…

---

## [ARCHIVE\_OUTPU\_DIRECTORY Overwrite failure](https://discourse.cmake.org/t/archive-outpu-directory-overwrite-failure/8210)

<div class="topic-metadata">

**Author:** [@aidexie](https://discourse.cmake.org/u/aidexie)\
**Replies:** 2\
**Last updated:** [May 26, 2023, 1:06am UTC](https://discourse.cmake.org/t/archive-outpu-directory-overwrite-failure/8210 "2023-05-26T01:06:22Z")

</div>

I would like the library output directory of a module to be customisable, and I have previously customised the global library output directory. When I used the following approach I found that it did not work. set(CMAKE\_…

---

## [Namespaced function names in CMake](https://discourse.cmake.org/t/namespaced-function-names-in-cmake/8187)

<div class="topic-metadata">

**Author:** [@Barry\_Revzin](https://discourse.cmake.org/u/Barry_Revzin)\
**Replies:** 2\
**Last updated:** [May 23, 2023, 10:22pm UTC](https://discourse.cmake.org/t/namespaced-function-names-in-cmake/8187 "2023-05-23T22:22:21Z")

</div>

I can declare a qualified function: function(my::func) message(STATUS "Hi!") endfunction() And I can call it qualified… this way, which works as expected: cmake\_language(CALL my::func) but not this way my::func(…

---

## [Cmake Tutorial Issue](https://discourse.cmake.org/t/cmake-tutorial-issue/7791)

<div class="topic-metadata">

**Author:** [@James\_Waldron](https://discourse.cmake.org/u/James_Waldron)\
**Replies:** 2\
**Last updated:** [May 23, 2023, 7:27am UTC](https://discourse.cmake.org/t/cmake-tutorial-issue/7791 "2023-05-23T07:27:35Z")

</div>

I have tried searching for a solution, but I haven’t been able to find a solution that prevents the error form occurring while using the code that should build fine. This specifically pertains to Exercise 1 of Step 2 in …

---

## [GHS Language Standard not getting picked up](https://discourse.cmake.org/t/ghs-language-standard-not-getting-picked-up/8169)

<div class="topic-metadata">

**Author:** [@Speqtre](https://discourse.cmake.org/u/Speqtre)\
**Replies:** 1\
**Last updated:** [May 19, 2023, 11:35pm UTC](https://discourse.cmake.org/t/ghs-language-standard-not-getting-picked-up/8169 "2023-05-19T23:35:00Z")

</div>

My GHS MULTI project builds and compiles fine in GHS. I’m able to setup my cmake project without errors using: cmake -G “Green Hills MULTI” -A arm64 -T c:\\ghs\\comp\_202214 -D GHS\_OS\_DIR=…/int1179teledyne -D GHS\_BSP\_NAM…

---

## [Missing imported target](https://discourse.cmake.org/t/missing-imported-target/8163)

<div class="topic-metadata">

**Author:** [@robiwano](https://discourse.cmake.org/u/robiwano)\
**Replies:** 1\
**Last updated:** [May 19, 2023, 10:16am UTC](https://discourse.cmake.org/t/missing-imported-target/8163 "2023-05-19T10:16:33Z")

</div>

I have a folder structure like so: /build /src /import where /import contains /include and /lib folder for an imported target. /import also has a CMakeLists.txt file with following content: add\_library(my\_import\_tar…

---

## [; is parsed as %3B](https://discourse.cmake.org/t/is-parsed-as-3b/8155)

<div class="topic-metadata">

**Author:** [@aidexie](https://discourse.cmake.org/u/aidexie)\
**Replies:** 1\
**Last updated:** [May 18, 2023, 12:15pm UTC](https://discourse.cmake.org/t/is-parsed-as-3b/8155 "2023-05-18T12:15:01Z")

</div>

I need to set the link attribute “force symbol refenece” in vs, and I need to set more than one. I found a solution on the internet. set\_target\_properties(target PROPERTIES LINK\_FLAGS “/INCLUDE:TEST1;TEST2”) But in vs …

---

## [Why CMAKE\_CXX\_COMPILER\_ID is overwritten when using colcon?](https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151)

<div class="topic-metadata">

**Author:** [@theateist](https://discourse.cmake.org/u/theateist)\
**Replies:** 1\
**Last updated:** [May 18, 2023, 12:08pm UTC](https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151 "2023-05-18T12:08:03Z")

</div>

I’m building a workspace with colcon build on Windows 10 and it’s aborted with the following message: CMake Warning at C:/colcon\_ws/install/ros\_industrial\_cmake\_boilerplate/lib/cmake/ros\_industrial\_cmake\_boilerplate/cma…

---

## [CMake + CPack "Unspecified" component](https://discourse.cmake.org/t/cmake-cpack-unspecified-component/8143)

<div class="topic-metadata">

**Author:** [@antoniovazquezblanco](https://discourse.cmake.org/u/antoniovazquezblanco)\
**Replies:** 2\
**Last updated:** [May 17, 2023, 6:34pm UTC](https://discourse.cmake.org/t/cmake-cpack-unspecified-component/8143 "2023-05-17T18:34:00Z")

</div>

Hi everyone! I am trying to contribute to a friends project with a nice packing and distribution system. The code I wrote can be found in my fork: Particularly, I want to split DEB packaging into two versions, a lib …

---

## [Cannot set property of a test in a subdirectory](https://discourse.cmake.org/t/cannot-set-property-of-a-test-in-a-subdirectory/4337)

<div class="topic-metadata">

**Author:** [@pmqs](https://discourse.cmake.org/u/pmqs)\
**Replies:** 10\
**Last updated:** [May 17, 2023, 5:13pm UTC](https://discourse.cmake.org/t/cannot-set-property-of-a-test-in-a-subdirectory/4337 "2023-05-17T17:13:09Z")

</div>

I’m having trouble setting properties on all tests in a directory tree. Here is a dummy project that illustrates the issue cmake\_minimum\_required(VERSION 3.17) project(Hello\_world VERSION 1.0) enable\_testing() # get\_a…

---

## [add\_library(Target $\<$CONFIG:DebugEditor\>:SHARED "") error](https://discourse.cmake.org/t/add-library-target-config-debugeditor-shared-error/8126)

<div class="topic-metadata">

**Author:** [@aidexie](https://discourse.cmake.org/u/aidexie)\
**Replies:** 1\
**Last updated:** [May 15, 2023, 10:10am UTC](https://discourse.cmake.org/t/add-library-target-config-debugeditor-shared-error/8126 "2023-05-15T10:10:16Z")

</div>

On windows platform we use cmake to generate VS projects, which have a total of 4 configuration modes: Debug, DebugEditor, Release, ReleaseEditor. now we have a new requirement, some modules are compiled as static librar…

---

## [How to set the parameters of cmake\_ranlib?](https://discourse.cmake.org/t/how-to-set-the-parameters-of-cmake-ranlib/8112)

<div class="topic-metadata">

**Author:** [@TornadoMan](https://discourse.cmake.org/u/TornadoMan)\
**Replies:** 2\
**Last updated:** [May 15, 2023, 1:26am UTC](https://discourse.cmake.org/t/how-to-set-the-parameters-of-cmake-ranlib/8112 "2023-05-15T01:26:03Z")

</div>

For binary consistency, parameters ‘-D’ need to be set to cmake\_ranlib, I tried the following but it didn’t work SET(CMAKE\_C\_COMPILER\_RANLIB “\<CMAKE\_RANLIB\> -D ”) SET(CMAKE\_CXX\_COMPILER\_RANLIB “\<CMAKE\_RANLIB\> -D ”)

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

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