# Code

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

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

**Page:** 67

---

## [generator expression $\<$\<BOOL:MSVC\>:dllmain.c\> evaluate to dllmain.c on linux](https://discourse.cmake.org/t/generator-expression-bool-msvc-dllmain-c-evaluate-to-dllmain-c-on-linux/2150)

<div class="topic-metadata">

**Author:** [@quanzhuo](https://discourse.cmake.org/u/quanzhuo)\
**Replies:** 3\
**Last updated:** [November 12, 2020, 1:01am UTC](https://discourse.cmake.org/t/generator-expression-bool-msvc-dllmain-c-evaluate-to-dllmain-c-on-linux/2150 "2020-11-12T01:01:37Z")

</div>

All is in title. $\<$\< BOOL:MSVC\>:dllmain.c\> evaluate to dllmain.c on Windows which is expected, However, it evaluated to dllmain.c on linux too. Why ? I use cmake 3.18 on both windows and linux.

---

## [cannot link to dynamic library correctly during parallel build](https://discourse.cmake.org/t/cannot-link-to-dynamic-library-correctly-during-parallel-build/1706)

<div class="topic-metadata">

**Author:** [@sandy-lcq](https://discourse.cmake.org/u/sandy-lcq)\
**Replies:** 1\
**Last updated:** [November 11, 2020, 10:12pm UTC](https://discourse.cmake.org/t/cannot-link-to-dynamic-library-correctly-during-parallel-build/1706 "2020-11-11T22:12:22Z")

</div>

I met a compile fail problem, which is caused during parallel build. Please see this bug report for detail: https://bugs.llvm.org/show\_bug.cgi?id=46617 how can I fix this in CMakeList.txt? I have tried to explicitly c…

---

## [Presentation order of targets within XCode](https://discourse.cmake.org/t/presentation-order-of-targets-within-xcode/1675)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 1\
**Last updated:** [November 11, 2020, 9:09pm UTC](https://discourse.cmake.org/t/presentation-order-of-targets-within-xcode/1675 "2020-11-11T21:09:47Z")

</div>

Using XCode with USE\_FOLDERS / set\_taget\_property(… FOLDER …) has helped organise my projects with lots of targets. However, the targets still appear inside XCode in arbitrary order (within the folders). Is there a way…

---

## [please, can you help me urgently](https://discourse.cmake.org/t/please-can-you-help-me-urgently/1673)

<div class="topic-metadata">

**Author:** [@Murat\_Serdar](https://discourse.cmake.org/u/Murat_Serdar)\
**Replies:** 1\
**Last updated:** [November 11, 2020, 9:07pm UTC](https://discourse.cmake.org/t/please-can-you-help-me-urgently/1673 "2020-11-11T21:07:24Z")

</div>

Hello, ı need to run a engineering code but for cmake ım beginner. I have to go this process MCS compiling procedure: Open CMakeLists.txt and change the default library path, xsdir, and version of library. Open CMakeL…

---

## [get\_filename\_component name\_we / name\_wle: what is 'or' ?](https://discourse.cmake.org/t/get-filename-component-name-we-name-wle-what-is-or/1370)

<div class="topic-metadata">

**Author:** [@davemilter](https://discourse.cmake.org/u/davemilter)\
**Replies:** 8\
**Last updated:** [November 10, 2020, 3:09pm UTC](https://discourse.cmake.org/t/get-filename-component-name-we-name-wle-what-is-or/1370 "2020-11-10T15:09:29Z")

</div>

I can not understand documentation of get\_filename\_component . It describes: NAME\_WE = File name without directory or longest extension NAME\_WLE = File name without directory or last extension What does it mean? If…

---

## [Propagating CXX flags to out of source projects?](https://discourse.cmake.org/t/propagating-cxx-flags-to-out-of-source-projects/2138)

<div class="topic-metadata">

**Author:** [@mrfirmware](https://discourse.cmake.org/u/mrfirmware)\
**Replies:** 11\
**Last updated:** [November 10, 2020, 12:07pm UTC](https://discourse.cmake.org/t/propagating-cxx-flags-to-out-of-source-projects/2138 "2020-11-10T12:07:12Z")

</div>

I need to propagate some cross-compiler flags like -mcpu down to some lower level libraries that are out of source. Is there “CMake way” to do this or do I need to agree upon some global variable name convention and “pas…

---

## [Inconsistent behaviour of \<PROJECT-NAME\>\_\* Variables defined on PROJECT Command](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288)

<div class="topic-metadata">

**Author:** [@infohoschie](https://discourse.cmake.org/u/infohoschie)\
**Replies:** 2\
**Last updated:** [November 9, 2020, 9:54pm UTC](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288 "2020-11-09T21:54:23Z")

</div>

When a Project is defined some project specific variables are set: \<PROJECT-NAME\>\_SOURCE\_DIR \<PROJECT-NAME\>\_BINARY\_DIR \<PROJECT-NAME\>\_VERSION \<PROJECT-NAME\>\_DESCRIPTION The scope of this variables seems to be inconsis…

---

## [Where are Exported Global Variables?](https://discourse.cmake.org/t/where-are-exported-global-variables/1299)

<div class="topic-metadata">

**Author:** [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 9:50pm UTC](https://discourse.cmake.org/t/where-are-exported-global-variables/1299 "2020-11-09T21:50:34Z")

</div>

Community Gurus: Does anybody know where the “exported global variables” are stored, and how to access them? When I execute this command ’ cmake -G “Eclipse CDT4 - Unix Makefiles” source ’ I see a comment in the genera…

---

## [how to perform a gcc command by using CMake and make](https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963)

<div class="topic-metadata">

**Author:** [@Lerner](https://discourse.cmake.org/u/Lerner)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 8:50pm UTC](https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963 "2020-11-09T20:50:40Z")

</div>

Hello everyone, I’m trying to create a statically linked lib-curl executable using CMake but I get undefined reference errors when I try to ‘make’ it, although I can successfully compile it with: "gcc -static main.c -o…

---

## [get\_prerequisites() tries to resolve system libraries even though advised not to](https://discourse.cmake.org/t/get-prerequisites-tries-to-resolve-system-libraries-even-though-advised-not-to/1148)

<div class="topic-metadata">

**Author:** [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 8:10pm UTC](https://discourse.cmake.org/t/get-prerequisites-tries-to-resolve-system-libraries-even-though-advised-not-to/1148 "2020-11-09T20:10:08Z")

</div>

My cmake file calls get\_prerequisites() with exclude\_system = 1 and recurse = 1 My expectation is that system libraries are not processed, which is what I want because I do not want to include them in the binary pack…

---

## [Common files used by multiple targets](https://discourse.cmake.org/t/common-files-used-by-multiple-targets/1203)

<div class="topic-metadata">

**Author:** [@vheon](https://discourse.cmake.org/u/vheon)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 7:57pm UTC](https://discourse.cmake.org/t/common-files-used-by-multiple-targets/1203 "2020-11-09T19:57:19Z")

</div>

Hi, I’m trying to port a project from a custom build system that generate Makefile to CMake. I am a novice of CMake but I’m studying :stuck\_out\_tongue: The project builds multiple executable and each executable is build…

---

## [Source doesn't exist yet for target depending on custom target using source generated by add\_custom\_command](https://discourse.cmake.org/t/source-doesnt-exist-yet-for-target-depending-on-custom-target-using-source-generated-by-add-custom-command/1218)

<div class="topic-metadata">

**Author:** [@Smit\_Patil](https://discourse.cmake.org/u/Smit_Patil)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 7:53pm UTC](https://discourse.cmake.org/t/source-doesnt-exist-yet-for-target-depending-on-custom-target-using-source-generated-by-add-custom-command/1218 "2020-11-09T19:53:48Z")

</div>

I am trying to port a meson project to CMake. I have the following subdirectories in my main CMake file: add\_subdirectory(protos) add\_subdirectory(qtlayershell) add\_subdirectory(demo) and the following in protos/CMak…

---

## [CMake different build output in windows and linux for ARM M0](https://discourse.cmake.org/t/cmake-different-build-output-in-windows-and-linux-for-arm-m0/1233)

<div class="topic-metadata">

**Author:** [@david.reimondez](https://discourse.cmake.org/u/david.reimondez)\
**Replies:** 1\
**Last updated:** [November 9, 2020, 7:46pm UTC](https://discourse.cmake.org/t/cmake-different-build-output-in-windows-and-linux-for-arm-m0/1233 "2020-11-09T19:46:31Z")

</div>

Hi all ! We are using cmake in combination with Ninja and gcc-arm compiler for doing cross-compiling for ARM M0 microcontroller processor. The output of this is an .hex file It is quite interesting that using exactly s…

---

## [Potential regression?: CMake + SWIG not detecting C++ headers as dependencies](https://discourse.cmake.org/t/potential-regression-cmake-swig-not-detecting-c-headers-as-dependencies/2135)

<div class="topic-metadata">

**Author:** [@sir.ferdek](https://discourse.cmake.org/u/sir.ferdek)\
**Replies:** 7\
**Last updated:** [November 9, 2020, 3:49pm UTC](https://discourse.cmake.org/t/potential-regression-cmake-swig-not-detecting-c-headers-as-dependencies/2135 "2020-11-09T15:49:16Z")

</div>

Hello everyone. I am looking for help in either configuring properly my project or determining if this is a bug that should be reported on gitlab. I have prepared a minimalistic project that reproduces the issue (but as…

---

## [String escaping with target\_compile\_options()](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117)

<div class="topic-metadata">

**Author:** [@JoelLinn](https://discourse.cmake.org/u/JoelLinn)\
**Replies:** 2\
**Last updated:** [November 4, 2020, 6:59pm UTC](https://discourse.cmake.org/t/string-escaping-with-target-compile-options/2117 "2020-11-04T18:59:43Z")

</div>

Hi, I need to pass some unorthodox arguments to the compiler, but without having their special characters escaped, like /wd"1234". This works with setting the flags variable globally but not when using target\_compile\_op…

---

## [Append variable to \<BUILD\_DIR\> in ExternalProject\_Add command](https://discourse.cmake.org/t/append-variable-to-build-dir-in-externalproject-add-command/2098)

<div class="topic-metadata">

**Author:** [@tomhh](https://discourse.cmake.org/u/tomhh)\
**Replies:** 3\
**Last updated:** [October 31, 2020, 10:45pm UTC](https://discourse.cmake.org/t/append-variable-to-build-dir-in-externalproject-add-command/2098 "2020-10-31T22:45:52Z")

</div>

I have an ExternalProject\_Add call that looks like this… ExternalProject\_Add( SDL2 URL https://www.libsdl.org/release/SDL2-2.0.12.tar.gz URL\_HASH MD5=783b6f2df8ff02b19bb5ce492b99c8ff INSTALL\_DIR ${CMAKE…

---

## [target\_sources() and header visibility](https://discourse.cmake.org/t/target-sources-and-header-visibility/2096)

<div class="topic-metadata">

**Author:** [@DreamCaptain](https://discourse.cmake.org/u/DreamCaptain)\
**Replies:** 5\
**Last updated:** [October 30, 2020, 12:46pm UTC](https://discourse.cmake.org/t/target-sources-and-header-visibility/2096 "2020-10-30T12:46:56Z")

</div>

Hi, I’m trying modern cmake approach, but seems like my understanding of how target\_sources() command works is wrong. Consider following hierarchy: foo\_project/ ├── CMakeLists.txt ├── headers │ └── foo.h ├── interfa…

---

## [Using get\_target\_property (or just get\_property) with generator expressions](https://discourse.cmake.org/t/using-get-target-property-or-just-get-property-with-generator-expressions/2090)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 6\
**Last updated:** [October 29, 2020, 1:34pm UTC](https://discourse.cmake.org/t/using-get-target-property-or-just-get-property-with-generator-expressions/2090 "2020-10-29T13:34:20Z")

</div>

I’ve been trying to obtain either IMPORTED\_LOCATION\_DEBUG, IMPORTED\_LOCATION\_RELEASE, IMPORTED\_LOCATION\_RELWITHDEBINFO, or IMPORTED\_LOCATION\_MINSIZEREL for a target, depending upon the configuration that I’m currently bu…

---

## [Why is TARGET\_LINK\_LIBRARIES unable to link to third-party libraries when configuring static libraries?](https://discourse.cmake.org/t/why-is-target-link-libraries-unable-to-link-to-third-party-libraries-when-configuring-static-libraries/1855)

<div class="topic-metadata">

**Author:** [@mirro187](https://discourse.cmake.org/u/mirro187)\
**Replies:** 3\
**Last updated:** [October 29, 2020, 1:50am UTC](https://discourse.cmake.org/t/why-is-target-link-libraries-unable-to-link-to-third-party-libraries-when-configuring-static-libraries/1855 "2020-10-29T01:50:25Z")

</div>

---

## [add\_custom\_command fails when OUTPUT is generated into a subdirectory](https://discourse.cmake.org/t/add-custom-command-fails-when-output-is-generated-into-a-subdirectory/2074)

<div class="topic-metadata">

**Author:** [@jjELT](https://discourse.cmake.org/u/jjELT)\
**Replies:** 15\
**Last updated:** [October 28, 2020, 1:46pm UTC](https://discourse.cmake.org/t/add-custom-command-fails-when-output-is-generated-into-a-subdirectory/2074 "2020-10-28T13:46:44Z")

</div>

Find attached a minimal example, where I am generating sources for a library my-lib using add\_custom\_command, an executable my-app depends on: (I cannot actually upload anything yet as a new user, so find the sample pro…

---

## [Any way to log message() outputs to a log file?](https://discourse.cmake.org/t/any-way-to-log-message-outputs-to-a-log-file/2021)

<div class="topic-metadata">

**Author:** [@starseeker](https://discourse.cmake.org/u/starseeker)\
**Replies:** 3\
**Last updated:** [October 27, 2020, 12:02pm UTC](https://discourse.cmake.org/t/any-way-to-log-message-outputs-to-a-log-file/2021 "2020-10-27T12:02:14Z")

</div>

Some years ago, there was some discussion about introducing a way in CMake to specify a file to use to log a copy of the message() function’s outputs: https://cmake.org/pipermail/cmake-developers/2015-July/025681.html D…

---

## [How to link an imported shared library to an executable without hard-coding the path and file name?](https://discourse.cmake.org/t/how-to-link-an-imported-shared-library-to-an-executable-without-hard-coding-the-path-and-file-name/2067)

<div class="topic-metadata">

**Author:** [@Shane\_Dev](https://discourse.cmake.org/u/Shane_Dev)\
**Replies:** 6\
**Last updated:** [October 26, 2020, 8:05am UTC](https://discourse.cmake.org/t/how-to-link-an-imported-shared-library-to-an-executable-without-hard-coding-the-path-and-file-name/2067 "2020-10-26T08:05:50Z")

</div>

Hello, My CMake project uses some third party libraries which I declared as IMPORTED then I set the IMPORTED\_IMPLIB or IMPORTED\_LOCATION properties (depending on compiler and type of library) to the full path and file n…

---

## [On Windows CHECK\_CXX\_SOURCE\_RUNS is calling check\_source\_runs](https://discourse.cmake.org/t/on-windows-check-cxx-source-runs-is-calling-check-source-runs/2065)

<div class="topic-metadata">

**Author:** [@bradbell](https://discourse.cmake.org/u/bradbell)\
**Replies:** 12\
**Last updated:** [October 25, 2020, 8:09pm UTC](https://discourse.cmake.org/t/on-windows-check-cxx-source-runs-is-calling-check-source-runs/2065 "2020-10-25T20:09:59Z")

</div>

I have a very simple project that indicate that when in Windows (Linux) CMAKE\_CXX\_SOURCE\_RUNS is calling (is not calling) my macro check\_source\_runs. The commands mkdir build cd build cmake .. run fine on Linux and exi…

---

## [What is the use of property IMPORTED\_LOCATION on DLL platforms?](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069)

<div class="topic-metadata">

**Author:** [@Shane\_Dev](https://discourse.cmake.org/u/Shane_Dev)\
**Replies:** 2\
**Last updated:** [October 25, 2020, 7:12pm UTC](https://discourse.cmake.org/t/what-is-the-use-of-property-imported-location-on-dll-platforms/2069 "2020-10-25T19:12:55Z")

</div>

Hello, According to the docs, IMPORTED\_LOCATION should be set to the .dll part of the library. I have found that it is not necessary. However the DLL does need to be in an appropriate location such as ${CMAKE\_BINARY\_DIR…

---

## [Finding program (really, build target) to be run by a CTest test?](https://discourse.cmake.org/t/finding-program-really-build-target-to-be-run-by-a-ctest-test/2047)

<div class="topic-metadata">

**Author:** [@starseeker](https://discourse.cmake.org/u/starseeker)\
**Replies:** 1\
**Last updated:** [October 25, 2020, 12:48pm UTC](https://discourse.cmake.org/t/finding-program-really-build-target-to-be-run-by-a-ctest-test/2047 "2020-10-25T12:48:24Z")

</div>

Is there any way to use get\_test\_property to report the program to be run to execute the test? Background: I’m using one of the standard workarounds for the current inability to make Ctest tests depend on the building …

---

## [How to run script in install phase from install directory](https://discourse.cmake.org/t/how-to-run-script-in-install-phase-from-install-directory/2043)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 4\
**Last updated:** [October 23, 2020, 10:11pm UTC](https://discourse.cmake.org/t/how-to-run-script-in-install-phase-from-install-directory/2043 "2020-10-23T22:11:32Z")

</div>

Dear CMake Gurus, This is a little convoluted and long, but I’m hoping it’s possible in CMake…with as little change to source code as possible! To wit, I work on a earth science model and one of the goals with our rece…

---

## [Best practices for option naming?](https://discourse.cmake.org/t/best-practices-for-option-naming/2039)

<div class="topic-metadata">

**Author:** [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Replies:** 2\
**Last updated:** [October 21, 2020, 4:30pm UTC](https://discourse.cmake.org/t/best-practices-for-option-naming/2039 "2020-10-21T16:30:51Z")

</div>

I recently came across this “problem” while I restructuring our source tree. Previously our third party dependencies were in the same repository as our own code and include by hand in our own CMake files. We changed thi…

---

## [How to add custom command after compilation stage and before linking stage?](https://discourse.cmake.org/t/how-to-add-custom-command-after-compilation-stage-and-before-linking-stage/2033)

<div class="topic-metadata">

**Author:** [@psionic12](https://discourse.cmake.org/u/psionic12)\
**Replies:** 2\
**Last updated:** [October 20, 2020, 8:58am UTC](https://discourse.cmake.org/t/how-to-add-custom-command-after-compilation-stage-and-before-linking-stage/2033 "2020-10-20T08:58:20Z")

</div>

Hi, I’m a writer of a code generator tool, and the tool must be run after the compilation stage and before linking stage. We use makefile before and this is not a problem, but when ports to cmake, I only find adding fl…

---

## [Boost Linker Issues](https://discourse.cmake.org/t/boost-linker-issues/2030)

<div class="topic-metadata">

**Author:** [@LavaMaster](https://discourse.cmake.org/u/LavaMaster)\
**Replies:** 17\
**Last updated:** [October 20, 2020, 7:45am UTC](https://discourse.cmake.org/t/boost-linker-issues/2030 "2020-10-20T07:45:05Z")

</div>

I am using the Boost library and I am having some linker issues. Currently my code is outputting this: Undefined symbols for architecture x86\_64: “boost::program\_options::to\_internal(std::\_\_1::basic\_string\<char, std::\_…

---

## [\`CXX\_EXTENSIONS\` and \`/permissive-\`](https://discourse.cmake.org/t/cxx-extensions-and-permissive/1994)

<div class="topic-metadata">

**Author:** [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)\
**Replies:** 1\
**Last updated:** [October 18, 2020, 3:17am UTC](https://discourse.cmake.org/t/cxx-extensions-and-permissive/1994 "2020-10-18T03:17:05Z")

</div>

AFAICT when I’m compiling a C++ target with the property CXX\_EXTENSIONS=OFF using MSVC, CMake doesn’t add the /permissive- flag, which as per the docs: You can use the /permissive- compiler option to specify standards-…

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

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