# Code

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

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

**Page:** 71

---

## [add\_custom\_command converting my absolute executable path to relative?](https://discourse.cmake.org/t/add-custom-command-converting-my-absolute-executable-path-to-relative/1326)

<div class="topic-metadata">

**Author:** [@Paul\_Belanger](https://discourse.cmake.org/u/Paul_Belanger)\
**Replies:** 5\
**Last updated:** [June 4, 2020, 4:46pm UTC](https://discourse.cmake.org/t/add-custom-command-converting-my-absolute-executable-path-to-relative/1326 "2020-06-04T16:46:13Z")

</div>

As part of the configuration stage of my project, I create a small executable program somewhere in the CMAKE\_BINARY\_DIR tree. I’m then trying to use that program as part of an ‘add\_custom\_command’ call to generate some s…

---

## [Macro unrecognized when compiling assembly code](https://discourse.cmake.org/t/macro-unrecognized-when-compiling-assembly-code/472)

<div class="topic-metadata">

**Author:** [@skulkarni](https://discourse.cmake.org/u/skulkarni)\
**Replies:** 5\
**Last updated:** [June 4, 2020, 12:54pm UTC](https://discourse.cmake.org/t/macro-unrecognized-when-compiling-assembly-code/472 "2020-06-04T12:54:49Z")

</div>

Hi, When compiling assembly code the macro is not recognized and throwing up error. \[ 85%\] Building ASM object BLE/nRF52/modules/CMakeFiles/MODULES.dir/nrfx/mdk/gcc\_startup\_nrf52.S.obj D:XXXX\\gcc\_7\_2\_1\\tools\\bin\\arm-n…

---

## [file GET\_RUNTIME\_DEPENDENCIES picks up incorrect shared objects](https://discourse.cmake.org/t/file-get-runtime-dependencies-picks-up-incorrect-shared-objects/1314)

<div class="topic-metadata">

**Author:** [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Replies:** 10\
**Last updated:** [June 4, 2020, 1:06am UTC](https://discourse.cmake.org/t/file-get-runtime-dependencies-picks-up-incorrect-shared-objects/1314 "2020-06-04T01:06:15Z")

</div>

file (GET\_RUNTIME\_DEPENDENCIES ) returns incorrect dependencies to /usr/lib instead of /usr/lib64 on Linux. Examples are libstdc++.so, libX11.so The cmake documentation states that libraries are searched on paths retur…

---

## [Overriding CMAKE\_CXX\_COMPILER with VS2017 on Windows 10](https://discourse.cmake.org/t/overriding-cmake-cxx-compiler-with-vs2017-on-windows-10/1311)

<div class="topic-metadata">

**Author:** [@dr-traktor](https://discourse.cmake.org/u/dr-traktor)\
**Replies:** 1\
**Last updated:** [June 3, 2020, 6:55pm UTC](https://discourse.cmake.org/t/overriding-cmake-cxx-compiler-with-vs2017-on-windows-10/1311 "2020-06-03T18:55:14Z")

</div>

Is there a way to specify a custom compiler on Windows 10 using Visual Studio 2017, and not use the one inside the VS2017 installation? Below are my attempts to do so. Using CMake 3.17.3 on Windows 10 and Visual Stud…

---

## [Intended way to interface with external targets(?)](https://discourse.cmake.org/t/intended-way-to-interface-with-external-targets/1099)

<div class="topic-metadata">

**Author:** [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)\
**Replies:** 1\
**Last updated:** [June 3, 2020, 3:11pm UTC](https://discourse.cmake.org/t/intended-way-to-interface-with-external-targets/1099 "2020-06-03T15:11:35Z")

</div>

I have a project with a similar structure ├── external │ ├── ext │ ├── glew │ └── opencv └── src And I’ve never felt like I correctly integrate CMake projects from my external directory with my source. I usually …

---

## [CMake Pre-Build command](https://discourse.cmake.org/t/cmake-pre-build-command/1083)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 17\
**Last updated:** [June 2, 2020, 11:44am UTC](https://discourse.cmake.org/t/cmake-pre-build-command/1083 "2020-06-02T11:44:33Z")

</div>

I am trying to have a formatting tool (AStyle) run before building a given target. There is the add\_custom\_command that can be associated with a target and specified as PRE\_BUILD. Unfortunately, this doesn’t work with M…

---

## [Dependency Management via CPack and dpkg-shlipdeps](https://discourse.cmake.org/t/dependency-management-via-cpack-and-dpkg-shlipdeps/1282)

<div class="topic-metadata">

**Author:** [@MRocholl](https://discourse.cmake.org/u/MRocholl)\
**Replies:** 0\
**Last updated:** [May 28, 2020, 2:25pm UTC](https://discourse.cmake.org/t/dependency-management-via-cpack-and-dpkg-shlipdeps/1282 "2020-05-28T14:25:49Z")

</div>

Hello, I am trying to package several cpp libraries as DEB packages that depend on each other. E.g. I have libA that depends on libB(\>=2.0.0), libB does not depend on any other library. Lib B is a package of its own …

---

## [set output directory for your binaries](https://discourse.cmake.org/t/set-output-directory-for-your-binaries/1278)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 4\
**Last updated:** [May 28, 2020, 7:29am UTC](https://discourse.cmake.org/t/set-output-directory-for-your-binaries/1278 "2020-05-28T07:29:08Z")

</div>

I want to define the output path in which my binary is going to be created. It should reflect the behaviour of CMake build in functions. Variants which exist only for historical reasons are not being considered. here is…

---

## [Toolchains: Multiple files generated by add\_executable](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161)

<div class="topic-metadata">

**Author:** [@Lectem](https://discourse.cmake.org/u/Lectem)\
**Replies:** 9\
**Last updated:** [May 23, 2020, 2:55pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161 "2020-05-23T14:55:27Z")

</div>

Is it possible to tell cmake that the toolchain will generate multiple files for executables? I’m thinking more specifically about emscripten which (might, depending on compile flags) generate both .js and .wasm files f…

---

## [ExternalProject\_Add fails to extract kexec-tools-2.0.17.tar.xz](https://discourse.cmake.org/t/externalproject-add-fails-to-extract-kexec-tools-2-0-17-tar-xz/1251)

<div class="topic-metadata">

**Author:** [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Replies:** 3\
**Last updated:** [May 23, 2020, 12:03pm UTC](https://discourse.cmake.org/t/externalproject-add-fails-to-extract-kexec-tools-2-0-17-tar-xz/1251 "2020-05-23T12:03:12Z")

</div>

I’m using ExternalProject\_Add with download parameters below: URL https://projects.horms.net/projects/kexec/kexec-tools/kexec-tools-2.0.17.tar.xz URL\_MD5 f72c11e3bd80de23cae144ce8683d96b I’m getting the following erro…

---

## [CMake variables in CTest?](https://discourse.cmake.org/t/cmake-variables-in-ctest/1244)

<div class="topic-metadata">

**Author:** [@dbahadir](https://discourse.cmake.org/u/dbahadir)\
**Replies:** 3\
**Last updated:** [May 20, 2020, 5:21pm UTC](https://discourse.cmake.org/t/cmake-variables-in-ctest/1244 "2020-05-20T17:21:30Z")

</div>

I am currently playing around with generating CTest scripts and running these using ctest. In one of those scripts I wanted to create a directory and thought I would be nice and use a platform agnostic approach: execut…

---

## [PLATFORM\_ID vs. WIN32 vs. CMAKE\_SYSTEM\_NAME](https://discourse.cmake.org/t/platform-id-vs-win32-vs-cmake-system-name/1226)

<div class="topic-metadata">

**Author:** [@ocroquette](https://discourse.cmake.org/u/ocroquette)\
**Replies:** 2\
**Last updated:** [May 19, 2020, 9:55pm UTC](https://discourse.cmake.org/t/platform-id-vs-win32-vs-cmake-system-name/1226 "2020-05-19T21:55:25Z")

</div>

Hi, I am bit confused about which of PLATFORM\_ID vs. WIN32 vs. CMAKE\_SYSTEM\_NAME to use. My build system supports Windows and macOS, so it looks like: for normal branching in the CMake scripts, I have the choice betw…

---

## [How to use LLVM's IR files as sources](https://discourse.cmake.org/t/how-to-use-llvms-ir-files-as-sources/1202)

<div class="topic-metadata">

**Author:** [@irinayat](https://discourse.cmake.org/u/irinayat)\
**Replies:** 1\
**Last updated:** [May 14, 2020, 7:49pm UTC](https://discourse.cmake.org/t/how-to-use-llvms-ir-files-as-sources/1202 "2020-05-14T19:49:09Z")

</div>

Hello! I need to include a few manually authored LLVM’s IR files into my CMake project. Clang supports mixing bc, ll and cpp files when compiling a binary, however, when I list the bitcode files in add\_executable/add\_lib…

---

## [Functions with sub-options](https://discourse.cmake.org/t/functions-with-sub-options/1206)

<div class="topic-metadata">

**Author:** [@Mellon](https://discourse.cmake.org/u/Mellon)\
**Replies:** 4\
**Last updated:** [May 14, 2020, 7:46pm UTC](https://discourse.cmake.org/t/functions-with-sub-options/1206 "2020-05-14T19:46:15Z")

</div>

Hi all, I’m would like to have a function that works as follows: foo(\<name\> SCHEMA \<path\> \[DEPENDS \<dependency\> ...\] \[SCHEMA \<path\> \[DEPENDS ...\] ...\]) that means, needs at least one SCHEMA with associated optional DE…

---

## [add\_custom\_command at the top level directory](https://discourse.cmake.org/t/add-custom-command-at-the-top-level-directory/1210)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 1\
**Last updated:** [May 14, 2020, 10:53am UTC](https://discourse.cmake.org/t/add-custom-command-at-the-top-level-directory/1210 "2020-05-14T10:53:03Z")

</div>

I would like to iterate all my project targets with top level scripts. Then, I would like to add pre-build steps for all of them using add\_custom\_command. I realize that by default in newer versions of cmake this does no…

---

## [Is there a way to implement a feature similar to CMAKE\_MY\_VAR for setting properties?](https://discourse.cmake.org/t/is-there-a-way-to-implement-a-feature-similar-to-cmake-my-var-for-setting-properties/1196)

<div class="topic-metadata">

**Author:** [@alcroito](https://discourse.cmake.org/u/alcroito)\
**Replies:** 6\
**Last updated:** [May 13, 2020, 12:38pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-implement-a-feature-similar-to-cmake-my-var-for-setting-properties/1196 "2020-05-13T12:38:11Z")

</div>

To disable some compile flags based on a target property, consumers of my library have to do something like the following: find\_package(Mylib) add\_executable(app\_target) target\_link\_libraries(app\_target INTERFACE mylib:…

---

## [find\_package doesn't look in default suffixes until enabling a language](https://discourse.cmake.org/t/find-package-doesnt-look-in-default-suffixes-until-enabling-a-language/1198)

<div class="topic-metadata">

**Author:** [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Replies:** 6\
**Last updated:** [May 12, 2020, 5:35pm UTC](https://discourse.cmake.org/t/find-package-doesnt-look-in-default-suffixes-until-enabling-a-language/1198 "2020-05-12T17:35:51Z")

</div>

Hi, I’ve got a bit of an unusual problem. I have a package that ships a C++ compiler wrapper. And it’s not one of those cheesy compiler wrappers that is just used because nobody knows how packaging works. It’s actually …

---

## [The FindGLEW.cmake module does not set GLEW\_LIBRARIES in some cases](https://discourse.cmake.org/t/the-findglew-cmake-module-does-not-set-glew-libraries-in-some-cases/989)

<div class="topic-metadata">

**Author:** [@geoffmcl](https://discourse.cmake.org/u/geoffmcl)\
**Replies:** 13\
**Last updated:** [May 12, 2020, 3:42pm UTC](https://discourse.cmake.org/t/the-findglew-cmake-module-does-not-set-glew-libraries-in-some-cases/989 "2020-05-12T15:42:04Z")

</div>

This is my first post here, and maybe this problem should be posted elsewhere… If the cmake find\_package(GLEW) finds lib/cmake/glew/glew-config.cmake, etc, it FAILS to set GLEW\_LIBRARIES… It does however set GLEW\_LIBRA…

---

## [VS generator and toolchain files](https://discourse.cmake.org/t/vs-generator-and-toolchain-files/1177)

<div class="topic-metadata">

**Author:** [@Lectem](https://discourse.cmake.org/u/Lectem)\
**Replies:** 2\
**Last updated:** [May 11, 2020, 5:54pm UTC](https://discourse.cmake.org/t/vs-generator-and-toolchain-files/1177 "2020-05-11T17:54:54Z")

</div>

I was trying to use the Emscripten.cmake toolchain file with the Visual Studio generator, but it seems it still tries to use CL.exe and LINK.exe. Is this a limitation of the generator? It works fine with make and ninja. …

---

## [Pass argument directly to the compiler](https://discourse.cmake.org/t/pass-argument-directly-to-the-compiler/1181)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 3\
**Last updated:** [May 11, 2020, 5:24pm UTC](https://discourse.cmake.org/t/pass-argument-directly-to-the-compiler/1181 "2020-05-11T17:24:58Z")

</div>

Effectively, I want to pass the actual compiler as an argument to my stub compiler. Having the CMAKE\_CXX\_COMPILER variable set by a toolchain file previously, I would like to do set(CMAKE\_CXX\_COMPILER "/usr/bin/imposte…

---

## [Static libraries and loadable modules](https://discourse.cmake.org/t/static-libraries-and-loadable-modules/1176)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 1\
**Last updated:** [May 11, 2020, 4:39pm UTC](https://discourse.cmake.org/t/static-libraries-and-loadable-modules/1176 "2020-05-11T16:39:10Z")

</div>

I am working on a library with a plugin system that currently works by having a plugin register itself on load. An app links with this library, as does the plugin. When BUILD\_SHARED\_LIBS=ON, the plugin loads correctly, b…

---

## [CMAKE\_DL\_LIBS](https://discourse.cmake.org/t/cmake-dl-libs/1159)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 4\
**Last updated:** [May 8, 2020, 8:16am UTC](https://discourse.cmake.org/t/cmake-dl-libs/1159 "2020-05-08T08:16:27Z")

</div>

What is the intended way of using CMAKE\_DL\_LIBS? Unlike most libraries in CMake, there doesn’t seem to be an imported target for it. In particular, if I have a library that has an interface dependency on CMAKE\_DL\_LIBS o…

---

## [Tutorial Step 5: log and exp not found](https://discourse.cmake.org/t/tutorial-step-5-log-and-exp-not-found/636)

<div class="topic-metadata">

**Author:** [@IronMoose](https://discourse.cmake.org/u/IronMoose)\
**Replies:** 7\
**Last updated:** [May 7, 2020, 7:10pm UTC](https://discourse.cmake.org/t/tutorial-step-5-log-and-exp-not-found/636 "2020-05-07T19:10:59Z")

</div>

Hello. I’m a bit stuck on step 5 of the CMake tutorial. Specifically, when I build the project I get: Looking for log Looking for log - not found Looking for exp Looking for exp - not found Configuring done Generat…

---

## [How to defer to to package's config file when it exists](https://discourse.cmake.org/t/how-to-defer-to-to-packages-config-file-when-it-exists/1154)

<div class="topic-metadata">

**Author:** [@AndrewGaspar](https://discourse.cmake.org/u/AndrewGaspar)\
**Replies:** 1\
**Last updated:** [May 6, 2020, 4:58pm UTC](https://discourse.cmake.org/t/how-to-defer-to-to-packages-config-file-when-it-exists/1154 "2020-05-06T16:58:28Z")

</div>

I have a dependency that now installs a FooConfig.cmake package configuration, but previously I had to provide my own FindFoo.cmake file to find the dependency. I’d like to support older versions of the dependency, too. …

---

## [Gathering transitive shared libraries](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100)

<div class="topic-metadata">

**Author:** [@UebelAndre](https://discourse.cmake.org/u/UebelAndre)\
**Replies:** 2\
**Last updated:** [April 25, 2020, 1:45pm UTC](https://discourse.cmake.org/t/gathering-transitive-shared-libraries/1100 "2020-04-25T13:45:46Z")

</div>

How would one go about gathering all the shared libraries (.dll's) for a given target and making sure they’re copied into its runtime/output directory? As an example, see the diagram below. executable ├── shared\_lib ├─…

---

## [CMake Generator Expression IN\_LIST](https://discourse.cmake.org/t/cmake-generator-expression-in-list/1145)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 4\
**Last updated:** [May 5, 2020, 3:36pm UTC](https://discourse.cmake.org/t/cmake-generator-expression-in-list/1145 "2020-05-05T15:36:59Z")

</div>

I have the following CMake setup which is not including the sources as expected. (PLATFORM is set to by a toolchain file, note I’m not using CMAKE\_SYSTEM\_NAME because one of my platforms (not listed below) isn’t supporte…

---

## [Set Definitions for external sub directory](https://discourse.cmake.org/t/set-definitions-for-external-sub-directory/1136)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 7\
**Last updated:** [May 4, 2020, 1:12pm UTC](https://discourse.cmake.org/t/set-definitions-for-external-sub-directory/1136 "2020-05-04T13:12:05Z")

</div>

I am adding google test to my project as a sub directory. Is there a better way to add defines to just that subdirectory rather than… add\_definitions(-DGTEST\_HAS\_PTHREAD=0) add\_subdirectory(googletest) remove\_definition…

---

## [FindJNI and libjsig](https://discourse.cmake.org/t/findjni-and-libjsig/1070)

<div class="topic-metadata">

**Author:** [@Joe\_Burzinski](https://discourse.cmake.org/u/Joe_Burzinski)\
**Replies:** 2\
**Last updated:** [May 1, 2020, 2:46pm UTC](https://discourse.cmake.org/t/findjni-and-libjsig/1070 "2020-05-01T14:46:27Z")

</div>

How come the FindJNI module doesn’t expose libjsig for linking? libjsig is needed if any other part of the program overrides the signal handlers for SIGSEGV and a couple others. See https://docs.oracle.com/javase/8/docs/…

---

## [Possible to create a Python virtual env from CMake and then find it with FindPython3?](https://discourse.cmake.org/t/possible-to-create-a-python-virtual-env-from-cmake-and-then-find-it-with-findpython3/1132)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 1\
**Last updated:** [May 1, 2020, 9:00am UTC](https://discourse.cmake.org/t/possible-to-create-a-python-virtual-env-from-cmake-and-then-find-it-with-findpython3/1132 "2020-05-01T09:00:21Z")

</div>

It’s basically all in the title. My project ships with a requirements.txt that lists a set of dependencies that need to be present to test the bindings to the C++ library I’m building. I would like to be able to perform…

---

## [How to share common cmake properties between exes?](https://discourse.cmake.org/t/how-to-share-common-cmake-properties-between-exes/1120)

<div class="topic-metadata">

**Author:** [@Greg](https://discourse.cmake.org/u/Greg)\
**Replies:** 7\
**Last updated:** [April 30, 2020, 12:26am UTC](https://discourse.cmake.org/t/how-to-share-common-cmake-properties-between-exes/1120 "2020-04-30T00:26:58Z")

</div>

My project is not large, but we do build about 100 executables. These executables come in a handful of different types: daemons, tools, tests, filters, etc. Usually, all the executable targets of a certain type share …

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

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