# Code

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

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

**Page:** 70

---

## [How to change build flag for just a few source files in a project for debugging](https://discourse.cmake.org/t/how-to-change-build-flag-for-just-a-few-source-files-in-a-project-for-debugging/1585)

<div class="topic-metadata">

**Author:** [@butette](https://discourse.cmake.org/u/butette)\
**Replies:** 3\
**Last updated:** [July 19, 2020, 3:37pm UTC](https://discourse.cmake.org/t/how-to-change-build-flag-for-just-a-few-source-files-in-a-project-for-debugging/1585 "2020-07-19T15:37:11Z")

</div>

If I already have a project set up with a standard set of compile/link options for that build type and need to debug by changing the compile and or link options for just one or two source files and leave the existing com…

---

## [If-test within ExternalProject\_Add/FetchContent\_Declare?](https://discourse.cmake.org/t/if-test-within-externalproject-add-fetchcontent-declare/1556)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 2\
**Last updated:** [July 16, 2020, 2:40pm UTC](https://discourse.cmake.org/t/if-test-within-externalproject-add-fetchcontent-declare/1556 "2020-07-16T14:40:10Z")

</div>

A query for the experts. Namely, I have a patch I’d like to apply to either a FetchContent\_Declare or ExternalProject\_Add command. And reading the doc I see there is a PATCH\_COMMAND that can be used. Nice. (Note I’m not …

---

## [Multiple definition of main](https://discourse.cmake.org/t/multiple-definition-of-main/1573)

<div class="topic-metadata">

**Author:** [@ELNS](https://discourse.cmake.org/u/ELNS)\
**Replies:** 6\
**Last updated:** [July 16, 2020, 2:39pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573 "2020-07-16T14:39:21Z")

</div>

Hi all, I have created a new cpp repository a day ago to re-implement my fortran code snippets in c plus plus language and this is default generated cmake file by clion IDE: cmake\_minimum\_required(VERSION 3.16) project…

---

## [Im following the cmake tutorial and i have some questions.](https://discourse.cmake.org/t/im-following-the-cmake-tutorial-and-i-have-some-questions/1559)

<div class="topic-metadata">

**Author:** [@Rundogie\_Rundogie](https://discourse.cmake.org/u/Rundogie_Rundogie)\
**Replies:** 0\
**Last updated:** [July 15, 2020, 4:58am UTC](https://discourse.cmake.org/t/im-following-the-cmake-tutorial-and-i-have-some-questions/1559 "2020-07-15T04:58:38Z")

</div>

Im using Cmake in visual studio and i m stucked on step 2. How can i change MY\_MATH in visual studio environment?

---

## [Setting custom include path for FetchContent?](https://discourse.cmake.org/t/setting-custom-include-path-for-fetchcontent/1539)

<div class="topic-metadata">

**Author:** [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)\
**Replies:** 2\
**Last updated:** [July 10, 2020, 10:44pm UTC](https://discourse.cmake.org/t/setting-custom-include-path-for-fetchcontent/1539 "2020-07-10T22:44:19Z")

</div>

By default, FetchContent seems to add the toplevel directory of the fetched code to the include path. Is there any way to customize this, so that fetched source that is out of your control can be segregated to avoid poss…

---

## [Question about failure result of get\_target\_property](https://discourse.cmake.org/t/question-about-failure-result-of-get-target-property/1384)

<div class="topic-metadata">

**Author:** [@christetreault](https://discourse.cmake.org/u/christetreault)\
**Replies:** 2\
**Last updated:** [July 10, 2020, 4:23pm UTC](https://discourse.cmake.org/t/question-about-failure-result-of-get-target-property/1384 "2020-07-10T16:23:50Z")

</div>

I’m trying to troubleshoot an issue with a VS project generated by CMake. The relevant section of the cmake file is: get\_target\_property(test\_suite\_folder ${test\_suite} FOLDER) if (NOT ${test\_suite\_folder} STREQUAL …

---

## [Having linker trouble with folly Library](https://discourse.cmake.org/t/having-linker-trouble-with-folly-library/1527)

<div class="topic-metadata">

**Author:** [@imlost](https://discourse.cmake.org/u/imlost)\
**Replies:** 1\
**Last updated:** [July 10, 2020, 7:39am UTC](https://discourse.cmake.org/t/having-linker-trouble-with-folly-library/1527 "2020-07-10T07:39:34Z")

</div>

Using VSPKG I obtained the folly library built statically (MT) but now I’m getting the following linker error below. Any suggestions on how to fix this error or what I may be missing from my cmakelists file? 1\>future\_be…

---

## [CPack: how to omit archive name from archived files' paths](https://discourse.cmake.org/t/cpack-how-to-omit-archive-name-from-archived-files-paths/1520)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 1\
**Last updated:** [July 8, 2020, 9:48pm UTC](https://discourse.cmake.org/t/cpack-how-to-omit-archive-name-from-archived-files-paths/1520 "2020-07-08T21:48:00Z")

</div>

project(foo VERSION 0.1.1) install( TARGETS ${lib} LIBRARY DESTINATION lib RUNTIME DESTINATION lib ARCHIVE DESTINATION lib) set(CPACK\_GENERATOR "ZIP") include(CPack) generates foo-0.1.1-Linux,zip, which …

---

## [Google Test System Includes](https://discourse.cmake.org/t/google-test-system-includes/1230)

<div class="topic-metadata">

**Author:** [@developer](https://discourse.cmake.org/u/developer)\
**Replies:** 2\
**Last updated:** [July 8, 2020, 6:30am UTC](https://discourse.cmake.org/t/google-test-system-includes/1230 "2020-07-08T06:30:20Z")

</div>

Google test is using system interface includes. This does not work for my project/build, so I am trying to not have those interface includes be -isystem. I did the following… set(CMAKE\_NO\_SYSTEM\_FROM\_IMPORTED ON) add\_su…

---

## [How does one link against CUDA "compatibility libs"](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467)

<div class="topic-metadata">

**Author:** [@paterno](https://discourse.cmake.org/u/paterno)\
**Replies:** 2\
**Last updated:** [July 1, 2020, 2:10pm UTC](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467 "2020-07-01T14:10:28Z")

</div>

I am using CMake v3.18.0rc2 to build a CUDA program that uses CUDA 11, on Scientific Linux 7 (a CentOS-7 relative). The drivers for CUDA 11 are not available on CentOS-7 (they are for CentOS-8), so I have been advised to…

---

## [CMake is forcing MSVC to use C compiler on C++ code](https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463)

<div class="topic-metadata">

**Author:** [@johnratius](https://discourse.cmake.org/u/johnratius)\
**Replies:** 1\
**Last updated:** [July 1, 2020, 1:19pm UTC](https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463 "2020-07-01T13:19:58Z")

</div>

I have no idea what I did; I am trying to compile C++ code and CMake on CLion chooses the Visual Studio C compiler to compile it. When I don’t use CMake, it runs fine. main.cpp: #include \<iostream\> #include "include/Wi…

---

## [Share pre-compiled header object](https://discourse.cmake.org/t/share-pre-compiled-header-object/1428)

<div class="topic-metadata">

**Author:** [@MathiasMagnus](https://discourse.cmake.org/u/MathiasMagnus)\
**Replies:** 1\
**Last updated:** [June 23, 2020, 12:11pm UTC](https://discourse.cmake.org/t/share-pre-compiled-header-object/1428 "2020-06-23T12:11:07Z")

</div>

I have a whole bunch of unit tests that share the headers of Google Test and a bunch of common includes. Many targets, same PCH. I noticed that inheriting an INTERFACE library as per the docs will create multiple PCH fil…

---

## [Which variables are not meant to be set in the CMakeLists.txt?](https://discourse.cmake.org/t/which-variables-are-not-meant-to-be-set-in-the-cmakelists-txt/1424)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 1\
**Last updated:** [June 22, 2020, 1:07pm UTC](https://discourse.cmake.org/t/which-variables-are-not-meant-to-be-set-in-the-cmakelists-txt/1424 "2020-06-22T13:07:48Z")

</div>

I understand that some variables are not meant to be set() in the CMakeLists.txt file, but are allowed to be set at the command line or in a toolchain file. Which variables are these? Are they documented anywhere? For i…

---

## [PRE-Ninja Bash-Command](https://discourse.cmake.org/t/pre-ninja-bash-command/1418)

<div class="topic-metadata">

**Author:** [@aphardt](https://discourse.cmake.org/u/aphardt)\
**Replies:** 9\
**Last updated:** [June 22, 2020, 12:51pm UTC](https://discourse.cmake.org/t/pre-ninja-bash-command/1418 "2020-06-22T12:51:20Z")

</div>

Hi I work on a big Cortex-M project with arm-none-eabi-gcc, cmake and ninja-build. The current build process is a bash script which consists of 4 parts: Execute pre-cmake-build bash instruction (also here, some file…

---

## [Modifying CMAKE\_\<LANG\>\_LINK\_EXECUTABLE in toolchain file](https://discourse.cmake.org/t/modifying-cmake-lang-link-executable-in-toolchain-file/1386)

<div class="topic-metadata">

**Author:** [@jairo](https://discourse.cmake.org/u/jairo)\
**Replies:** 4\
**Last updated:** [June 21, 2020, 1:39pm UTC](https://discourse.cmake.org/t/modifying-cmake-lang-link-executable-in-toolchain-file/1386 "2020-06-21T13:39:58Z")

</div>

Hello! I’m having quite some trouble finding a way to modify CMAKE\_C\_LINK\_EXECUTABLE/CMAKE\_CXX\_LINK\_EXECUTABLE for my embedded cross-compilation project. The compiler ID resolves correctly to “TI” and subsequencly TI-C.…

---

## [How do I add windows APIs to cmake?](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363)

<div class="topic-metadata">

**Author:** [@imlost](https://discourse.cmake.org/u/imlost)\
**Replies:** 4\
**Last updated:** [June 16, 2020, 8:19pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363 "2020-06-16T20:19:41Z")

</div>

I’m currently porting a crossplatform project to CMAKE and so far I’ve been able to just use find\_package() or add\_subdirectory() when dealing with third party libraries, but I don’t know how do it with Windows APIs. In …

---

## [CMake Generator Error: Failure to Convert include\_directories(...) See attached ZIP file](https://discourse.cmake.org/t/cmake-generator-error-failure-to-convert-include-directories-see-attached-zip-file/1396)

<div class="topic-metadata">

**Author:** [@Garry\_Anderson1](https://discourse.cmake.org/u/Garry_Anderson1)\
**Replies:** 11\
**Last updated:** [June 16, 2020, 12:37pm UTC](https://discourse.cmake.org/t/cmake-generator-error-failure-to-convert-include-directories-see-attached-zip-file/1396 "2020-06-16T12:37:29Z")

</div>

Support Team: My code development is being blocked by the CMake Generator, which fails to generate any Unix Makefiles code from “include\_directories” found in the CMakeLists.txt source. Can anybody help figure out what…

---

## [How to gather all files automatically to compile for executable](https://discourse.cmake.org/t/how-to-gather-all-files-automatically-to-compile-for-executable/1394)

<div class="topic-metadata">

**Author:** [@johnratius](https://discourse.cmake.org/u/johnratius)\
**Replies:** 5\
**Last updated:** [June 15, 2020, 4:32pm UTC](https://discourse.cmake.org/t/how-to-gather-all-files-automatically-to-compile-for-executable/1394 "2020-06-15T16:32:03Z")

</div>

I am trying to compile libraries on my own from a CMake script. For now, it’s just GLAD and GLFW. So for a normal project, I create a SOURCES variable and add the necessary headers and cpp files to it, then use the SOUR…

---

## [CMAKE\_CUDA\_HOST\_COMPILER reset to empty after enable\_language(CUDA) for CMake v3.17.3](https://discourse.cmake.org/t/cmake-cuda-host-compiler-reset-to-empty-after-enable-language-cuda-for-cmake-v3-17-3/1381)

<div class="topic-metadata">

**Author:** [@Triston\_C](https://discourse.cmake.org/u/Triston_C)\
**Replies:** 0\
**Last updated:** [June 12, 2020, 7:06pm UTC](https://discourse.cmake.org/t/cmake-cuda-host-compiler-reset-to-empty-after-enable-language-cuda-for-cmake-v3-17-3/1381 "2020-06-12T19:06:33Z")

</div>

My CMAKE\_CUDA\_HOST\_COMPILER was set as aarch64-linux-gnu-gcc. After enable\_language(CUDA), the var is set to empty string. The problem did not happene in v3.17.2. message(STATUS “CMAKE\_CUDA\_HOST\_COMPILER=${CMAKE\_CUDA\_HO…

---

## [How to find a specific Python module?](https://discourse.cmake.org/t/how-to-find-a-specific-python-module/1393)

<div class="topic-metadata">

**Author:** [@airwin](https://discourse.cmake.org/u/airwin)\
**Replies:** 2\
**Last updated:** [June 15, 2020, 1:31am UTC](https://discourse.cmake.org/t/how-to-find-a-specific-python-module/1393 "2020-06-15T01:31:43Z")

</div>

I have a specific Python module that currently happens to be located at /home/software/plplot/installcmake/lib/python3.7/site-packages/\_plplotc.so The specific prefix part of that fullpath can be specified using the en…

---

## [cmake\_parse\_arguments causes all arguments to be unhandeled](https://discourse.cmake.org/t/cmake-parse-arguments-causes-all-arguments-to-be-unhandeled/1392)

<div class="topic-metadata">

**Author:** [@johnratius](https://discourse.cmake.org/u/johnratius)\
**Replies:** 4\
**Last updated:** [June 14, 2020, 10:45pm UTC](https://discourse.cmake.org/t/cmake-parse-arguments-causes-all-arguments-to-be-unhandeled/1392 "2020-06-14T22:45:31Z")

</div>

I have a function and am trying to pass arguments though. Specifically my project name, and then Source files for my project. It’s set up like this: function( make\_function ) set( oneValueArgs APP\_NAME ) set( multiVal…

---

## [find\_program issue with space in filename](https://discourse.cmake.org/t/find-program-issue-with-space-in-filename/1365)

<div class="topic-metadata">

**Author:** [@fry](https://discourse.cmake.org/u/fry)\
**Replies:** 2\
**Last updated:** [June 10, 2020, 11:01pm UTC](https://discourse.cmake.org/t/find-program-issue-with-space-in-filename/1365 "2020-06-10T23:01:10Z")

</div>

I have the following code: find\_program( RECON\_EXE NAMES "Reason Recon" "Reason Recon 11 RESDK41 Logging" PATHS "/Applications/Reason Recon" "/Applications" "c:/Program Files/Propellerhead/Reason Recon" ) me…

---

## [Behaviour of source\_group(TREE ...) with no FILES specified](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 2\
**Last updated:** [June 9, 2020, 10:40pm UTC](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357 "2020-06-09T22:40:32Z")

</div>

Generating for Xcode using CMake 3.15.3: Why does: source\_group(TREE ${CMAKE\_CURRENT\_SOURCE\_DIR}/${my\_source\_subdir} FILES ${my\_files}) do something sensible (all source files in a nested structure), while source\_gro…

---

## [Linking towards an older OS version (Mac)](https://discourse.cmake.org/t/linking-towards-an-older-os-version-mac/1351)

<div class="topic-metadata">

**Author:** [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)\
**Replies:** 2\
**Last updated:** [June 9, 2020, 8:20pm UTC](https://discourse.cmake.org/t/linking-towards-an-older-os-version-mac/1351 "2020-06-09T20:20:38Z")

</div>

I have my executable working on MacOSX Catalina. However, since I am not using any of the features of it, I would like to target the earliest version os the OS I can, like, say, Mojave. I would like to know what flags/…

---

## [CMake project review and suggestions (closed)](https://discourse.cmake.org/t/cmake-project-review-and-suggestions-closed/768)

<div class="topic-metadata">

**Author:** [@Artemis](https://discourse.cmake.org/u/Artemis)\
**Replies:** 34\
**Last updated:** [June 8, 2020, 2:10pm UTC](https://discourse.cmake.org/t/cmake-project-review-and-suggestions-closed/768 "2020-06-08T14:10:42Z")

</div>

I’m working on my first CMake project, a C library. I’ll ask for help and suggestions as I make progress (like an “art review”, but for CMake) I’ve read plenty of material on the subject (documentation included, of cou…

---

## [Avoid Macport dependencies on MacOS](https://discourse.cmake.org/t/avoid-macport-dependencies-on-macos/1335)

<div class="topic-metadata">

**Author:** [@JanWielemaker](https://discourse.cmake.org/u/JanWielemaker)\
**Replies:** 3\
**Last updated:** [June 8, 2020, 1:03pm UTC](https://discourse.cmake.org/t/avoid-macport-dependencies-on-macos/1335 "2020-06-08T13:03:51Z")

</div>

I’m trying to build a bundle for MacOS. To do so, I’ve built the project dependencies in some local directory setting the minimal deployment target to 10.12 and do the same for the project itself, hoping to end up with…

---

## [Visual Studio - External Dependencies Empty?](https://discourse.cmake.org/t/visual-studio-external-dependencies-empty/1285)

<div class="topic-metadata">

**Author:** [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Replies:** 3\
**Last updated:** [June 5, 2020, 6:24pm UTC](https://discourse.cmake.org/t/visual-studio-external-dependencies-empty/1285 "2020-06-05T18:24:35Z")

</div>

I’m having serious issues related to my visual studio solutions cmake is generating. I’m unable to “Find All References” or it takes a ridiculously slow time. When I click on got to definition on files I know are be…

---

## [Copy (changed) scripts as part of build](https://discourse.cmake.org/t/copy-changed-scripts-as-part-of-build/1320)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 3\
**Last updated:** [June 5, 2020, 1:30pm UTC](https://discourse.cmake.org/t/copy-changed-scripts-as-part-of-build/1320 "2020-06-05T13:30:21Z")

</div>

In my Make architecture, I had the following: Directory/ Makefile src bin (output goes here) \*\* my\_exe run/ \*\* run1.sh \*\* run2.sh \*\* run3.sh The run\*.sh scripts all run "…/bin/my\_exe ". my\_exe itself is a dummy …

---

## [CMake: can't find library header files](https://discourse.cmake.org/t/cmake-cant-find-library-header-files/1334)

<div class="topic-metadata">

**Author:** [@unbdd](https://discourse.cmake.org/u/unbdd)\
**Replies:** 2\
**Last updated:** [June 5, 2020, 7:37am UTC](https://discourse.cmake.org/t/cmake-cant-find-library-header-files/1334 "2020-06-05T07:37:36Z")

</div>

I have a CMake project with the following folder structure: my\_project ├── build ├── CMakeLists.txt ├── hello\_test │ ├── CMakeLists.txt │ └── main.cpp └── my\_libs └── hello\_lib ├── CMakeLists.txt …

---

## [cmake does not follow symlinks on windows](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322)

<div class="topic-metadata">

**Author:** [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Replies:** 9\
**Last updated:** [June 4, 2020, 5:20pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322 "2020-06-04T17:20:33Z")

</div>

get\_filename\_component(... REALPATH) and file (INSTALL ... DESTINATION ... USE\_SOURCE\_PERMISSIONS FOLLOW\_SYMLINK\_CHAIN) do not process symbolic links on windows. Is this a known problem (cmake 3.17.2)?

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

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