# Code

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

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

**Page:** 69

---

## [Provide a hint to find\_package to use a CMake target from the build tree](https://discourse.cmake.org/t/provide-a-hint-to-find-package-to-use-a-cmake-target-from-the-build-tree/1844)

<div class="topic-metadata">

**Author:** [@Ahmed\_Hesham](https://discourse.cmake.org/u/Ahmed_Hesham)\
**Replies:** 1\
**Last updated:** [September 15, 2020, 8:29am UTC](https://discourse.cmake.org/t/provide-a-hint-to-find-package-to-use-a-cmake-target-from-the-build-tree/1844 "2020-09-15T08:29:54Z")

</div>

Hello, I am having trouble with CMake in a use case that I would have thought to be fairly common. I am not entirely sure what to search for which is why I’m trying the mailing list. Let’s say I am building a C++ proje…

---

## [Using install(script ... correctly](https://discourse.cmake.org/t/using-install-script-correctly/1836)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 5\
**Last updated:** [September 15, 2020, 7:52am UTC](https://discourse.cmake.org/t/using-install-script-correctly/1836 "2020-09-15T07:52:20Z")

</div>

I’m trying to use “install(script …” correctly, but it seems to fail silently and I can’t work out why (precisely because its silent - there are no diagnostic or error messages being sent out). This is the script I want…

---

## [Using 'install(CODE "execute\_process(COMMAND ...' with a shell command](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 2\
**Last updated:** [September 14, 2020, 9:09am UTC](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833 "2020-09-14T09:09:14Z")

</div>

I’ve used the pattern install(CODE "execute\_process(COMMAND ${CMAKE\_COMMAND} -E ... successfully many times, but I’m having difficulty where the process I want to run is a Bash shell command rather than a CMAKE -E op…

---

## [Platform QNX does not set UNIX to True when cross-compiling on Windows](https://discourse.cmake.org/t/platform-qnx-does-not-set-unix-to-true-when-cross-compiling-on-windows/1824)

<div class="topic-metadata">

**Author:** [@Pablo\_R](https://discourse.cmake.org/u/Pablo_R)\
**Replies:** 1\
**Last updated:** [September 12, 2020, 11:24pm UTC](https://discourse.cmake.org/t/platform-qnx-does-not-set-unix-to-true-when-cross-compiling-on-windows/1824 "2020-09-12T23:24:14Z")

</div>

Hi, I am cross-compiling to QNX on Windows. The first lines of my toolchain file look as follows. include(Platform/QNX) set(CMAKE\_SYSTEM\_NAME QNX) set(CMAKE\_CXX\_COMPILER\_ID QCC) However, I observed that my CMakeLists …

---

## [cmake 3.14, ubunto 20.04: Generator Ninja does not support platform specification, but platform x64 was specified.](https://discourse.cmake.org/t/cmake-3-14-ubunto-20-04-generator-ninja-does-not-support-platform-specification-but-platform-x64-was-specified/1820)

<div class="topic-metadata">

**Author:** [@ProTur1](https://discourse.cmake.org/u/ProTur1)\
**Replies:** 1\
**Last updated:** [September 11, 2020, 3:47pm UTC](https://discourse.cmake.org/t/cmake-3-14-ubunto-20-04-generator-ninja-does-not-support-platform-specification-but-platform-x64-was-specified/1820 "2020-09-11T15:47:25Z")

</div>

Generator Ninja does not support platform specification, but platform x64 was specified. Where to start looking for the above problem? Im setting CMAKE\_GENERATOR\_PLATFORM without problem when working with genera…

---

## [CMake generating much smaller \*.a files than makefile](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816)

<div class="topic-metadata">

**Author:** [@dehilster](https://discourse.cmake.org/u/dehilster)\
**Replies:** 4\
**Last updated:** [September 10, 2020, 3:39pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816 "2020-09-10T15:39:40Z")

</div>

When converting from makefile to CMake, the resulting file sizes are hugely different. size with makefile: 266k size with cmake: 33K Here are the files. Any insight would be very helpful! Makefile: LIBOBJ = dir.o io…

---

## [Cannot find header files during compilation; dependencies managed by Hunter](https://discourse.cmake.org/t/cannot-find-header-files-during-compilation-dependencies-managed-by-hunter/1798)

<div class="topic-metadata">

**Author:** [@govi218](https://discourse.cmake.org/u/govi218)\
**Replies:** 1\
**Last updated:** [September 9, 2020, 9:55pm UTC](https://discourse.cmake.org/t/cannot-find-header-files-during-compilation-dependencies-managed-by-hunter/1798 "2020-09-09T21:55:00Z")

</div>

Here is my top level CMakeLists.txt. I build it using cmake -H. -B\_builds -DHUNTER\_STATUS\_DEBUG=ON -DCMAKE\_BUILD\_TYPE=Release : cmake\_minimum\_required(VERSION 3.2) set( CMAKE\_TOOLCHAIN\_FILE "${CMAKE\_SOURCE\_DIR}…

---

## [How to determine when set(var ... PARENT\_SCOPE) will work?](https://discourse.cmake.org/t/how-to-determine-when-set-var-parent-scope-will-work/1795)

<div class="topic-metadata">

**Author:** [@webbtrail](https://discourse.cmake.org/u/webbtrail)\
**Replies:** 6\
**Last updated:** [September 9, 2020, 3:31pm UTC](https://discourse.cmake.org/t/how-to-determine-when-set-var-parent-scope-will-work/1795 "2020-09-09T15:31:46Z")

</div>

I want an included .cmake file to pass/update variables in the PARENT\_SCOPE. What is the best way to determine that set(var value PARENT\_SCOPE) will work before it is used? has\_parent(HAS\_PARENT) if(HAS\_PARENT) set(p…

---

## [Missing CompileAs option on vcxproj generated by cmake 3.18.1](https://discourse.cmake.org/t/missing-compileas-option-on-vcxproj-generated-by-cmake-3-18-1/1708)

<div class="topic-metadata">

**Author:** [@YassinLokhat](https://discourse.cmake.org/u/YassinLokhat)\
**Replies:** 2\
**Last updated:** [August 26, 2020, 9:33pm UTC](https://discourse.cmake.org/t/missing-compileas-option-on-vcxproj-generated-by-cmake-3-18-1/1708 "2020-08-26T21:33:36Z")

</div>

When I generate the .vcxproj for my project with cmake 3.2.1, it generates the line \<CompileAs\>CompileAsCpp\</CompileAs\> But when I try the cmake version 3.18.1, the generated .vcxproj file does not contain that previou…

---

## [No such file or directory at configure time](https://discourse.cmake.org/t/no-such-file-or-directory-at-configure-time/1749)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 1\
**Last updated:** [August 26, 2020, 1:36pm UTC](https://discourse.cmake.org/t/no-such-file-or-directory-at-configure-time/1749 "2020-08-26T13:36:51Z")

</div>

Problem: execution of imported target returns a No such file or directory message. find\_package( Python3 ) if( Python3\_FOUND ) execute\_process( COMMAND Python3::Interpreter --version RESULT\_VARIABLE res OUTPUT\_V…

---

## [How does cmake configure Header Files folder to configure subfolder Item?](https://discourse.cmake.org/t/how-does-cmake-configure-header-files-folder-to-configure-subfolder-item/1728)

<div class="topic-metadata">

**Author:** [@mirro187](https://discourse.cmake.org/u/mirro187)\
**Replies:** 4\
**Last updated:** [August 23, 2020, 1:06am UTC](https://discourse.cmake.org/t/how-does-cmake-configure-header-files-folder-to-configure-subfolder-item/1728 "2020-08-23T01:06:04Z")

</div>

The red line has been identified in the screenshot below

---

## [How to statically link external library by target\_link\_libraries()?](https://discourse.cmake.org/t/how-to-statically-link-external-library-by-target-link-libraries/1718)

<div class="topic-metadata">

**Author:** [@yosukesan](https://discourse.cmake.org/u/yosukesan)\
**Replies:** 4\
**Last updated:** [August 19, 2020, 5:37pm UTC](https://discourse.cmake.org/t/how-to-statically-link-external-library-by-target-link-libraries/1718 "2020-08-19T17:37:32Z")

</div>

I am trying to achieve the equivalent of following command by CMake. gcc -static -O0 -g main.c /usr/lib/x86\_64-linux-gnu/libpthread.a My cmake script successfully built executable file, but gave segmentation fault at r…

---

## [Support for \`git describe\` output in a SemVer prerelease string](https://discourse.cmake.org/t/support-for-git-describe-output-in-a-semver-prerelease-string/1714)

<div class="topic-metadata">

**Author:** [@relliott](https://discourse.cmake.org/u/relliott)\
**Replies:** 4\
**Last updated:** [August 19, 2020, 4:16pm UTC](https://discourse.cmake.org/t/support-for-git-describe-output-in-a-semver-prerelease-string/1714 "2020-08-19T16:16:14Z")

</div>

Hello, I would like to have my project use the current output from git describe as the prerelease component of its SemVer version. I have a solution that seems to work in all but one corner case. I’m hoping to find a w…

---

## [orhestration](https://discourse.cmake.org/t/orhestration/1713)

<div class="topic-metadata">

**Author:** [@Tomasz](https://discourse.cmake.org/u/Tomasz)\
**Replies:** 0\
**Last updated:** [August 17, 2020, 7:29pm UTC](https://discourse.cmake.org/t/orhestration/1713 "2020-08-17T19:29:58Z")

</div>

Hi I have mid size project. Project is split trough modules(libs/exe) It also depends on external libs and framework. I have make constructed this project in that way: For all internal exe or libs I create it own CMa…

---

## [Unexpected/inconsistent behavior of cmake -E compare\_files](https://discourse.cmake.org/t/unexpected-inconsistent-behavior-of-cmake-e-compare-files/1680)

<div class="topic-metadata">

**Author:** [@arclight](https://discourse.cmake.org/u/arclight)\
**Replies:** 4\
**Last updated:** [August 17, 2020, 6:06pm UTC](https://discourse.cmake.org/t/unexpected-inconsistent-behavior-of-cmake-e-compare-files/1680 "2020-08-17T18:06:25Z")

</div>

I’m attempting to compare code output with reference text using CTest (add\_test()) and I’m getting some strange results which makes me think I’m not using cmake -E compare\_files correctly. The documentation and examples …

---

## [Issue building third party libraries and including them in same project](https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695)

<div class="topic-metadata">

**Author:** [@mattchabala](https://discourse.cmake.org/u/mattchabala)\
**Replies:** 1\
**Last updated:** [August 13, 2020, 3:43pm UTC](https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695 "2020-08-13T15:43:55Z")

</div>

Hello, I’m working on a simple project that uses a third party application to handle data. I’m using CMake to check if the third party application already exists on the machine and if it’s not then CMake downloads the l…

---

## [Cmake Cortex-M multitarget build](https://discourse.cmake.org/t/cmake-cortex-m-multitarget-build/1536)

<div class="topic-metadata">

**Author:** [@aphardt](https://discourse.cmake.org/u/aphardt)\
**Replies:** 8\
**Last updated:** [August 7, 2020, 11:06am UTC](https://discourse.cmake.org/t/cmake-cortex-m-multitarget-build/1536 "2020-08-07T11:06:12Z")

</div>

Hi Im trying to achieve a cmake build environment where i can build multiple targets (binaries) at once. cmake and make/ninja actually run successfully, but the generated ELF’s somehow do not run at all. When i run the…

---

## [Define a pre-build command without creating a new target](https://discourse.cmake.org/t/define-a-pre-build-command-without-creating-a-new-target/1623)

<div class="topic-metadata">

**Author:** [@Artemis](https://discourse.cmake.org/u/Artemis)\
**Replies:** 12\
**Last updated:** [August 5, 2020, 2:13pm UTC](https://discourse.cmake.org/t/define-a-pre-build-command-without-creating-a-new-target/1623 "2020-08-05T14:13:43Z")

</div>

After reading Professional CMake (almost) back to back, I’m once again asking for your support :upside\_down\_face: I’m struggling to define a fixed pre-build command for a target. I need to generate a header with the cur…

---

## [cmake 3.17.0 generates target-NOTFOUND for configured target](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642)

<div class="topic-metadata">

**Author:** [@yisseamake](https://discourse.cmake.org/u/yisseamake)\
**Replies:** 2\
**Last updated:** [August 4, 2020, 1:33pm UTC](https://discourse.cmake.org/t/cmake-3-17-0-generates-target-notfound-for-configured-target/1642 "2020-08-04T13:33:05Z")

</div>

Could you please advise what causes cmake to fail finding existing imported library target when generating build.make \_EXTERNAL\_OBJECTS list. cmake generates file ./build/mingw64/myprjsrc/CMakeFiles/myshared.dir/build.…

---

## [CPack + Wix + WixFirewallExtension - can I add a new xmlns to the filex.wxs file?](https://discourse.cmake.org/t/cpack-wix-wixfirewallextension-can-i-add-a-new-xmlns-to-the-filex-wxs-file/1569)

<div class="topic-metadata">

**Author:** [@bolz](https://discourse.cmake.org/u/bolz)\
**Replies:** 2\
**Last updated:** [August 4, 2020, 12:08pm UTC](https://discourse.cmake.org/t/cpack-wix-wixfirewallextension-can-i-add-a-new-xmlns-to-the-filex-wxs-file/1569 "2020-08-04T12:08:56Z")

</div>

Hello, I’m rather new at using CPack, so please bear with me. I have a project for which I use CPack and Wix to create an msi. I need to add a firewall exception for the installed executable, but I get this error in wi…

---

## [How to use CPack IFW to generate desktop shortcuts?](https://discourse.cmake.org/t/how-to-use-cpack-ifw-to-generate-desktop-shortcuts/1663)

<div class="topic-metadata">

**Author:** [@Mr-jiayunfei](https://discourse.cmake.org/u/Mr-jiayunfei)\
**Replies:** 0\
**Last updated:** [August 4, 2020, 2:50am UTC](https://discourse.cmake.org/t/how-to-use-cpack-ifw-to-generate-desktop-shortcuts/1663 "2020-08-04T02:50:14Z")

</div>

How to use CPack IFW to generate desktop shortcuts? How to use CPack IFW to overwrite an existing installation? I use the Install frame work that comes with Qt to write scripts that can complete the function, but I wan…

---

## [how to implement only configuration in the header file folder to add a folder?](https://discourse.cmake.org/t/how-to-implement-only-configuration-in-the-header-file-folder-to-add-a-folder/1652)

<div class="topic-metadata">

**Author:** [@mirro187](https://discourse.cmake.org/u/mirro187)\
**Replies:** 0\
**Last updated:** [July 31, 2020, 5:14am UTC](https://discourse.cmake.org/t/how-to-implement-only-configuration-in-the-header-file-folder-to-add-a-folder/1652 "2020-07-31T05:14:52Z")

</div>

---

## [Makefile Generator indepent definition of compiler / linker options containing shell meta characters](https://discourse.cmake.org/t/makefile-generator-indepent-definition-of-compiler-linker-options-containing-shell-meta-characters/1534)

<div class="topic-metadata">

**Author:** [@raik](https://discourse.cmake.org/u/raik)\
**Replies:** 2\
**Last updated:** [July 28, 2020, 1:45pm UTC](https://discourse.cmake.org/t/makefile-generator-indepent-definition-of-compiler-linker-options-containing-shell-meta-characters/1534 "2020-07-28T13:45:32Z")

</div>

Hello, we are facing problems to define compiler or linker options inside cmake files that contain characters having some special meaning for make target commands interpreter in a CMakeGenerator independent way. Eg. When…

---

## [Finding library names and locations](https://discourse.cmake.org/t/finding-library-names-and-locations/1622)

<div class="topic-metadata">

**Author:** [@normvcr](https://discourse.cmake.org/u/normvcr)\
**Replies:** 2\
**Last updated:** [July 27, 2020, 1:22am UTC](https://discourse.cmake.org/t/finding-library-names-and-locations/1622 "2020-07-27T01:22:28Z")

</div>

The command ‘’‘find\_package(Qt5 COMPONENTS Widgets REQUIRED CONFIG)’’’ seems to work, as Qt5\_FOUND is true, and Qt5Widgets\_INCLUDE\_DIRS has the correct include folders. However, Qt5Widgets\_LIBRARIES only has “Qt5::Wi…

---

## [Delay in operation of file(GENERATE ...](https://discourse.cmake.org/t/delay-in-operation-of-file-generate/1611)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 6\
**Last updated:** [July 23, 2020, 10:42pm UTC](https://discourse.cmake.org/t/delay-in-operation-of-file-generate/1611 "2020-07-23T22:42:12Z")

</div>

This little bit of code: file(GENERATE OUTPUT ${CMAKE\_CURRENT\_BINARY\_DIR}/empty\_pch.cxx CONTENT "/\* empty file \*/") target\_sources(CommonPCH\_Lib PRIVATE ${CMAKE\_CURRENT\_BINARY\_DIR}/empty\_pch.cxx) … works perf…

---

## [Short-circuit evaluation in if?](https://discourse.cmake.org/t/short-circuit-evaluation-in-if/1608)

<div class="topic-metadata">

**Author:** [@Leherenn](https://discourse.cmake.org/u/Leherenn)\
**Replies:** 3\
**Last updated:** [July 22, 2020, 3:15pm UTC](https://discourse.cmake.org/t/short-circuit-evaluation-in-if/1608 "2020-07-22T15:15:59Z")

</div>

I could not find it in the documentation (https://cmake.org/cmake/help/latest/command/if.html), but it would seem that conditions do not short-circuit. Is that correct? if(DEFINED MY\_VAR AND ${MY\_VAR} STREQUAL "true") …

---

## [Why does cmake have no file selection button after Find\*\*\*.cmake sets the PTHREADS\_INCLUDE\_DIR variable?](https://discourse.cmake.org/t/why-does-cmake-have-no-file-selection-button-after-find-cmake-sets-the-pthreads-include-dir-variable/1607)

<div class="topic-metadata">

**Author:** [@mirro187](https://discourse.cmake.org/u/mirro187)\
**Replies:** 1\
**Last updated:** [July 22, 2020, 12:14pm UTC](https://discourse.cmake.org/t/why-does-cmake-have-no-file-selection-button-after-find-cmake-sets-the-pthreads-include-dir-variable/1607 "2020-07-22T12:14:13Z")

</div>

---

## [install with EXPORT and multiple CONFIGURATIONS](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 4\
**Last updated:** [July 22, 2020, 1:02am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292 "2020-07-22T01:02:04Z")

</div>

I want to make a multi configuration package using cpack -C and the Visual Studio multi-generator. So, knowing that each of RUNTIME, LIBRARY, and ARCHIVE can appear only once in a call to install(), I tried writing the c…

---

## [OneAPI support with Custom Toolchain](https://discourse.cmake.org/t/oneapi-support-with-custom-toolchain/1593)

<div class="topic-metadata">

**Author:** [@jyoung](https://discourse.cmake.org/u/jyoung)\
**Replies:** 1\
**Last updated:** [July 20, 2020, 9:26pm UTC](https://discourse.cmake.org/t/oneapi-support-with-custom-toolchain/1593 "2020-07-20T21:26:23Z")

</div>

I’m trying to write a custom toolchain file to support compiling a simple OneAPI project with the DPCPP compiler. It was suggested in a recent workshop that I write a custom toolchain file, which I have done (see attache…

---

## [Depending on Package Config file as External Project](https://discourse.cmake.org/t/depending-on-package-config-file-as-external-project/1501)

<div class="topic-metadata">

**Author:** [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)\
**Replies:** 11\
**Last updated:** [July 20, 2020, 10:47am UTC](https://discourse.cmake.org/t/depending-on-package-config-file-as-external-project/1501 "2020-07-20T10:47:59Z")

</div>

I’m looking to provide sample code to a library built using CMake. The sample is hosted alongside the sources of the library in a folder called \<project\_root\>/example and I would like it to show how downstreams would use…

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

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