# Code

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

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

**Page:** 72

---

## [Cmake 3.17 Visual Studio 2015 x64 MinGW64 fortran compilation issues](https://discourse.cmake.org/t/cmake-3-17-visual-studio-2015-x64-mingw64-fortran-compilation-issues/1076)

<div class="topic-metadata">

**Author:** [@elm](https://discourse.cmake.org/u/elm)\
**Replies:** 3\
**Last updated:** [April 28, 2020, 2:37pm UTC](https://discourse.cmake.org/t/cmake-3-17-visual-studio-2015-x64-mingw64-fortran-compilation-issues/1076 "2020-04-28T14:37:05Z")

</div>

Good day, I have a mixed C++/Fortran Project I am trying to compile on Windows 10 (latest update) with the latest version of cmake and running into an issue related to the fortran compilation. Note that I have MINGW64 …

---

## [Make CMake error give the full path to the faulty CMakeLists.txt](https://discourse.cmake.org/t/make-cmake-error-give-the-full-path-to-the-faulty-cmakelists-txt/1072)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 2\
**Last updated:** [April 28, 2020, 12:44pm UTC](https://discourse.cmake.org/t/make-cmake-error-give-the-full-path-to-the-faulty-cmakelists-txt/1072 "2020-04-28T12:44:00Z")

</div>

Given a simple structure: - project --- CMakeLists.txt --- lib --- --- CMakeLists.txt The top level CMakeLists.txt file just does an add\_subdirectory(lib). If the lib CMakeLists.txt file is faulty, an error like the fo…

---

## [cmake pybind11 cannot create target because another target with the same name already exists, how to bypass?](https://discourse.cmake.org/t/cmake-pybind11-cannot-create-target-because-another-target-with-the-same-name-already-exists-how-to-bypass/1097)

<div class="topic-metadata">

**Author:** [@ragnarokas](https://discourse.cmake.org/u/ragnarokas)\
**Replies:** 6\
**Last updated:** [April 25, 2020, 2:56pm UTC](https://discourse.cmake.org/t/cmake-pybind11-cannot-create-target-because-another-target-with-the-same-name-already-exists-how-to-bypass/1097 "2020-04-25T14:56:06Z")

</div>

Hello, I have the code, which cmakelists.txt looks like: \> cmake\_minimum\_required(VERSION 3.14) \> project(grapoli\_lap) \> set(CMAKE\_CXX\_STANDARD 17) \> \> set(SOURCE\_FILES \> unit\_test/geometry/monomer\_test.cpp \> …

---

## [CUDA aarch64 cross compile fails to validate nvcc](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593)

<div class="topic-metadata">

**Author:** [@DKB](https://discourse.cmake.org/u/DKB)\
**Replies:** 2\
**Last updated:** [April 22, 2020, 9:34pm UTC](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593 "2020-04-22T21:34:21Z")

</div>

I’m attempting to use a toolchain file to cross-compile from Linux x86\_64 to aarch64. set(CMAKE\_SYSTEM\_NAME Linux) set(CMAKE\_SYSTEM\_PROCESSOR aarch64) set(CMAKE\_TOOLS\_PREFIX ${CMAKE\_SYSTEM\_PROCESSOR}-linux-gnu- CACHE S…

---

## [Override CMAKE\_CXX\_STANDARD at target level.](https://discourse.cmake.org/t/override-cmake-cxx-standard-at-target-level/1068)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 4\
**Last updated:** [April 21, 2020, 9:09pm UTC](https://discourse.cmake.org/t/override-cmake-cxx-standard-at-target-level/1068 "2020-04-21T21:09:25Z")

</div>

I have a top level project that sets the standard to 14, set(CMAKE\_CXX\_STANDARD 14). I have a target below (that is included via add\_subdirectory) that links to an external library that requires the -std=gnu++1y flag to…

---

## [CPack DEB generator is following symlinks of directories](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045)

<div class="topic-metadata">

**Author:** [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Replies:** 8\
**Last updated:** [April 21, 2020, 5:19pm UTC](https://discourse.cmake.org/t/cpack-deb-generator-is-following-symlinks-of-directories/1045 "2020-04-21T17:19:26Z")

</div>

The following link indicates this issue was fixed: https://gitlab.kitware.com/cmake/cmake/issues/19448 But, for me it still remains with CMake v3.15.7. The following code illustrates the issue: install(CODE " EXEC…

---

## [Help with target\_precompile\_headers](https://discourse.cmake.org/t/help-with-target-precompile-headers/1065)

<div class="topic-metadata">

**Author:** [@polar](https://discourse.cmake.org/u/polar)\
**Replies:** 2\
**Last updated:** [April 20, 2020, 6:31pm UTC](https://discourse.cmake.org/t/help-with-target-precompile-headers/1065 "2020-04-20T18:31:07Z")

</div>

Problem, Windows10, vs2019: using target\_precompile\_headers(some\_target PRIVATE \_pch.h) when building a subcomponent of a static library, some.lib. The problem is that when I try to link to some.lib, I get a LNK2011: p…

---

## [Proper usage of HANDLE\_COMPONENTS in custom FindXXX.cmake Module](https://discourse.cmake.org/t/proper-usage-of-handle-components-in-custom-findxxx-cmake-module/1063)

<div class="topic-metadata">

**Author:** [@KBentley57](https://discourse.cmake.org/u/KBentley57)\
**Replies:** 0\
**Last updated:** [April 20, 2020, 2:32pm UTC](https://discourse.cmake.org/t/proper-usage-of-handle-components-in-custom-findxxx-cmake-module/1063 "2020-04-20T14:32:10Z")

</div>

I am modernizing a bit of old CMake, and in the process, am re-writing a few module files. I’m following along the documentation in the cmake-developer man page, and generally have most things sorted. What I can’t seem…

---

## [Install EXPORT for multiple build types](https://discourse.cmake.org/t/install-export-for-multiple-build-types/1023)

<div class="topic-metadata">

**Author:** [@abroekhuis](https://discourse.cmake.org/u/abroekhuis)\
**Replies:** 9\
**Last updated:** [April 20, 2020, 7:20am UTC](https://discourse.cmake.org/t/install-export-for-multiple-build-types/1023 "2020-04-20T07:20:55Z")

</div>

Hi all, I have a project for which I can do a Debug and Release build. Using a debug postfix, libraries are named differently. So I though I could do a make install in both build directories, resulting in a mixed instal…

---

## [add\_custom\_command adds nonsense "driveletter:" to step](https://discourse.cmake.org/t/add-custom-command-adds-nonsense-driveletter-to-step/1049)

<div class="topic-metadata">

**Author:** [@Xaymar](https://discourse.cmake.org/u/Xaymar)\
**Replies:** 9\
**Last updated:** [April 20, 2020, 7:12am UTC](https://discourse.cmake.org/t/add-custom-command-adds-nonsense-driveletter-to-step/1049 "2020-04-20T07:12:43Z")

</div>

CMake Version: 3.17.1 Using the WORKING\_DIRECTORY option in add\_custom\_command completely breaks the generated build step. For an unknown reason, CMake generates an extra line which is usually just “driveletter:” (C:, D…

---

## [ExternalProject\_Add creates wrong folder](https://discourse.cmake.org/t/externalproject-add-creates-wrong-folder/1041)

<div class="topic-metadata">

**Author:** [@Lotte1990](https://discourse.cmake.org/u/Lotte1990)\
**Replies:** 2\
**Last updated:** [April 17, 2020, 9:46am UTC](https://discourse.cmake.org/t/externalproject-add-creates-wrong-folder/1041 "2020-04-17T09:46:01Z")

</div>

In my project’s CMakeLists.txt I’m adding external projects like this: externalproject\_add(xxx GIT\_REPOSITORY xxxrepo SOURCE\_DIR ../../../3rdParty/xxx/src BUILD\_DIR ../../../3rdParty/xxx/build) externalproject\_add(yyy G…

---

## [ccmake . command not foud](https://discourse.cmake.org/t/ccmake-command-not-foud/1038)

<div class="topic-metadata">

**Author:** [@Vaya\_Putra](https://discourse.cmake.org/u/Vaya_Putra)\
**Replies:** 0\
**Last updated:** [April 15, 2020, 4:06pm UTC](https://discourse.cmake.org/t/ccmake-command-not-foud/1038 "2020-04-15T16:06:29Z")

</div>

hi i newbie using linux i have problem i had cmake old version 13.3.3, since i have to update this cmake i already done to uninstall and install new version but when i run cmake --version always state old version wh…

---

## [Best practices for company global compile flags](https://discourse.cmake.org/t/best-practices-for-company-global-compile-flags/1007)

<div class="topic-metadata">

**Author:** [@HenryMiller1](https://discourse.cmake.org/u/HenryMiller1)\
**Replies:** 1\
**Last updated:** [April 15, 2020, 1:58pm UTC](https://discourse.cmake.org/t/best-practices-for-company-global-compile-flags/1007 "2020-04-15T13:58:40Z")

</div>

We have been using cmake for years, and I’m trying to modernize our cmake. One issue that has come up is what about company global flags. We have a company policy that all internally written code is compiled with -Wall…

---

## [When to use ${} around variable names](https://discourse.cmake.org/t/when-to-use-around-variable-names/1021)

<div class="topic-metadata">

**Author:** [@Robert\_Boehne](https://discourse.cmake.org/u/Robert_Boehne)\
**Replies:** 3\
**Last updated:** [April 14, 2020, 10:50pm UTC](https://discourse.cmake.org/t/when-to-use-around-variable-names/1021 "2020-04-14T22:50:27Z")

</div>

All, Recently I put up a change in our product’s CMakeLists.txt to eliminate unnecessary use of ${} in tests around variables CMAKE\_SYSTEM\_NAME and CMAKE\_CXX\_COMPILER\_ID. That prompted a colleague to ask “when is it ne…

---

## [test does not run with configuration](https://discourse.cmake.org/t/test-does-not-run-with-configuration/1018)

<div class="topic-metadata">

**Author:** [@hex](https://discourse.cmake.org/u/hex)\
**Replies:** 7\
**Last updated:** [April 14, 2020, 7:57pm UTC](https://discourse.cmake.org/t/test-does-not-run-with-configuration/1018 "2020-04-14T19:57:41Z")

</div>

I added a test which does not run: add\_test( NAME debugOnly COMMAND Cap24::testapp CONFIGURATIONS Debug ) the test should be executed only for the ‘Debug’ configuration. I am using the gnu makefiles generator …

---

## [Save CMake function parameter forwarding](https://discourse.cmake.org/t/save-cmake-function-parameter-forwarding/1002)

<div class="topic-metadata">

**Author:** [@mensinda](https://discourse.cmake.org/u/mensinda)\
**Replies:** 10\
**Last updated:** [April 14, 2020, 7:51pm UTC](https://discourse.cmake.org/t/save-cmake-function-parameter-forwarding/1002 "2020-04-14T19:51:52Z")

</div>

Is it generally possible to safely forward function parameters? I know that ${ARGV} is less than ideal since it flattens lists, etc. So I am looking for a solution that doesn’t have the same issues. More specifically I …

---

## [CMAKE\_RANLIB vs CMAKE\_CXX\_COMPILER\_RANLIB](https://discourse.cmake.org/t/cmake-ranlib-vs-cmake-cxx-compiler-ranlib/1017)

<div class="topic-metadata">

**Author:** [@rnyberg](https://discourse.cmake.org/u/rnyberg)\
**Replies:** 1\
**Last updated:** [April 14, 2020, 2:03pm UTC](https://discourse.cmake.org/t/cmake-ranlib-vs-cmake-cxx-compiler-ranlib/1017 "2020-04-14T14:03:02Z")

</div>

Hi! I’m not certain how these variables are to be used. In my case building with clang 7 and -flto I need to run the cxx compiler specific ranlib but CMAKE\_RANLIB is the one actually run. Am I supposed to to something l…

---

## [cannot use gtest\_add\_tests and gtest\_disover\_tests in lates cmake](https://discourse.cmake.org/t/cannot-use-gtest-add-tests-and-gtest-disover-tests-in-lates-cmake/991)

<div class="topic-metadata">

**Author:** [@Fido](https://discourse.cmake.org/u/Fido)\
**Replies:** 1\
**Last updated:** [April 11, 2020, 11:18pm UTC](https://discourse.cmake.org/t/cannot-use-gtest-add-tests-and-gtest-disover-tests-in-lates-cmake/991 "2020-04-11T23:18:32Z")

</div>

When I use any of these two commands, the result is: CMake Error at CMakeLists.txt:67 (gtest\_add\_tests): Unknown CMake command "gtest\_add\_tests". Any suggestion for what I’m doing wrong?

---

## [FetchContent protobuf and use for FindProtobuf functions](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739)

<div class="topic-metadata">

**Author:** [@Leonard\_Lausen](https://discourse.cmake.org/u/Leonard_Lausen)\
**Replies:** 2\
**Last updated:** [April 11, 2020, 7:58am UTC](https://discourse.cmake.org/t/fetchcontent-protobuf-and-use-for-findprotobuf-functions/739 "2020-04-11T07:58:08Z")

</div>

Following https://gitlab.kitware.com/cmake/cmake/issues/19875#note\_705896 it is possible to FetchContent protobuf. Is it feasible to use that protobuf and it’s compiler for the protobuf\_generate\_cpp and protobuf\_gene…

---

## [Linux copying dependencies using file(GET\_RUNTIME\_DEPENDENCIES..)](https://discourse.cmake.org/t/linux-copying-dependencies-using-file-get-runtime-dependencies/946)

<div class="topic-metadata">

**Author:** [@Lerner](https://discourse.cmake.org/u/Lerner)\
**Replies:** 7\
**Last updated:** [April 9, 2020, 2:10pm UTC](https://discourse.cmake.org/t/linux-copying-dependencies-using-file-get-runtime-dependencies/946 "2020-04-09T14:10:03Z")

</div>

Hi there, I’m trying to make a simple OpenCV Linux application but it works only on OpenCV installed OS, so I wan’t to copy all of it’s dependencies into build folder via cmake to make it also work on the other computers…

---

## [How to get errors from 'install' command?](https://discourse.cmake.org/t/how-to-get-errors-from-install-command/956)

<div class="topic-metadata">

**Author:** [@JoeAB](https://discourse.cmake.org/u/JoeAB)\
**Replies:** 2\
**Last updated:** [April 9, 2020, 7:47am UTC](https://discourse.cmake.org/t/how-to-get-errors-from-install-command/956 "2020-04-09T07:47:15Z")

</div>

I want to copy a directory tree full of web files. It sounds as simple as install(DIRECTORY mydir/ DESTINATION dir/elsewhere) but it just not create a directory, copy any files or give an error or warning. How do I get…

---

## [find\_package does not find Boost](https://discourse.cmake.org/t/find-package-does-not-find-boost/509)

<div class="topic-metadata">

**Author:** [@JoeAB](https://discourse.cmake.org/u/JoeAB)\
**Replies:** 2\
**Last updated:** [April 7, 2020, 9:09pm UTC](https://discourse.cmake.org/t/find-package-does-not-find-boost/509 "2020-04-07T21:09:26Z")

</div>

Our project is building and running on Windows 7 and Ubuntu 16.04. I am now trying to cross compile it under licensed code, copying our project under the external directory. I added BOOST\_ROOT, BOOST\_INCLUDEDIR and Boost…

---

## [Create target that only runs other target](https://discourse.cmake.org/t/create-target-that-only-runs-other-target/885)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 6\
**Last updated:** [April 6, 2020, 3:52pm UTC](https://discourse.cmake.org/t/create-target-that-only-runs-other-target/885 "2020-04-06T15:52:22Z")

</div>

Hi everyone, I’m currently building a cmake for compiling and flashing microcontroller applications (avr). The important part looks like that: function(add\_avr\_executable targetName) add\_executable(${targetName} $…

---

## [Building MPICH as an external project results in an odd fortran error - FCMODOUTFLAG not detected.](https://discourse.cmake.org/t/building-mpich-as-an-external-project-results-in-an-odd-fortran-error-fcmodoutflag-not-detected/927)

<div class="topic-metadata">

**Author:** [@KBentley57](https://discourse.cmake.org/u/KBentley57)\
**Replies:** 1\
**Last updated:** [April 6, 2020, 3:29pm UTC](https://discourse.cmake.org/t/building-mpich-as-an-external-project-results-in-an-odd-fortran-error-fcmodoutflag-not-detected/927 "2020-04-06T15:29:58Z")

</div>

I’m building several packages of scientific software, for use in my program, and for the life of me, I can’t figure out the behavior I’m seeing. I am unsure that it’s a bug, per se, but something is awry, and I’m not su…

---

## [CODE: math(OUTPUT\_FORMAT HEXADECIMAL) workaround for CMake \< 3.13](https://discourse.cmake.org/t/code-math-output-format-hexadecimal-workaround-for-cmake-3-13/924)

<div class="topic-metadata">

**Author:** [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Replies:** 4\
**Last updated:** [April 2, 2020, 9:58pm UTC](https://discourse.cmake.org/t/code-math-output-format-hexadecimal-workaround-for-cmake-3-13/924 "2020-04-02T21:58:51Z")

</div>

One of our CMake projects includes a GENERATED config file that needs to include the project version converted into hexadecimal form. With CMake 3.13+, easy-peasy: math(EXPR PROJECT\_VERSION\_HEX "(${PROJECT\_VERSION…

---

## [Make miss dependencies when add\_custom\_command depends on add\_custom\_target or add\_custom\_command](https://discourse.cmake.org/t/make-miss-dependencies-when-add-custom-command-depends-on-add-custom-target-or-add-custom-command/835)

<div class="topic-metadata">

**Author:** [@amurzeau](https://discourse.cmake.org/u/amurzeau)\
**Replies:** 16\
**Last updated:** [April 2, 2020, 9:30pm UTC](https://discourse.cmake.org/t/make-miss-dependencies-when-add-custom-command-depends-on-add-custom-target-or-add-custom-command/835 "2020-04-02T21:30:54Z")

</div>

Hi, When in a subdirectory’s CMakeLists.txt, I have: add\_custom\_command( OUTPUT ${TEST\_OUTPUT} COMMAND ${CMAKE\_COMMAND} -E copy ${TEST\_INPUT} ${TEST\_OUTPUT} DEPENDS ${TEST\_INPUT} ) add\_custom\_target(gen\_test\_file DE…

---

## [How to customize install, install/local and install/strip?](https://discourse.cmake.org/t/how-to-customize-install-install-local-and-install-strip/934)

<div class="topic-metadata">

**Author:** [@Xaymar](https://discourse.cmake.org/u/Xaymar)\
**Replies:** 2\
**Last updated:** [April 2, 2020, 8:16pm UTC](https://discourse.cmake.org/t/how-to-customize-install-install-local-and-install-strip/934 "2020-04-02T20:16:13Z")

</div>

When generating projects for linux using one of the makefile generators, there are multiple install targets, all which currently do the exact same thing. How do I configure each of these to install different files, if at…

---

## [How to install an external project?](https://discourse.cmake.org/t/how-to-install-an-external-project/888)

<div class="topic-metadata">

**Author:** [@ajm](https://discourse.cmake.org/u/ajm)\
**Replies:** 11\
**Last updated:** [April 2, 2020, 7:39am UTC](https://discourse.cmake.org/t/how-to-install-an-external-project/888 "2020-04-02T07:39:54Z")

</div>

Problem: Installing an external project I am looking to have CMake clone and build a git repository as an ExternalProject, then package in the resulting binary files with the main project. The documentation for External…

---

## [Woraround to overcome badly designed config packaging with imported target names = library names](https://discourse.cmake.org/t/woraround-to-overcome-badly-designed-config-packaging-with-imported-target-names-library-names/893)

<div class="topic-metadata">

**Author:** [@airwin](https://discourse.cmake.org/u/airwin)\
**Replies:** 2\
**Last updated:** [April 1, 2020, 9:04pm UTC](https://discourse.cmake.org/t/woraround-to-overcome-badly-designed-config-packaging-with-imported-target-names-library-names/893 "2020-04-01T21:04:59Z")

</div>

One such badly designed package is the lapack software where those developers (still as of the latest version, 3.9.0) do not use the NAMESPACE option to install(EXPORT…) to set, e.g., a LAPACK:: namespace on the impor…

---

## [ExternalProject Build Byproduct Path](https://discourse.cmake.org/t/externalproject-build-byproduct-path/775)

<div class="topic-metadata">

**Author:** [@dMaggot](https://discourse.cmake.org/u/dMaggot)\
**Replies:** 5\
**Last updated:** [April 1, 2020, 5:54pm UTC](https://discourse.cmake.org/t/externalproject-build-byproduct-path/775 "2020-04-01T17:54:35Z")

</div>

I am using the ExternalProject for two projects and in both cases I need to list build byproducts. The problem is that in both cases I need to list them relative to the build. Thinking about this, it makes little sense t…

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

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