# Usage

**URL:** https://discourse.cmake.org/c/usage/12.md?page=82

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

**Page:** 83

---

## [How to properly import CMake files/modules?](https://discourse.cmake.org/t/how-to-properly-import-cmake-files-modules/2816)

<div class="topic-metadata">

**Author:** [@senr80](https://discourse.cmake.org/u/senr80)\
**Replies:** 4\
**Last updated:** [February 24, 2021, 1:48pm UTC](https://discourse.cmake.org/t/how-to-properly-import-cmake-files-modules/2816 "2021-02-24T13:48:01Z")

</div>

I created a collection of CMake functions and macros that will be rolled out on our development machines. Our projects should just need to include the collection’s main .cmake file to make use of it. I had in mind to so…

---

## [How to only preprocess and link some of the files in cmake](https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812)

<div class="topic-metadata">

**Author:** [@deepan](https://discourse.cmake.org/u/deepan)\
**Replies:** 1\
**Last updated:** [February 23, 2021, 6:56pm UTC](https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812 "2021-02-23T18:56:41Z")

</div>

I want some of my files only to be preprocessed and linked(.ld files) and others(.c) has to be fully compiled. How to do this in cmake ?

---

## [cmake\_dependent\_option with complex conditionals](https://discourse.cmake.org/t/cmake-dependent-option-with-complex-conditionals/2793)

<div class="topic-metadata">

**Author:** [@markd](https://discourse.cmake.org/u/markd)\
**Replies:** 3\
**Last updated:** [February 22, 2021, 8:16pm UTC](https://discourse.cmake.org/t/cmake-dependent-option-with-complex-conditionals/2793 "2021-02-22T20:16:52Z")

</div>

It seems that cmake\_dependent\_option does not work with complex conditionals. For example: OPTION(OPT1 "Option 1" ON) OPTION(OPT2 "Option 2" ON) OPTION(OPT3 "Option 3" OFF) # Complex condition in if statement IF (OPT1…

---

## [LINK\_FLAGS order in CMake link step](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803)

<div class="topic-metadata">

**Author:** [@alainlou](https://discourse.cmake.org/u/alainlou)\
**Replies:** 3\
**Last updated:** [February 22, 2021, 6:12pm UTC](https://discourse.cmake.org/t/link-flags-order-in-cmake-link-step/2803 "2021-02-22T18:12:47Z")

</div>

OS: Ubuntu 18.04 Version: 3.10.2 Other relevant info: set(CMAKE\_CXX\_COMPILER dpcpp) cmake\_minimum\_required (VERSION 3.4) I have the following target add\_executable(${EMULATOR\_TARGET} ${SOURCE\_FILE} ${HEADER\_FILE}) a…

---

## [enable\_language(CUDA) -Xcompiler error](https://discourse.cmake.org/t/enable-language-cuda-xcompiler-error/2774)

<div class="topic-metadata">

**Author:** [@jclombardo](https://discourse.cmake.org/u/jclombardo)\
**Replies:** 3\
**Last updated:** [February 22, 2021, 3:16pm UTC](https://discourse.cmake.org/t/enable-language-cuda-xcompiler-error/2774 "2021-02-22T15:16:05Z")

</div>

Hi, I can’t manage to generate a correct nvcc compile line with cuda language enabled, at least when a lot of compiler definition (coming from external dependencies) are present. The -Xcompile options are separated by s…

---

## [Error building STRATA on MSYS2](https://discourse.cmake.org/t/error-building-strata-on-msys2/2810)

<div class="topic-metadata">

**Author:** [@Adrian\_Duncan](https://discourse.cmake.org/u/Adrian_Duncan)\
**Replies:** 3\
**Last updated:** [February 22, 2021, 2:41pm UTC](https://discourse.cmake.org/t/error-building-strata-on-msys2/2810 "2021-02-22T14:41:10Z")

</div>

Hello I am following instructions on installing a program called STRATA, which is found on this website: https://github.com/arkottke/strata#building I am using windows, and I am using MSYS2 as recommended on the websi…

---

## [Unknown CMake command "CPMAddPackage"](https://discourse.cmake.org/t/unknown-cmake-command-cpmaddpackage/2808)

<div class="topic-metadata">

**Author:** [@mahmoodn](https://discourse.cmake.org/u/mahmoodn)\
**Replies:** 2\
**Last updated:** [February 22, 2021, 2:09am UTC](https://discourse.cmake.org/t/unknown-cmake-command-cpmaddpackage/2808 "2021-02-22T02:09:03Z")

</div>

Hi I can not figure out what to do with this error on a Debian 10. $ cmake -DGUNROCK\_GENCODE\_SM75=ON .. -- The C compiler identification is GNU 8.3.0 -- The CXX compiler identification is GNU 8.3.0 -- Check for working…

---

## [Proper way to set compiler and language standard in CMake](https://discourse.cmake.org/t/proper-way-to-set-compiler-and-language-standard-in-cmake/2756)

<div class="topic-metadata">

**Author:** [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Replies:** 9\
**Last updated:** [February 19, 2021, 8:20pm UTC](https://discourse.cmake.org/t/proper-way-to-set-compiler-and-language-standard-in-cmake/2756 "2021-02-19T20:20:47Z")

</div>

Hi, ... project(${TARGET\_NAME} VERSION 1.0.0) ... set(CMAKE\_CXX\_COMPILER ${CPP\_COMPILER}) set(CMAKE\_C\_COMPILER ${C\_COMPILER}) ... target\_compile\_features(${TARGET\_NAME} PUBLIC cxx\_std\_14) I get, with gcc 5.5.0 (Ubuntu …

---

## [CMakePresets.json - how to pass CMAKE\_TOOLCHAIN\_FILE ?](https://discourse.cmake.org/t/cmakepresets-json-how-to-pass-cmake-toolchain-file/2786)

<div class="topic-metadata">

**Author:** [@Lukasz\_Tyrala](https://discourse.cmake.org/u/Lukasz_Tyrala)\
**Replies:** 2\
**Last updated:** [February 17, 2021, 8:32pm UTC](https://discourse.cmake.org/t/cmakepresets-json-how-to-pass-cmake-toolchain-file/2786 "2021-02-17T20:32:09Z")

</div>

First: CMakePreset.json is a great improvement! Please let me know how to provide toolchain file in CMakePresets.json { "version": 1, "cmakeMinimumRequired": { "major": 3, "minor": 19, "patch": 0 }, …

---

## [install build artefacts of an external project](https://discourse.cmake.org/t/install-build-artefacts-of-an-external-project/2791)

<div class="topic-metadata">

**Author:** [@Lieven](https://discourse.cmake.org/u/Lieven)\
**Replies:** 1\
**Last updated:** [February 17, 2021, 5:42pm UTC](https://discourse.cmake.org/t/install-build-artefacts-of-an-external-project/2791 "2021-02-17T17:42:52Z")

</div>

Use case: there is some external project that need to build stuff ancient style (configure/make/make install) the outcome is a few shared libraries (.so with the symlinks game, by the wat on linux) users of these (libr…

---

## [CMake does not find CUDA if not in $PATH if CUDA is a project LANGUAGE](https://discourse.cmake.org/t/cmake-does-not-find-cuda-if-not-in-path-if-cuda-is-a-project-language/2790)

<div class="topic-metadata">

**Author:** [@paskino](https://discourse.cmake.org/u/paskino)\
**Replies:** 5\
**Last updated:** [February 17, 2021, 4:23pm UTC](https://discourse.cmake.org/t/cmake-does-not-find-cuda-if-not-in-path-if-cuda-is-a-project-language/2790 "2021-02-17T16:23:27Z")

</div>

Dear all, I am pretty confused: since 3.10 CUDA is a first class language and one need not to use find\_package(CUDA) nor find\_package(CUDAToolkit). A minimal setup you can find at https://github.com/paskino/cmake-cuda …

---

## [How to add a source file to a executable that only exists after ExternalProject\_Add in Cmake](https://discourse.cmake.org/t/how-to-add-a-source-file-to-a-executable-that-only-exists-after-externalproject-add-in-cmake/2789)

<div class="topic-metadata">

**Author:** [@ForceConstant](https://discourse.cmake.org/u/ForceConstant)\
**Replies:** 1\
**Last updated:** [February 17, 2021, 2:36pm UTC](https://discourse.cmake.org/t/how-to-add-a-source-file-to-a-executable-that-only-exists-after-externalproject-add-in-cmake/2789 "2021-02-17T14:36:41Z")

</div>

I have a cmake project, where it is pulling an external project using ExternalProject\_Add() and I don’t want to use it’s build files, but just would like to add its source files to either a add\_executable or add\_library …

---

## [Help debugging transitive INTERFACE\_INCLUDE\_DIRECTORIES](https://discourse.cmake.org/t/help-debugging-transitive-interface-include-directories/2752)

<div class="topic-metadata">

**Author:** [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Replies:** 3\
**Last updated:** [February 16, 2021, 8:11pm UTC](https://discourse.cmake.org/t/help-debugging-transitive-interface-include-directories/2752 "2021-02-16T20:11:58Z")

</div>

Is it possible to get a whole information about target properties/include dirs and all dependencies (include transitive) using the brand new cmake-file-api(7)? Hello everyone. I try to determine why some transitive INTE…

---

## [Changing Intel Fortran compiler option /fpconstant](https://discourse.cmake.org/t/changing-intel-fortran-compiler-option-fpconstant/2766)

<div class="topic-metadata">

**Author:** [@kaykay](https://discourse.cmake.org/u/kaykay)\
**Replies:** 4\
**Last updated:** [February 16, 2021, 6:06pm UTC](https://discourse.cmake.org/t/changing-intel-fortran-compiler-option-fpconstant/2766 "2021-02-16T18:06:36Z")

</div>

Hi, I am new to CMake although I have been aware of its existence for several years. I am trying to use CMake to build a static library project in Visual Studio Community 2015. I have to pass compiler flag /fpconstant.…

---

## [expression generator in list](https://discourse.cmake.org/t/expression-generator-in-list/2763)

<div class="topic-metadata">

**Author:** [@grimgort](https://discourse.cmake.org/u/grimgort)\
**Replies:** 3\
**Last updated:** [February 16, 2021, 12:42pm UTC](https://discourse.cmake.org/t/expression-generator-in-list/2763 "2021-02-16T12:42:20Z")

</div>

Hello, Using the following list gives me an error in add\_link\_option, but not in target\_link\_option. In particular $\<$CONFIG:Release:XXX; returns $\<0:""\> .So the second generator expression doesn’t work. it seems to wo…

---

## [Unable to set value for preprocessor variable](https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760)

<div class="topic-metadata">

**Author:** [@imlost](https://discourse.cmake.org/u/imlost)\
**Replies:** 1\
**Last updated:** [February 15, 2021, 7:53am UTC](https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760 "2021-02-15T07:53:01Z")

</div>

Hi have a library in my project that needs a preprocessor variable set with an integer value. I can define it, but not set the value. The library is in a sub directory with its own CmakeLists file. What am I missing? Cr…

---

## [Is this really a better style to use generator expressions every time?](https://discourse.cmake.org/t/is-this-really-a-better-style-to-use-generator-expressions-every-time/2753)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 3\
**Last updated:** [February 12, 2021, 3:12pm UTC](https://discourse.cmake.org/t/is-this-really-a-better-style-to-use-generator-expressions-every-time/2753 "2021-02-12T15:12:07Z")

</div>

\# either target\_compile\_options(Greeter PUBLIC "$\<$\<BOOL:${MSVC}\>:/permissive-\>") # or if(MSVC) target\_compile\_options(Greeter PUBLIC /permissive) endif() the first line generates on unix the GreeterTarget.cmake cont…

---

## [option compilation not added with Intel fortran compiler + msvc](https://discourse.cmake.org/t/option-compilation-not-added-with-intel-fortran-compiler-msvc/2738)

<div class="topic-metadata">

**Author:** [@grimgort](https://discourse.cmake.org/u/grimgort)\
**Replies:** 4\
**Last updated:** [February 12, 2021, 10:08am UTC](https://discourse.cmake.org/t/option-compilation-not-added-with-intel-fortran-compiler-msvc/2738 "2021-02-12T10:08:15Z")

</div>

Hello, I have a big problem to add compilation options with the compiler intel fortran +msvc . When I add compilation options, they are not taken into account in visual studio (see picture). A certain number of options…

---

## [list of commands supporting generator expressions](https://discourse.cmake.org/t/list-of-commands-supporting-generator-expressions/2743)

<div class="topic-metadata">

**Author:** [@woodz](https://discourse.cmake.org/u/woodz)\
**Replies:** 3\
**Last updated:** [February 11, 2021, 2:54pm UTC](https://discourse.cmake.org/t/list-of-commands-supporting-generator-expressions/2743 "2021-02-11T14:54:15Z")

</div>

set() supports generator expressions but this is not mentioned in the official doc to this command. I’ve been told using generator expressions in set() is agnostic. Is there a compulsory and complete list of commands s…

---

## [Cannot use MSVC\_IDE before first project call?](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734)

<div class="topic-metadata">

**Author:** [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Replies:** 6\
**Last updated:** [February 10, 2021, 11:21pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734 "2021-02-10T23:21:42Z")

</div>

I’m writing a toolchain file and want to use the MSVC\_IDE variable. However it doesn’t work. This will not work. if (MSVC\_IDE) message(FATAL\_ERROR "Foo") endif() This will work if (CMAKE\_GENERATOR MATCHES "Visual Stu…

---

## [OS X Big Sur - Temporary files -framework missing argument](https://discourse.cmake.org/t/os-x-big-sur-temporary-files-framework-missing-argument/2735)

<div class="topic-metadata">

**Author:** [@ARSanderson](https://discourse.cmake.org/u/ARSanderson)\
**Replies:** 2\
**Last updated:** [February 10, 2021, 9:16pm UTC](https://discourse.cmake.org/t/os-x-big-sur-temporary-files-framework-missing-argument/2735 "2021-02-10T21:16:33Z")

</div>

I have recently updated to OS X Big Sur and running into an issue with CMake (3.19.4) detecting MPICH. Here is the output in CMakeError.log: The MPI test test\_mpi for C in mode normal failed to compile with the followin…

---

## [Possible to partially override files in ${CMAKE\_ROOT}/Modules?](https://discourse.cmake.org/t/possible-to-partially-override-files-in-cmake-root-modules/2727)

<div class="topic-metadata">

**Author:** [@Eric\_Malenfant](https://discourse.cmake.org/u/Eric_Malenfant)\
**Replies:** 3\
**Last updated:** [February 9, 2021, 4:43pm UTC](https://discourse.cmake.org/t/possible-to-partially-override-files-in-cmake-root-modules/2727 "2021-02-09T16:43:43Z")

</div>

Hello, We’re trying to use CMake with Embarcadero C++ Builder 10. In order to be able to do so, we need to replace the default Platform/Windows-Embarcadero.cmake with a version that is provided with C++ Builder, as inst…

---

## [How to give custom path to the object files](https://discourse.cmake.org/t/how-to-give-custom-path-to-the-object-files/2716)

<div class="topic-metadata">

**Author:** [@deepan](https://discourse.cmake.org/u/deepan)\
**Replies:** 3\
**Last updated:** [February 9, 2021, 1:38pm UTC](https://discourse.cmake.org/t/how-to-give-custom-path-to-the-object-files/2716 "2021-02-09T13:38:56Z")

</div>

I want to give custom path to the object files. All the generated object files should be in this location instead of cmake own path.

---

## [How 2 count number of elements in json array using string(json](https://discourse.cmake.org/t/how-2-count-number-of-elements-in-json-array-using-string-json/2709)

<div class="topic-metadata">

**Author:** [@leeruns](https://discourse.cmake.org/u/leeruns)\
**Replies:** 1\
**Last updated:** [February 6, 2021, 6:26pm UTC](https://discourse.cmake.org/t/how-2-count-number-of-elements-in-json-array-using-string-json/2709 "2021-02-06T18:26:24Z")

</div>

Simple usage question here. If I want to count the size of a json array read json file count number of entryies in top level array save number of entries as a variable file(read JSON input.json input) string(JSON le…

---

## [Create relative paths for compiler\_commands.json](https://discourse.cmake.org/t/create-relative-paths-for-compiler-commands-json/1762)

<div class="topic-metadata">

**Author:** [@leeruns](https://discourse.cmake.org/u/leeruns)\
**Replies:** 8\
**Last updated:** [February 6, 2021, 5:06pm UTC](https://discourse.cmake.org/t/create-relative-paths-for-compiler-commands-json/1762 "2021-02-06T17:06:26Z")

</div>

I am working on a project where the code is currently compiled inside a linux container. When I instruct cmake to write the file it uses absolute paths. cmake -S /app/opt/myApp -B /app/opt/myApp -DCMAKE\_EXPORT\_COMPILE\_…

---

## [Disable OpenMP](https://discourse.cmake.org/t/disable-openmp/2700)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.cmake.org/u/pauljurczak)\
**Replies:** 7\
**Last updated:** [February 5, 2021, 9:27pm UTC](https://discourse.cmake.org/t/disable-openmp/2700 "2021-02-05T21:27:52Z")

</div>

I’m using CMake v3.19.3 on Ubuntu 18.04.5 with clang 11.0.1 and VS Code. Here is my CMakeLists.txt file: cmake\_minimum\_required(VERSION 3.18) project(ocv VERSION 0.1.0) find\_package(fmt REQUIRED) find\_package(OpenCV 4.…

---

## [Concerning CMake-presets (replacing our 'project variants')](https://discourse.cmake.org/t/concerning-cmake-presets-replacing-our-project-variants/2696)

<div class="topic-metadata">

**Author:** [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Replies:** 3\
**Last updated:** [February 5, 2021, 2:48pm UTC](https://discourse.cmake.org/t/concerning-cmake-presets-replacing-our-project-variants/2696 "2021-02-05T14:48:15Z")

</div>

Hi, back in Nov 2019 I asked here how I might define ‘project variants’ to define ‘super-options’ that would switch a set of options ON. https://discourse.cmake.org/t/project-variants/205?u=davida @ben.boeckel suggeste…

---

## [CMake, CPack, INSTALL(FILES...), "make package", and permission denied...](https://discourse.cmake.org/t/cmake-cpack-install-files-make-package-and-permission-denied/2678)

<div class="topic-metadata">

**Author:** [@TemporalBeing](https://discourse.cmake.org/u/TemporalBeing)\
**Replies:** 2\
**Last updated:** [February 5, 2021, 6:07am UTC](https://discourse.cmake.org/t/cmake-cpack-install-files-make-package-and-permission-denied/2678 "2021-02-05T06:07:23Z")

</div>

I have an open source project that is using CMake and CPack to build our distributables - deb, rpm, tarballs, and hopefully DMG and a Windows Installer in the future. Due to our various target platforms, we are stuck wit…

---

## [Cmake re-run with cuda code](https://discourse.cmake.org/t/cmake-re-run-with-cuda-code/2698)

<div class="topic-metadata">

**Author:** [@Xin\_Chen](https://discourse.cmake.org/u/Xin_Chen)\
**Replies:** 1\
**Last updated:** [February 4, 2021, 2:56pm UTC](https://discourse.cmake.org/t/cmake-re-run-with-cuda-code/2698 "2021-02-04T14:56:17Z")

</div>

I face an issue about cmake on windows. When I build a c++ library, if it has cuda code, then cmake will multiple time on windows (depend on how many cuda\_add\_library used) some code snippet: https://paste.ubuntu.com/p…

---

## [Unit tests failing only when run via CTest](https://discourse.cmake.org/t/unit-tests-failing-only-when-run-via-ctest/2694)

<div class="topic-metadata">

**Author:** [@devmake](https://discourse.cmake.org/u/devmake)\
**Replies:** 1\
**Last updated:** [February 4, 2021, 2:51pm UTC](https://discourse.cmake.org/t/unit-tests-failing-only-when-run-via-ctest/2694 "2021-02-04T14:51:10Z")

</div>

Have the following situation: C++ codebase Unit test suite based on the Boot.Test When run directly all the tests pass no issues When run via ctest eg: ctest -j 1 or ctest -j 5 tests fail It is the same test every time …

[Previous page](https://discourse.cmake.org/c/usage/12.md?page=81)

[Next page](https://discourse.cmake.org/c/usage/12.md?page=83)
