# Code

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

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

**Page:** 51

---

## [Parser does not catch Generator Expression Error](https://discourse.cmake.org/t/parser-does-not-catch-generator-expression-error/4877)

<div class="topic-metadata">

**Author:** [@Gopal\_Raghavan](https://discourse.cmake.org/u/Gopal_Raghavan)\
**Replies:** 2\
**Last updated:** [January 19, 2022, 10:09pm UTC](https://discourse.cmake.org/t/parser-does-not-catch-generator-expression-error/4877 "2022-01-19T22:09:38Z")

</div>

When using the following expression: $\<$\<OR:$\<CONFIG:flash\_release\>,$\<CONFIG:flash\_debug\>\>:${LINKER\_FLAGS\_FLASH\_COMMON}\>, if i am missing the final \>, cmake generator does not catch this error. This results in weird li…

---

## [pkg\_check\_modules in FindPkgConfig creates interface library](https://discourse.cmake.org/t/pkg-check-modules-in-findpkgconfig-creates-interface-library/4847)

<div class="topic-metadata">

**Author:** [@lguez](https://discourse.cmake.org/u/lguez)\
**Replies:** 12\
**Last updated:** [January 19, 2022, 3:22pm UTC](https://discourse.cmake.org/t/pkg-check-modules-in-findpkgconfig-creates-interface-library/4847 "2022-01-19T15:22:32Z")

</div>

When called with the IMPORTED\_TARGET argument, the command pkg\_check\_modules in the module FindPkgConfig creates an interface library. From the code of FindPkgConfig.cmake: add\_library(PkgConfig::${\_prefix} INTERFACE I…

---

## [ExternalProject\_Add + file api](https://discourse.cmake.org/t/externalproject-add-file-api/4868)

<div class="topic-metadata">

**Author:** [@DavidHeitbrink](https://discourse.cmake.org/u/DavidHeitbrink)\
**Replies:** 1\
**Last updated:** [January 18, 2022, 8:28pm UTC](https://discourse.cmake.org/t/externalproject-add-file-api/4868 "2022-01-18T20:28:26Z")

</div>

I am working with a multi-repo system, basically everything is added via ExternalProject\_Add. My build system is Linux (with cmake v 3.20.2), I have a remote connection from a windows machine. The issue I am having is I…

---

## [Install to $COMMONFILES with nsis](https://discourse.cmake.org/t/install-to-commonfiles-with-nsis/4802)

<div class="topic-metadata">

**Author:** [@abique](https://discourse.cmake.org/u/abique)\
**Replies:** 2\
**Last updated:** [January 17, 2022, 9:07am UTC](https://discourse.cmake.org/t/install-to-commonfiles-with-nsis/4802 "2022-01-17T09:07:45Z")

</div>

Hi, I want to install some files into $COMMONFILES, but I don’t know how to do that, cpack:nsis puts everything into program files. Do you know how to solve it? Thank you.

---

## [Apply clang-tidy on objective-c++ file using cmake ?](https://discourse.cmake.org/t/apply-clang-tidy-on-objective-c-file-using-cmake/4860)

<div class="topic-metadata">

**Author:** [@zohar81](https://discourse.cmake.org/u/zohar81)\
**Replies:** 1\
**Last updated:** [January 16, 2022, 6:15pm UTC](https://discourse.cmake.org/t/apply-clang-tidy-on-objective-c-file-using-cmake/4860 "2022-01-16T18:15:22Z")

</div>

Hi, I’m applying my clang-tidy rules on macOS cmake project using the following command : set\_target\_properties(${target\_name} PROPERTIES CXX\_CLANG\_TIDY ${clang\_tidy\_cmd}) Recently I’ve added a file that is written in …

---

## [How can I suppress CMake's warning about RPATH or tell it to ignore implicit directories?](https://discourse.cmake.org/t/how-can-i-suppress-cmakes-warning-about-rpath-or-tell-it-to-ignore-implicit-directories/4745)

<div class="topic-metadata">

**Author:** [@sgfallows](https://discourse.cmake.org/u/sgfallows)\
**Replies:** 3\
**Last updated:** [January 16, 2022, 5:55pm UTC](https://discourse.cmake.org/t/how-can-i-suppress-cmakes-warning-about-rpath-or-tell-it-to-ignore-implicit-directories/4745 "2022-01-16T17:55:24Z")

</div>

I’ve recently converted a large mature project from qmake to CMake. On Ubuntu 20.04, CMake 3.21.0 After configuration is complete (so during generation I assume) CMake reports the following error for several of the shar…

---

## [Setting environment variables in a batch file called using execute\_process.](https://discourse.cmake.org/t/setting-environment-variables-in-a-batch-file-called-using-execute-process/4861)

<div class="topic-metadata">

**Author:** [@underdisc](https://discourse.cmake.org/u/underdisc)\
**Replies:** 1\
**Last updated:** [January 16, 2022, 5:27pm UTC](https://discourse.cmake.org/t/setting-environment-variables-in-a-batch-file-called-using-execute-process/4861 "2022-01-16T17:27:03Z")

</div>

Say I have a batch file that looks like this. set varA=valueA I want my CMakeLists.txt file to make use of this environment variable with the syntax provided by CMake. $ENV{varA} Before that can be done, I need to ru…

---

## [target\_precompile\_headers, generate an .h precompiled header file instead of .hxx ?](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815)

<div class="topic-metadata">

**Author:** [@amzh](https://discourse.cmake.org/u/amzh)\
**Replies:** 4\
**Last updated:** [January 13, 2022, 11:26am UTC](https://discourse.cmake.org/t/target-precompile-headers-generate-an-h-precompiled-header-file-instead-of-hxx/4815 "2022-01-13T11:26:38Z")

</div>

Hello, The documentation says The list of header files is used to generate a header file named cmake\_pch.h|xx which is used to generate the precompiled header file What 's the proper way of telling CMake how to gen…

---

## [Two same output obj generated by VS IDE and CMake command line cause LNK4006](https://discourse.cmake.org/t/two-same-output-obj-generated-by-vs-ide-and-cmake-command-line-cause-lnk4006/4833)

<div class="topic-metadata">

**Author:** [@wowengineer](https://discourse.cmake.org/u/wowengineer)\
**Replies:** 0\
**Last updated:** [January 13, 2022, 4:06am UTC](https://discourse.cmake.org/t/two-same-output-obj-generated-by-vs-ide-and-cmake-command-line-cause-lnk4006/4833 "2022-01-13T04:06:05Z")

</div>

I’m adding NASM files into projects by CMakelists. With this version, IDE and project have two output folders to generate same obj, so that cause warning lnk4006 already defined second definition ignored. One output fold…

---

## [Correct way to link std::filesystem with GCC 8?](https://discourse.cmake.org/t/correct-way-to-link-std-filesystem-with-gcc-8/4121)

<div class="topic-metadata">

**Author:** [@spinicist](https://discourse.cmake.org/u/spinicist)\
**Replies:** 7\
**Last updated:** [January 12, 2022, 4:03pm UTC](https://discourse.cmake.org/t/correct-way-to-link-std-filesystem-with-gcc-8/4121 "2022-01-12T16:03:08Z")

</div>

As noted at the bottom of the page here: Filesystem library - cppreference.com, using std::filesystem from C++17 with GCC 8 requires adding -lstdc++fs to the linker options. GCC 8 is the system compiler for Debian 10. W…

---

## [How to add different OpenCL installed libraries to my CMake project](https://discourse.cmake.org/t/how-to-add-different-opencl-installed-libraries-to-my-cmake-project/4750)

<div class="topic-metadata">

**Author:** [@Tamas](https://discourse.cmake.org/u/Tamas)\
**Replies:** 0\
**Last updated:** [December 31, 2021, 7:47am UTC](https://discourse.cmake.org/t/how-to-add-different-opencl-installed-libraries-to-my-cmake-project/4750 "2021-12-31T07:47:47Z")

</div>

I’ve the interfaces under my repo. I also installed some vendor OpenCL libs and I don’t know how I can handle separately. The best I know, I create a small library for each verndors and before calling them I check whethe…

---

## [Why macro argument gets evaluated?](https://discourse.cmake.org/t/why-macro-argument-gets-evaluated/4811)

<div class="topic-metadata">

**Author:** [@ixsci](https://discourse.cmake.org/u/ixsci)\
**Replies:** 7\
**Last updated:** [January 11, 2022, 1:39pm UTC](https://discourse.cmake.org/t/why-macro-argument-gets-evaluated/4811 "2022-01-11T13:39:48Z")

</div>

Given the following simple code: set(var \[\[\\$\\{something\\}\]\]) function(print\_fun VAR) message("Fun: {${VAR}}") endfunction() macro(print\_mac VAR) message("Mac: {${VAR}}") endmacro() print\_fun("${var}") print\_mac…

---

## [Pass verbosity to custom/external commands? (ideally at build-time)](https://discourse.cmake.org/t/pass-verbosity-to-custom-external-commands-ideally-at-build-time/4809)

<div class="topic-metadata">

**Author:** [@rcoup](https://discourse.cmake.org/u/rcoup)\
**Replies:** 1\
**Last updated:** [January 10, 2022, 4:56pm UTC](https://discourse.cmake.org/t/pass-verbosity-to-custom-external-commands-ideally-at-build-time/4809 "2022-01-10T16:56:17Z")

</div>

With ExternalProject\_Add/add\_custom\_command/etc, what’s the best way to pass verbosity through as extra arguments? Ideally increasing build-time verbosity via make VERBOSE=1 or similar can also call some command --verbo…

---

## [How to direct FindX11 and FindOpenGL to look in specific directory](https://discourse.cmake.org/t/how-to-direct-findx11-and-findopengl-to-look-in-specific-directory/4790)

<div class="topic-metadata">

**Author:** [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)\
**Replies:** 4\
**Last updated:** [January 9, 2022, 9:54pm UTC](https://discourse.cmake.org/t/how-to-direct-findx11-and-findopengl-to-look-in-specific-directory/4790 "2022-01-09T21:54:47Z")

</div>

I am using cmake v 3.22.1. On our MacOS systems we want to use XQuartz for X11 and OpenGL includes and libs, which are installed in /opt/X11/include and /opt/X11/lib, respectively. My CMakeLists.txt calls FindOpenGL and…

---

## [Add external headers and sources](https://discourse.cmake.org/t/add-external-headers-and-sources/4789)

<div class="topic-metadata">

**Author:** [@bremenpl](https://discourse.cmake.org/u/bremenpl)\
**Replies:** 16\
**Last updated:** [January 9, 2022, 8:59pm UTC](https://discourse.cmake.org/t/add-external-headers-and-sources/4789 "2022-01-09T20:59:06Z")

</div>

Hello, I am trying to figure out how to include files into my project, that are outside of the project directory. The files structure on the system looks the following: So my CMakeLists.txt is in MyProject dir, whil…

---

## [Adding #include-depedencies from add\_custom\_command output to its input](https://discourse.cmake.org/t/adding-include-depedencies-from-add-custom-command-output-to-its-input/4787)

<div class="topic-metadata">

**Author:** [@EdGore](https://discourse.cmake.org/u/EdGore)\
**Replies:** 1\
**Last updated:** [January 6, 2022, 10:55pm UTC](https://discourse.cmake.org/t/adding-include-depedencies-from-add-custom-command-output-to-its-input/4787 "2022-01-06T22:55:28Z")

</div>

Hello! I use add\_custom\_command to generate C-Files during the build. (if it matters, it’s the Oracle Pro\*C precompiler) The input and the output file both have #include statements. (Pro\*C is just plain C plus inline …

---

## [Copying config-specific paths at build time](https://discourse.cmake.org/t/copying-config-specific-paths-at-build-time/4776)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 3\
**Last updated:** [January 5, 2022, 10:58pm UTC](https://discourse.cmake.org/t/copying-config-specific-paths-at-build-time/4776 "2022-01-05T22:58:02Z")

</div>

I’m trying to figure out how to optionally copy a directory, whose path depends on whether I’m doing a debug or release build, at build time (NOT install time, which is easy). By ‘optionally’, I mean copy the directory …

---

## [Importing dependencies for users of my library](https://discourse.cmake.org/t/importing-dependencies-for-users-of-my-library/4780)

<div class="topic-metadata">

**Author:** [@Dylan\_Reedy](https://discourse.cmake.org/u/Dylan_Reedy)\
**Replies:** 6\
**Last updated:** [January 5, 2022, 10:18pm UTC](https://discourse.cmake.org/t/importing-dependencies-for-users-of-my-library/4780 "2022-01-05T22:18:44Z")

</div>

Hi! I am trying to make my library user friendly, such that a user can import it as a target and link against it in a simple way. My library has a public 3rd party dependency that I can’t seem to configure quite right. …

---

## [find\_package in external project](https://discourse.cmake.org/t/find-package-in-external-project/4771)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 3\
**Last updated:** [January 5, 2022, 2:21am UTC](https://discourse.cmake.org/t/find-package-in-external-project/4771 "2022-01-05T02:21:09Z")

</div>

Is it possible to use find\_package from a component that is built as an external project? I believe find\_package is executed at configure time, but the cmake files required for find\_package are installed when external p…

---

## [find\_package() stops working when CMAKE\_SYSTEM\_NAME=iOS](https://discourse.cmake.org/t/find-package-stops-working-when-cmake-system-name-ios/4609)

<div class="topic-metadata">

**Author:** [@bblanchon](https://discourse.cmake.org/u/bblanchon)\
**Replies:** 8\
**Last updated:** [January 4, 2022, 2:20pm UTC](https://discourse.cmake.org/t/find-package-stops-working-when-cmake-system-name-ios/4609 "2022-01-04T14:20:02Z")

</div>

Hi, My problem concerns find\_package() in the “Config” mode. I created a PDFiumConfig.cmake and set the environment variable PDFium\_DIR to the correct directory. find\_package() works fine for all platforms except for …

---

## [How to properly include header files](https://discourse.cmake.org/t/how-to-properly-include-header-files/4762)

<div class="topic-metadata">

**Author:** [@kartachovd](https://discourse.cmake.org/u/kartachovd)\
**Replies:** 1\
**Last updated:** [January 4, 2022, 1:09pm UTC](https://discourse.cmake.org/t/how-to-properly-include-header-files/4762 "2022-01-04T13:09:31Z")

</div>

I’m so sorry if this has been asked before but I’ve scoured around and I can’t find a suitable answer for my question! Let’s say my project structure is as follows: Engine Components bunch of .h files Tools Vec…

---

## [cmake code generator language](https://discourse.cmake.org/t/cmake-code-generator-language/4747)

<div class="topic-metadata">

**Author:** [@Lawrence\_Ibarria](https://discourse.cmake.org/u/Lawrence_Ibarria)\
**Replies:** 4\
**Last updated:** [January 2, 2022, 7:31pm UTC](https://discourse.cmake.org/t/cmake-code-generator-language/4747 "2022-01-02T19:31:50Z")

</div>

In our C++ project we use something similar to google’s protocol buffers. That consists of a compiler and a source file, when the compiler runs the source generates a C header (optionally a C source) that later is used …

---

## [Exclude targets from "all" if they are incompatible with given CMAKE\_SYSTEM\_PROCESSOR?](https://discourse.cmake.org/t/exclude-targets-from-all-if-they-are-incompatible-with-given-cmake-system-processor/4760)

<div class="topic-metadata">

**Author:** [@carlosgalvezp](https://discourse.cmake.org/u/carlosgalvezp)\
**Replies:** 2\
**Last updated:** [January 2, 2022, 8:53am UTC](https://discourse.cmake.org/t/exclude-targets-from-all-if-they-are-incompatible-with-given-cmake-system-processor/4760 "2022-01-02T08:53:33Z")

</div>

Hi! I want to ask if there’s any neat solution to the following use case in CMake. I have a project that contains: x86-only code (e.g. google tests) arm-only code (e.g. low-level device drivers) generic code that is h…

---

## [add\_custom\_command OUTPUT problem (absolute path + ninja generator)](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727)

<div class="topic-metadata">

**Author:** [@mbee](https://discourse.cmake.org/u/mbee)\
**Replies:** 4\
**Last updated:** [December 23, 2021, 7:38pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727 "2021-12-23T19:38:48Z")

</div>

I’m creating custom commands with outputs, defined as: C:/Projects/git/\_obj/XXXX/gccarm/$\<IF:$\<CONFIG:RelWithDebInfo\>,Release,$\<CONFIG\>\>/BoardMix.hex This triggers the following ninja error: ninja : error : FindFirstF…

---

## [Cmake Build and test with Qt and google test](https://discourse.cmake.org/t/cmake-build-and-test-with-qt-and-google-test/4729)

<div class="topic-metadata">

**Author:** [@jkwok678](https://discourse.cmake.org/u/jkwok678)\
**Replies:** 3\
**Last updated:** [December 22, 2021, 11:05pm UTC](https://discourse.cmake.org/t/cmake-build-and-test-with-qt-and-google-test/4729 "2021-12-22T23:05:01Z")

</div>

I’m trying to build a Qt C++ Application with automated tests using google tests. What is going wrong right now? This is the CmakeList.txt in the /test directory. set( RBUILDTEST ${RBUILD}Tests ) file( GLOB TEST\_FILES…

---

## [Quirks in message(SEND\_ERROR)](https://discourse.cmake.org/t/quirks-in-message-send-error/4723)

<div class="topic-metadata">

**Author:** [@CaptainCrowbar](https://discourse.cmake.org/u/CaptainCrowbar)\
**Replies:** 1\
**Last updated:** [December 21, 2021, 12:30pm UTC](https://discourse.cmake.org/t/quirks-in-message-send-error/4723 "2021-12-21T12:30:28Z")

</div>

I have a Cmake function that looks like this (simplified for illustration): function(check\_file\_exists file url) find\_file(found ${file}) if(NOT found) message(SEND\_ERROR "File not found: ${file}\\nDownlo…

---

## [Disable compiler flag for external dependencies](https://discourse.cmake.org/t/disable-compiler-flag-for-external-dependencies/4717)

<div class="topic-metadata">

**Author:** [@Mint](https://discourse.cmake.org/u/Mint)\
**Replies:** 5\
**Last updated:** [December 21, 2021, 12:23pm UTC](https://discourse.cmake.org/t/disable-compiler-flag-for-external-dependencies/4717 "2021-12-21T12:23:10Z")

</div>

Hello, I am trying to compile my c++ source files with certain gcc compiler flags (namely -Wall), but not external libs. But I can’t figure out how to achieve this. I have this mock setup for my cmakelists project file: …

---

## [set\_target\_properties neither finds .lib file nor header files and doesn't link library correctly](https://discourse.cmake.org/t/set-target-properties-neither-finds-lib-file-nor-header-files-and-doesnt-link-library-correctly/4715)

<div class="topic-metadata">

**Author:** [@fschutt](https://discourse.cmake.org/u/fschutt)\
**Replies:** 1\
**Last updated:** [December 21, 2021, 12:21pm UTC](https://discourse.cmake.org/t/set-target-properties-neither-finds-lib-file-nor-header-files-and-doesnt-link-library-correctly/4715 "2021-12-21T12:21:39Z")

</div>

I’m currently trying to use a DLL library written in Rust from C++ with cmake. The output from Rust is a .dll and a .dll.lib file (for linking). I’ve generated a C header file and created a new project with cmake-init. M…

---

## [Generate code from code?](https://discourse.cmake.org/t/generate-code-from-code/4700)

<div class="topic-metadata">

**Author:** [@clevijoki](https://discourse.cmake.org/u/clevijoki)\
**Replies:** 1\
**Last updated:** [December 21, 2021, 12:14pm UTC](https://discourse.cmake.org/t/generate-code-from-code/4700 "2021-12-21T12:14:53Z")

</div>

What I want to do is add a custom command that runs on all of the source/dependencies of a target. So I want to know all the .c/.cpp and indirectly referenced .h files to generate code, which would also have to be compi…

---

## [How to set -dynamic-linker from the outside?](https://discourse.cmake.org/t/how-to-set-dynamic-linker-from-the-outside/4659)

<div class="topic-metadata">

**Author:** [@Adam\_Badura](https://discourse.cmake.org/u/Adam_Badura)\
**Replies:** 7\
**Last updated:** [December 17, 2021, 7:20am UTC](https://discourse.cmake.org/t/how-to-set-dynamic-linker-from-the-outside/4659 "2021-12-17T07:20:33Z")

</div>

Our project is compiled using various systems (like Yocto, home-grown a’la Maven, etc.) for different platforms, including both native (for example run tests) and target machines (cross-compilation). One of the challeng…

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

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