# Code

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

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

**Page:** 75

---

## [Tutorial Step 9 error](https://discourse.cmake.org/t/tutorial-step-9-error/533)

<div class="topic-metadata">

**Author:** [@mrichter](https://discourse.cmake.org/u/mrichter)\
**Replies:** 2\
**Last updated:** [January 22, 2020, 9:55pm UTC](https://discourse.cmake.org/t/tutorial-step-9-error/533 "2020-01-22T21:55:42Z")

</div>

Hello again. In setting up to build for step 9 of the online tutorial, I Get a different error than theone the tutorial says I should expect. I followed all the sintructions given up to the point wehre it says what sho…

---

## [Add include files for Github ExternalProject library](https://discourse.cmake.org/t/add-include-files-for-github-externalproject-library/529)

<div class="topic-metadata">

**Author:** [@prex](https://discourse.cmake.org/u/prex)\
**Replies:** 7\
**Last updated:** [January 22, 2020, 4:12pm UTC](https://discourse.cmake.org/t/add-include-files-for-github-externalproject-library/529 "2020-01-22T16:12:43Z")

</div>

I’m running out of ideas how to fix this. I have a CMakeList used by the catkin\_tools (ROS) build system. Furthermore, I’m using catkin\_simple, which defines some macros. However, the problem I have is more related to th…

---

## [Help for integrating an CppTranspiler](https://discourse.cmake.org/t/help-for-integrating-an-cpptranspiler/527)

<div class="topic-metadata">

**Author:** [@freylax](https://discourse.cmake.org/u/freylax)\
**Replies:** 1\
**Last updated:** [January 20, 2020, 4:54pm UTC](https://discourse.cmake.org/t/help-for-integrating-an-cpptranspiler/527 "2020-01-20T16:54:28Z")

</div>

I need Help for integrating an Cpp Transpiler (Purescript to cpp see purescript-native-build. The custom command has the characteristics that it works on a set of input files and will produce an set of output files. If o…

---

## [Tutorial Step 5 does not work as presented](https://discourse.cmake.org/t/tutorial-step-5-does-not-work-as-presented/507)

<div class="topic-metadata">

**Author:** [@mrichter](https://discourse.cmake.org/u/mrichter)\
**Replies:** 7\
**Last updated:** [January 16, 2020, 1:11am UTC](https://discourse.cmake.org/t/tutorial-step-5-does-not-work-as-presented/507 "2020-01-16T01:11:50Z")

</div>

I’m really new to CMake, and I’ve been following the tutorial at https://cmake.org/cmake/help/latest/guide/tutorial/index.html#adding-system-introspection-step-5. The instructions for running step 5 do not work. For on…

---

## [Re-export private compile definitions as interface definitions (cmake 3.12)](https://discourse.cmake.org/t/re-export-private-compile-definitions-as-interface-definitions-cmake-3-12/498)

<div class="topic-metadata">

**Author:** [@reuk](https://discourse.cmake.org/u/reuk)\
**Replies:** 5\
**Last updated:** [January 15, 2020, 3:34pm UTC](https://discourse.cmake.org/t/re-export-private-compile-definitions-as-interface-definitions-cmake-3-12/498 "2020-01-15T15:34:08Z")

</div>

Given the following CMakeLists, I would expect the ‘genexdebug’ target to print out “foo bar” when run, but it only prints “foo”. Can anyone tell me why? What’s the best way to check for specific private definitions, and…

---

## [How to set option to a library but only when used by examples](https://discourse.cmake.org/t/how-to-set-option-to-a-library-but-only-when-used-by-examples/481)

<div class="topic-metadata">

**Author:** [@inetic](https://discourse.cmake.org/u/inetic)\
**Replies:** 2\
**Last updated:** [January 15, 2020, 9:35am UTC](https://discourse.cmake.org/t/how-to-set-option-to-a-library-but-only-when-used-by-examples/481 "2020-01-15T09:35:53Z")

</div>

I have a CMake project that is a library that also adds an example. Something like this /example/ -\> myexample.cpp -\> CMakeLists.txt /include/ -\> mylib.h /src/ -\> mylib.cpp /CMakeLists.txt My /CMakeLists.txt looks …

---

## [Compiling ARM64 ASM in Visual Studio with CMake](https://discourse.cmake.org/t/compiling-arm64-asm-in-visual-studio-with-cmake/500)

<div class="topic-metadata">

**Author:** [@mlindgren](https://discourse.cmake.org/u/mlindgren)\
**Replies:** 0\
**Last updated:** [January 14, 2020, 9:57pm UTC](https://discourse.cmake.org/t/compiling-arm64-asm-in-visual-studio-with-cmake/500 "2020-01-14T21:57:08Z")

</div>

Hi folks, I’m working on a cross-platform project which has some hand-written assembly to optimize performance for various CPU architectures. I’m converting this project to CMake from a proprietary build system, startin…

---

## [Get complete compile flags for a target](https://discourse.cmake.org/t/get-complete-compile-flags-for-a-target/485)

<div class="topic-metadata">

**Author:** [@DKB](https://discourse.cmake.org/u/DKB)\
**Replies:** 3\
**Last updated:** [January 14, 2020, 5:31pm UTC](https://discourse.cmake.org/t/get-complete-compile-flags-for-a-target/485 "2020-01-14T17:31:21Z")

</div>

I have a number of legacy Makefiles I am using through add\_custom\_command to produce libraries and executables as we slowly port to CMake. One issue I’m having is dealing with the CXX and CUDA target compile flags propag…

---

## [CMakeLists.txt : Link options not working properly](https://discourse.cmake.org/t/cmakelists-txt-link-options-not-working-properly/489)

<div class="topic-metadata">

**Author:** [@sramnath](https://discourse.cmake.org/u/sramnath)\
**Replies:** 0\
**Last updated:** [January 13, 2020, 10:14pm UTC](https://discourse.cmake.org/t/cmakelists-txt-link-options-not-working-properly/489 "2020-01-13T22:14:28Z")

</div>

Hello, I am using the TI-CGT compiler and have been successful in getting all my source files to compile. However, I am unable to get the link command to successfully link, and I have crafted a manual link command whi…

---

## [How do I create multiple installation targets?](https://discourse.cmake.org/t/how-do-i-create-multiple-installation-targets/475)

<div class="topic-metadata">

**Author:** [@xfbs](https://discourse.cmake.org/u/xfbs)\
**Replies:** 3\
**Last updated:** [January 13, 2020, 1:27pm UTC](https://discourse.cmake.org/t/how-do-i-create-multiple-installation-targets/475 "2020-01-13T13:27:18Z")

</div>

Hey there. I am rewriting some build system for a larger project. Currently, we have multiple targets to install different components (install\_lib, install\_hdr, install\_data, etc). We need this because we generate differ…

---

## [Qt5 component library not copied to CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 8\
**Last updated:** [January 8, 2020, 11:33am UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461 "2020-01-08T11:33:46Z")

</div>

Under Windows, CMake sees the following: set(CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY ${PROJECT\_BINARY\_DIR}/bin/$\<CONFIG\>) find\_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Network Concurrent) target\_link\_libraries(mylib …

---

## [How to print location of Qt5 component library?](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 7\
**Last updated:** [January 7, 2020, 6:47pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462 "2020-01-07T18:47:46Z")

</div>

CMake code find\_package(HDF5 MODULE REQUIRED COMPONENTS CXX) message(STATUS "hdf5: VERSION=${HDF5\_VERSION}, LIB=${HDF5\_LIBRARIES}) results in informative output like -- hdf5: VERSION=1.10.4, LIB=/usr/lib/x86\_64-linux-…

---

## [Generated libraries, not sources.](https://discourse.cmake.org/t/generated-libraries-not-sources/458)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 2\
**Last updated:** [January 7, 2020, 4:57pm UTC](https://discourse.cmake.org/t/generated-libraries-not-sources/458 "2020-01-07T16:57:06Z")

</div>

We are trying to move our build system from GNU Make to CMake and have run into issues defining an unconventional part of our build. This pattern repeats itself multiple places, so it would be useful to write a function …

---

## [How to limit the scope of compiler flags only to a (my) local library?](https://discourse.cmake.org/t/how-to-limit-the-scope-of-compiler-flags-only-to-a-my-local-library/457)

<div class="topic-metadata">

**Author:** [@discovery](https://discourse.cmake.org/u/discovery)\
**Replies:** 7\
**Last updated:** [January 7, 2020, 3:22pm UTC](https://discourse.cmake.org/t/how-to-limit-the-scope-of-compiler-flags-only-to-a-my-local-library/457 "2020-01-07T15:22:11Z")

</div>

1 I am trying the example below : add\_library( mylib src/my\_code.cpp) target\_include\_directories(mylib PUBLIC include ${catkin\_INCLUDE\_DIRS} ${thirdPartyLib\_INCLUDE\_DIRS}) add\_dependencies( …

---

## [is not a full path to an existing compiler tool](https://discourse.cmake.org/t/is-not-a-full-path-to-an-existing-compiler-tool/436)

<div class="topic-metadata">

**Author:** [@skulkarni](https://discourse.cmake.org/u/skulkarni)\
**Replies:** 7\
**Last updated:** [January 3, 2020, 6:27am UTC](https://discourse.cmake.org/t/is-not-a-full-path-to-an-existing-compiler-tool/436 "2020-01-03T06:27:16Z")

</div>

Hi I am new to Cmake. I have installed Cmake tool and downloaded gcc-arm-none-eabi. Below settings I have done in my cmake file set(ARM\_NONE\_EABI\_TOOLCHAIN\_PATH “C:/Users/XXXXX/binaries/gcc-arm-none-eabi/bin”) Also I…

---

## [Escaping semicolons in CMAKE\_CONFIGURE\_DEPENDS?](https://discourse.cmake.org/t/escaping-semicolons-in-cmake-configure-depends/447)

<div class="topic-metadata">

**Author:** [@spinda](https://discourse.cmake.org/u/spinda)\
**Replies:** 6\
**Last updated:** [January 2, 2020, 10:26pm UTC](https://discourse.cmake.org/t/escaping-semicolons-in-cmake-configure-depends/447 "2020-01-02T22:26:49Z")

</div>

The documentation for CMAKE\_CONFIGURE\_DEPENDS states: Specify files as a semicolon-separated list of paths. Relative paths are interpreted as relative to the current source directory. What should I do when the path i…

---

## [Linkage of libcublasLt.so from CUDA\_TOOLKIT\_ROOT\_DIR/lib64](https://discourse.cmake.org/t/linkage-of-libcublaslt-so-from-cuda-toolkit-root-dir-lib64/438)

<div class="topic-metadata">

**Author:** [@cponder](https://discourse.cmake.org/u/cponder)\
**Replies:** 7\
**Last updated:** [December 31, 2019, 10:11pm UTC](https://discourse.cmake.org/t/linkage-of-libcublaslt-so-from-cuda-toolkit-root-dir-lib64/438 "2019-12-31T22:11:22Z")

</div>

I’m building a library that depends on CUDA & cuBLAS. A peculiarity I’m seeing is that the paths are resolved for the CUDA & cuBLAS libraries --\> ldd libCUDA-SGEMM.so linux-vdso.so.1 (0x00007ffda4173000) libcuda.s…

---

## [Build explicit target with ExternalProject](https://discourse.cmake.org/t/build-explicit-target-with-externalproject/442)

<div class="topic-metadata">

**Author:** [@MBZ](https://discourse.cmake.org/u/MBZ)\
**Replies:** 3\
**Last updated:** [December 30, 2019, 2:08pm UTC](https://discourse.cmake.org/t/build-explicit-target-with-externalproject/442 "2019-12-30T14:08:45Z")

</div>

How do I build specific target with ExternalProject ? scenario 1: my external project has few targets and I would like to build only on of them scenario 2: the targets in my external project has EXCLUDE\_FROM\_ALL so I m…

---

## [FetchContent\_Declare not recognized](https://discourse.cmake.org/t/fetchcontent-declare-not-recognized/443)

<div class="topic-metadata">

**Author:** [@adamvm](https://discourse.cmake.org/u/adamvm)\
**Replies:** 2\
**Last updated:** [December 30, 2019, 1:48pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-not-recognized/443 "2019-12-30T13:48:59Z")

</div>

Hello, I added gtest based on : https://kubasejdak.com/19-reasons-why-cmake-is-actually-awesome#4-cmake-allows-easy-external-project-download-and-incorporation so head of my CMakeLists.txt looks: cmake\_minimum\_required…

---

## [Directly invoke the linker](https://discourse.cmake.org/t/directly-invoke-the-linker/433)

<div class="topic-metadata">

**Author:** [@Acsor](https://discourse.cmake.org/u/Acsor)\
**Replies:** 7\
**Last updated:** [December 26, 2019, 5:35pm UTC](https://discourse.cmake.org/t/directly-invoke-the-linker/433 "2019-12-26T17:35:25Z")

</div>

I am setting up a cross-compiling C project targeting two micro architectures, inspired by ARM and MIPS. Without loss of generality, I’ll focus on the micro ARM architecture, where the compile instructions I was given ar…

---

## [Linking multiarch libraries in cross-compilation toolchain](https://discourse.cmake.org/t/linking-multiarch-libraries-in-cross-compilation-toolchain/415)

<div class="topic-metadata">

**Author:** [@tambre](https://discourse.cmake.org/u/tambre)\
**Replies:** 6\
**Last updated:** [December 19, 2019, 12:52pm UTC](https://discourse.cmake.org/t/linking-multiarch-libraries-in-cross-compilation-toolchain/415 "2019-12-19T12:52:32Z")

</div>

I’m creating a toolchain for cross-compiling on x64 for an ARM64 device. I find some libraries using PkgConfig in the actual application and in the final linking command they’re linked like -lglib-2.0. Unfortunately thi…

---

## [How to automatically add header and source files to executable without file(GLOB )?](https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395)

<div class="topic-metadata">

**Author:** [@waxta](https://discourse.cmake.org/u/waxta)\
**Replies:** 1\
**Last updated:** [December 17, 2019, 5:08pm UTC](https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395 "2019-12-17T17:08:39Z")

</div>

Hello. For now, I use file(GLOB\_RECURSE source\_list "\*.cpp" "\*.h") in order to automatically add new files to project. I work with Clion and it “doesn’t like” this function. I mean, when I want to generate function’s def…

---

## [How to import from build tree? (Answered)](https://discourse.cmake.org/t/how-to-import-from-build-tree-answered/392)

<div class="topic-metadata">

**Author:** [@Javier\_Gutierrez](https://discourse.cmake.org/u/Javier_Gutierrez)\
**Replies:** 1\
**Last updated:** [December 17, 2019, 3:00pm UTC](https://discourse.cmake.org/t/how-to-import-from-build-tree-answered/392 "2019-12-17T15:00:52Z")

</div>

Hello there, It took me more time than expected to find out how to “import” an export file that I created with the export from a build tree approach. That is using the export() command. I learned how to export from a b…

---

## [macOS copy dependency to package](https://discourse.cmake.org/t/macos-copy-dependency-to-package/349)

<div class="topic-metadata">

**Author:** [@baschdel\_98](https://discourse.cmake.org/u/baschdel_98)\
**Replies:** 1\
**Last updated:** [December 16, 2019, 9:29pm UTC](https://discourse.cmake.org/t/macos-copy-dependency-to-package/349 "2019-12-16T21:29:12Z")

</div>

Hello there, I have a small problem with c++ cmake on OSX. I am writing an application that depends on Qt, Curl, and FFmpeg. I am able to build the application I am able to create a \*.app directory I am able to creat…

---

## [Why does source file try\_compile not propagate CMAKE\_TOOLCHAIN\_FILE to the generated project?](https://discourse.cmake.org/t/why-does-source-file-try-compile-not-propagate-cmake-toolchain-file-to-the-generated-project/275)

<div class="topic-metadata">

**Author:** [@alcroito](https://discourse.cmake.org/u/alcroito)\
**Replies:** 1\
**Last updated:** [December 15, 2019, 1:04am UTC](https://discourse.cmake.org/t/why-does-source-file-try-compile-not-propagate-cmake-toolchain-file-to-the-generated-project/275 "2019-12-15T01:04:56Z")

</div>

Looking at the generated CMakeCache.txt of a try\_compile project (via --debug-trycompile), I do not see a CMAKE\_TOOLCHAIN\_FILE cache entry, even if one was passed to the project. In my particular case I pass the Google …

---

## [Can OBJECT libraries be EXCLUDED\_FROM\_ALL?](https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357)

<div class="topic-metadata">

**Author:** [@Eric\_Malenfant](https://discourse.cmake.org/u/Eric_Malenfant)\
**Replies:** 1\
**Last updated:** [December 12, 2019, 1:19pm UTC](https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357 "2019-12-12T13:19:25Z")

</div>

Hello, Currently using version 3.14.4, and experimenting with OBJECT libraries (https://cmake.org/cmake/help/v3.14/command/add\_library.html#object-libraries) Just ran a few tests, but it seems that targets added via ad…

---

## [\-Wl,-force\_link flags not working correctly](https://discourse.cmake.org/t/wl-force-link-flags-not-working-correctly/322)

<div class="topic-metadata">

**Author:** [@oliverdain](https://discourse.cmake.org/u/oliverdain)\
**Replies:** 20\
**Last updated:** [December 12, 2019, 10:02am UTC](https://discourse.cmake.org/t/wl-force-link-flags-not-working-correctly/322 "2019-12-12T10:02:43Z")

</div>

I have a very strange issue which I suspect is a cmake bug. I’ve tried to reproduce with a small example but the small example works fine. I’ve got a multi-directory project. In one of those projects I have a CMakeLists.…

---

## [CMake ExternalProject addon forcing install path to c:/program files and ignoring INSTALL\_PATH option](https://discourse.cmake.org/t/cmake-externalproject-addon-forcing-install-path-to-c-program-files-and-ignoring-install-path-option/342)

<div class="topic-metadata">

**Author:** [@ethindp](https://discourse.cmake.org/u/ethindp)\
**Replies:** 2\
**Last updated:** [December 10, 2019, 2:25pm UTC](https://discourse.cmake.org/t/cmake-externalproject-addon-forcing-install-path-to-c-program-files-and-ignoring-install-path-option/342 "2019-12-10T14:25:43Z")

</div>

This is incredibly confusing. I have the following CMake code in my CMakeLists.txt: list(APPEND CMAKE\_ARGS "-DSCRIPT\_API=C#" "-DBSF\_ENABLE\_EXCEPTIONS=On" "-DAUDIO\_MODULE=OpenAudio" "-DBSF\_PLUGIN\_IMGUI=Off" "-DRENDER\_API…

---

## [Library target isn't rebuilt when it depends on another custom target.](https://discourse.cmake.org/t/library-target-isnt-rebuilt-when-it-depends-on-another-custom-target/311)

<div class="topic-metadata">

**Author:** [@ginee](https://discourse.cmake.org/u/ginee)\
**Replies:** 4\
**Last updated:** [December 10, 2019, 7:55am UTC](https://discourse.cmake.org/t/library-target-isnt-rebuilt-when-it-depends-on-another-custom-target/311 "2019-12-10T07:55:44Z")

</div>

I made a dependency on a library target for a custom target by “ADD\_DEPENDENCIES(lib\_target extern\_target)”. It works well that every time lib\_target is built, extern\_target will be built. However, when associated fi…

---

## [Usage of INTERFACE\_LINK\_LIBRARIES with namespaced targets](https://discourse.cmake.org/t/usage-of-interface-link-libraries-with-namespaced-targets/330)

<div class="topic-metadata">

**Author:** [@Martin\_Stolpe](https://discourse.cmake.org/u/Martin_Stolpe)\
**Replies:** 6\
**Last updated:** [December 9, 2019, 6:33pm UTC](https://discourse.cmake.org/t/usage-of-interface-link-libraries-with-namespaced-targets/330 "2019-12-09T18:33:47Z")

</div>

I try to use the Intel MKL, which has some pkg-config configuration files, with CMake. When I try to link the MKL statically in my project some linker options will be stored in the INTERFACE\_LINK\_LIBRARIES property. When…

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

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