# Code

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

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

**Page:** 63

---

## [Transitioning to Namespace in CMakeLists.txt](https://discourse.cmake.org/t/transitioning-to-namespace-in-cmakelists-txt/2744)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 1\
**Last updated:** [February 11, 2021, 4:41pm UTC](https://discourse.cmake.org/t/transitioning-to-namespace-in-cmakelists-txt/2744 "2021-02-11T16:41:08Z")

</div>

This is a bit of an odd question, but I’m trying to write “elegant” CMake code instead of hacky. The issue is that I work on a project that brings in libraries with find\_package() and some of the dependency libraries hav…

---

## [How to get object file to link first?](https://discourse.cmake.org/t/how-to-get-object-file-to-link-first/2729)

<div class="topic-metadata">

**Author:** [@Mats\_Liljegren](https://discourse.cmake.org/u/Mats_Liljegren)\
**Replies:** 4\
**Last updated:** [February 11, 2021, 1:46pm UTC](https://discourse.cmake.org/t/how-to-get-object-file-to-link-first/2729 "2021-02-11T13:46:20Z")

</div>

I’m trying to compile a Windows DLL for code originally intended for a Unix platform. One problem I have is that Windows fopen() defaults to O\_TEXT, but Unix defaults to O\_BINARY. Windows recommends two ways to solve th…

---

## [delayload inconsistency between Visual Studio and Ninja generators](https://discourse.cmake.org/t/delayload-inconsistency-between-visual-studio-and-ninja-generators/2719)

<div class="topic-metadata">

**Author:** [@rconde01](https://discourse.cmake.org/u/rconde01)\
**Replies:** 2\
**Last updated:** [February 8, 2021, 10:01pm UTC](https://discourse.cmake.org/t/delayload-inconsistency-between-visual-studio-and-ninja-generators/2719 "2021-02-08T22:01:39Z")

</div>

Consider the following example which has a delay loaded dll. When building with the Visual Studio generator it builds fine. However, with the Ninja generator you get: dll.lib(dll.dll) : error LNK2001: unresolved externa…

---

## [Set the "Additional Dependencies " option in under the Librarian Tag while creating a Static Library Project](https://discourse.cmake.org/t/set-the-additional-dependencies-option-in-under-the-librarian-tag-while-creating-a-static-library-project/2721)

<div class="topic-metadata">

**Author:** [@PranaliTirkhunde](https://discourse.cmake.org/u/PranaliTirkhunde)\
**Replies:** 1\
**Last updated:** [February 8, 2021, 6:19pm UTC](https://discourse.cmake.org/t/set-the-additional-dependencies-option-in-under-the-librarian-tag-while-creating-a-static-library-project/2721 "2021-02-08T18:19:24Z")

</div>

Hi, I am trying to create a Static Library Project in Visual Studio 2017. I wish to add another Static library under the “Additional Dependencies” Tab in the Librarian section using CMake. I am using the following comma…

---

## [FetchContent cache variables](https://discourse.cmake.org/t/fetchcontent-cache-variables/1538)

<div class="topic-metadata">

**Author:** [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Replies:** 11\
**Last updated:** [February 8, 2021, 8:15am UTC](https://discourse.cmake.org/t/fetchcontent-cache-variables/1538 "2021-02-08T08:15:22Z")

</div>

Hi everyone, I wondered what the best method is to pass values for cache variables to a project included with FetchContent. Say I do want shared libs and no testing for that lib and use some project specific option, I …

---

## [Use variables or genexes with usage requirements?](https://discourse.cmake.org/t/use-variables-or-genexes-with-usage-requirements/2679)

<div class="topic-metadata">

**Author:** [@Angew](https://discourse.cmake.org/u/Angew)\
**Replies:** 3\
**Last updated:** [February 8, 2021, 8:07am UTC](https://discourse.cmake.org/t/use-variables-or-genexes-with-usage-requirements/2679 "2021-02-08T08:07:03Z")

</div>

Hi all, I have a question about setting usage requirements which depend on platform or compiler. Assume I have a C++ library Foo such that: When consumers link against it on Windows, they must define FOO\_WINDOWS. When …

---

## [How to add a JAR file to a C++ Qt Widgets for Android project?](https://discourse.cmake.org/t/how-to-add-a-jar-file-to-a-c-qt-widgets-for-android-project/597)

<div class="topic-metadata">

**Author:** [@ludo](https://discourse.cmake.org/u/ludo)\
**Replies:** 1\
**Last updated:** [February 5, 2021, 9:04pm UTC](https://discourse.cmake.org/t/how-to-add-a-jar-file-to-a-c-qt-widgets-for-android-project/597 "2021-02-05T21:04:09Z")

</div>

Ubuntu 18.04 cmake 3.15.3 Qt Creator 4.11.0 Qt 5.14.1 for Android Android NDK r21 Android ABI arm64-v8a Using the clang++ compiler from the NDK r21 toolchain: /home/cosmo/android-ndk-r21/toolchains/llvm/prebuilt/l…

---

## [With multiple configurations, is it possible to add\_custom\_command as a final step?](https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704)

<div class="topic-metadata">

**Author:** [@jice73](https://discourse.cmake.org/u/jice73)\
**Replies:** 1\
**Last updated:** [February 5, 2021, 7:57pm UTC](https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704 "2021-02-05T19:57:22Z")

</div>

This is on a build box, where the generator is "Ninja Multi-Config", and -DCMAKE\_CONFIGURATION\_TYPES="Release;Debug" -DCMAKE\_DEFAULT\_CONFIGS=all. After the project is built (it has multiple libraries), I want to run a c…

---

## ["::@\<address\>" as suffix of returned item of LINK\_LIBRARIES](https://discourse.cmake.org/t/address-as-suffix-of-returned-item-of-link-libraries/2699)

<div class="topic-metadata">

**Author:** [@Shaun-Cox](https://discourse.cmake.org/u/Shaun-Cox)\
**Replies:** 3\
**Last updated:** [February 5, 2021, 3:01pm UTC](https://discourse.cmake.org/t/address-as-suffix-of-returned-item-of-link-libraries/2699 "2021-02-05T15:01:24Z")

</div>

I’m calling get\_target\_property for LINK\_LIBRARIES on targets that I want to enumerate dependencies of. I noticed that sometimes I’m returned strings like this: MyTargetA::@\<0000016D82804B50\> and other times (the norm…

---

## [Undefined third-party library symbols when building dylib on MacOS](https://discourse.cmake.org/t/undefined-third-party-library-symbols-when-building-dylib-on-macos/2671)

<div class="topic-metadata">

**Author:** [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)\
**Replies:** 4\
**Last updated:** [February 3, 2021, 11:00pm UTC](https://discourse.cmake.org/t/undefined-third-party-library-symbols-when-building-dylib-on-macos/2671 "2021-02-03T23:00:20Z")

</div>

The following command generates a Makefile on linux that properly builds a .so library: # Shared library add\_library(mbauxShared SHARED mb\_cheb.c mb\_delaun.c mb\_intersectgrid.c mb\_readwritegrd.c …

---

## [IDEs and header files](https://discourse.cmake.org/t/ides-and-header-files/2665)

<div class="topic-metadata">

**Author:** [@Andrew](https://discourse.cmake.org/u/Andrew)\
**Replies:** 2\
**Last updated:** [February 3, 2021, 6:41pm UTC](https://discourse.cmake.org/t/ides-and-header-files/2665 "2021-02-03T18:41:04Z")

</div>

Sample project: add\_library( a ) target\_sources( a PRIVATE a.c PUBLIC a.h ) add\_library( b ) target\_sources( b PRIVATE b.c PUBLIC b.h ) target\_link\_libraries( b PUBLIC a ) When I bring this up in my IDE, target a has…

---

## [Are square brackets universally supported by file(GLOB)?](https://discourse.cmake.org/t/are-square-brackets-universally-supported-by-file-glob/2674)

<div class="topic-metadata">

**Author:** [@arclight](https://discourse.cmake.org/u/arclight)\
**Replies:** 5\
**Last updated:** [February 3, 2021, 2:00pm UTC](https://discourse.cmake.org/t/are-square-brackets-universally-supported-by-file-glob/2674 "2021-02-03T14:00:07Z")

</div>

Hi, I have a situation where an application adds timestamp information to output file names and I’m trying to strip that out so I can automate regression testing. File names are of the format EXzzhhmm.nnn where zz is a…

---

## [Copy data files to build dir and avoid Debug/Release folder when using MSVC](https://discourse.cmake.org/t/copy-data-files-to-build-dir-and-avoid-debug-release-folder-when-using-msvc/2632)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 3\
**Last updated:** [February 2, 2021, 12:50pm UTC](https://discourse.cmake.org/t/copy-data-files-to-build-dir-and-avoid-debug-release-folder-when-using-msvc/2632 "2021-02-02T12:50:42Z")

</div>

Hi, In my tests (I use google test) I use some external my\_file.txt. Thus I need to put this my\_file.txt to the build dir. It is known that MSVC creates additional config (Debug/Release) folder and other compilers don’…

---

## [\[solved\] How to include library](https://discourse.cmake.org/t/solved-how-to-include-library/2670)

<div class="topic-metadata">

**Author:** [@start\_something](https://discourse.cmake.org/u/start_something)\
**Replies:** 1\
**Last updated:** [February 1, 2021, 8:56pm UTC](https://discourse.cmake.org/t/solved-how-to-include-library/2670 "2021-02-01T20:56:20Z")

</div>

Hi! I’m just starting out with cmake, so I expect that this might be a beginner question. When I wrote my own make file, I could just add -lncurses to my CXXFLAGS variable and it would automatically pick up my ncurses …

---

## [ExternalProject\_Add and setting/appending to CMAKE\_CXX\_FLAGS](https://discourse.cmake.org/t/externalproject-add-and-setting-appending-to-cmake-cxx-flags/1275)

<div class="topic-metadata">

**Author:** [@KrisThielemans](https://discourse.cmake.org/u/KrisThielemans)\
**Replies:** 5\
**Last updated:** [January 29, 2021, 2:16pm UTC](https://discourse.cmake.org/t/externalproject-add-and-setting-appending-to-cmake-cxx-flags/1275 "2021-01-29T14:16:32Z")

</div>

We use a SuperBuild and need to pass extra compiler flags on Windows with Visual Studio to the (CMake-based) external project. We have no control over the project. My strategy was to do something like ExternalProject\_A…

---

## [How to portably specify header search paths to target\_include\_directories()?](https://discourse.cmake.org/t/how-to-portably-specify-header-search-paths-to-target-include-directories/2638)

<div class="topic-metadata">

**Author:** [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)\
**Replies:** 4\
**Last updated:** [January 27, 2021, 5:56pm UTC](https://discourse.cmake.org/t/how-to-portably-specify-header-search-paths-to-target-include-directories/2638 "2021-01-27T17:56:15Z")

</div>

Library mylib contains file foo.c which includes: #include \<Xm/Xm.h\> On my linux system, file /usr/include/Xm/Xm.h exists and /usr/include is treated as a “system” header directory by the compiler, and so there’s no ne…

---

## [.lst file generation in cmake](https://discourse.cmake.org/t/lst-file-generation-in-cmake/2600)

<div class="topic-metadata">

**Author:** [@deepan](https://discourse.cmake.org/u/deepan)\
**Replies:** 2\
**Last updated:** [January 27, 2021, 4:09am UTC](https://discourse.cmake.org/t/lst-file-generation-in-cmake/2600 "2021-01-27T04:09:34Z")

</div>

i want to generate .lst files for my source file. I am successfully able to generate the executable. But i dont know how to generate .lst files for my source files. get\_property(allsrcfiles TARGET myExe PROPERTY SOURCE…

---

## [Help with try\_run() and CMAKE\_FLAGS](https://discourse.cmake.org/t/help-with-try-run-and-cmake-flags/2636)

<div class="topic-metadata">

**Author:** [@mathomp4](https://discourse.cmake.org/u/mathomp4)\
**Replies:** 3\
**Last updated:** [January 26, 2021, 3:07pm UTC](https://discourse.cmake.org/t/help-with-try-run-and-cmake-flags/2636 "2021-01-26T15:07:23Z")

</div>

All, I’m trying to figure out how to test if a compiler flag runs on a processor. The issue is that I’m porting some code from Intel chips to AMD Rome chips and I’ve found that if I compile (using Intel Fortran) with -x…

---

## [How to find third-party header files in /Applications on MacOS?](https://discourse.cmake.org/t/how-to-find-third-party-header-files-in-applications-on-macos/2597)

<div class="topic-metadata">

**Author:** [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)\
**Replies:** 2\
**Last updated:** [January 22, 2021, 1:58pm UTC](https://discourse.cmake.org/t/how-to-find-third-party-header-files-in-applications-on-macos/2597 "2021-01-22T13:58:25Z")

</div>

What CMAKE\_ variable should I include in the PATHS argument to find\_file(), such that /Applications will be searched on MacOS? For example: I’m running MacOS 10.13.6 (“High Sierra”), and I’ve installed a third-party app…

---

## [express the right dependencies in CMake](https://discourse.cmake.org/t/express-the-right-dependencies-in-cmake/2333)

<div class="topic-metadata">

**Author:** [@Massimiliano\_Cialdi](https://discourse.cmake.org/u/Massimiliano_Cialdi)\
**Replies:** 7\
**Last updated:** [January 22, 2021, 11:37am UTC](https://discourse.cmake.org/t/express-the-right-dependencies-in-cmake/2333 "2021-01-22T11:37:45Z")

</div>

Hi, in my projects I have a header file that is generated at build-time. It is included from a single .c file. So the chain of dependencies would be as follows: executable -\> file.o -\> header generated. How is it poss…

---

## [use cmake to generate pdb](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583)

<div class="topic-metadata">

**Author:** [@NanaSeino233](https://discourse.cmake.org/u/NanaSeino233)\
**Replies:** 8\
**Last updated:** [January 21, 2021, 3:24pm UTC](https://discourse.cmake.org/t/use-cmake-to-generate-pdb/2583 "2021-01-21T15:24:22Z")

</div>

我正在使用cmake编译leptonica1.78，在生成sln方案后，我使用了vs2017来生成.dll动态链接库， 当用实用工具cppan-d-b-d来生成pvt.cppan.demo.jpeg-9.2.0.dll等依赖时，并没有生成pdb文件，由于配置属性是utility，在vs2017中无法更改设置。 我想请教一下cmake中有没有指令可以配置utility生成pdb文件。 目前尝试过的指令是 “set(CMAKE\_CXX…

---

## [CMake: Common dependency between different projects](https://discourse.cmake.org/t/cmake-common-dependency-between-different-projects/2593)

<div class="topic-metadata">

**Author:** [@pmylon](https://discourse.cmake.org/u/pmylon)\
**Replies:** 1\
**Last updated:** [January 21, 2021, 3:19pm UTC](https://discourse.cmake.org/t/cmake-common-dependency-between-different-projects/2593 "2021-01-21T15:19:15Z")

</div>

Hello! I have a question regarding a project (C++, CMake) I am working on. Let’s assume the following simplified project structure for demonstration purposes (each folder contains some source and header files): demo\_pr…

---

## [ExternalProject Premature Completion](https://discourse.cmake.org/t/externalproject-premature-completion/1690)

<div class="topic-metadata">

**Author:** [@jameskr97](https://discourse.cmake.org/u/jameskr97)\
**Replies:** 2\
**Last updated:** [January 21, 2021, 7:07am UTC](https://discourse.cmake.org/t/externalproject-premature-completion/1690 "2021-01-21T07:07:36Z")

</div>

Hi CMake Community, I’m currently trying to add crashpad as a dependency to my C++ project. I have chosen to gather all the dependencies from chromium needed to build my project, and even go as far to commit some binari…

---

## [Exporting renamed/multiple-named configs](https://discourse.cmake.org/t/exporting-renamed-multiple-named-configs/2586)

<div class="topic-metadata">

**Author:** [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Replies:** 2\
**Last updated:** [January 20, 2021, 10:16pm UTC](https://discourse.cmake.org/t/exporting-renamed-multiple-named-configs/2586 "2021-01-20T22:16:46Z")

</div>

I’m trying to find a way to rename an existing CMake project, but in a way that avoids disrupting existing users. Those users will (at least initially, and for a time) be expecting the project to define the options, targ…

---

## [Custom command output location](https://discourse.cmake.org/t/custom-command-output-location/2571)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 3\
**Last updated:** [January 20, 2021, 8:35am UTC](https://discourse.cmake.org/t/custom-command-output-location/2571 "2021-01-20T08:35:39Z")

</div>

When using a multi-config generator like Visual Studio, objects and libraries are (by default) placed in ${CMAKE\_CURRENT\_BINARY\_DIR}/$\<CONFIG\>. Now, suppose I have a library target, myLib and I want to process it with so…

---

## [How to find C11 threads](https://discourse.cmake.org/t/how-to-find-c11-threads/2506)

<div class="topic-metadata">

**Author:** [@Wirtos](https://discourse.cmake.org/u/Wirtos)\
**Replies:** 4\
**Last updated:** [January 19, 2021, 7:40pm UTC](https://discourse.cmake.org/t/how-to-find-c11-threads/2506 "2021-01-19T19:40:37Z")

</div>

I was trying to create a project involving the use of C11 threads, but I can’t find the requirements in the CMAKE\_C\_KNOWN\_FEATURES nor in the FindThreads package. Should I write custom detection code for this purpose, or…

---

## [Propagation of FetchContent targets when installing](https://discourse.cmake.org/t/propagation-of-fetchcontent-targets-when-installing/2559)

<div class="topic-metadata">

**Author:** [@tomhh](https://discourse.cmake.org/u/tomhh)\
**Replies:** 11\
**Last updated:** [January 18, 2021, 8:22pm UTC](https://discourse.cmake.org/t/propagation-of-fetchcontent-targets-when-installing/2559 "2021-01-18T20:22:59Z")

</div>

Hi there, I’ve run into this issue I don’t quite understand and was hoping someone could help clarify. I have a simple header-only library (LibA) which is used by a static library (LibB) via FetchContent. I would like …

---

## [Link shared cmake target with prebuilt static libraries (PIC)](https://discourse.cmake.org/t/link-shared-cmake-target-with-prebuilt-static-libraries-pic/2504)

<div class="topic-metadata">

**Author:** [@jazu.dev](https://discourse.cmake.org/u/jazu.dev)\
**Replies:** 2\
**Last updated:** [January 17, 2021, 4:46pm UTC](https://discourse.cmake.org/t/link-shared-cmake-target-with-prebuilt-static-libraries-pic/2504 "2021-01-17T16:46:13Z")

</div>

Greetings, In my CMakeLists.txt I declare a shared library target (for Android/JNI): add\_library(native-lib SHARED native-lib.cpp) That depends on an external static library, which then depends upon a bunch of other s…

---

## [Intel oneAPI Gold release broken (Linux, Windows)](https://discourse.cmake.org/t/intel-oneapi-gold-release-broken-linux-windows/2340)

<div class="topic-metadata">

**Author:** [@scivision](https://discourse.cmake.org/u/scivision)\
**Replies:** 3\
**Last updated:** [January 15, 2021, 2:44am UTC](https://discourse.cmake.org/t/intel-oneapi-gold-release-broken-linux-windows/2340 "2021-01-15T02:44:06Z")

</div>

Intel oneAPI compilers worked across several beta versions as well as several CMake versions. I simply use icc/icl + ifort so I think this is unrelated to the IntelClang and DPC++ currently in CMake GitLab MRs. However,…

---

## [Launching a daemon/service using CTest](https://discourse.cmake.org/t/launching-a-daemon-service-using-ctest/2515)

<div class="topic-metadata">

**Author:** [@agouaillard](https://discourse.cmake.org/u/agouaillard)\
**Replies:** 4\
**Last updated:** [January 12, 2021, 7:08pm UTC](https://discourse.cmake.org/t/launching-a-daemon-service-using-ctest/2515 "2021-01-12T19:08:35Z")

</div>

goal I’m trying to implement automatic testing of several native apps using Appium. The steps would be as follow for each app: configure the Appium node with name and path of executable start the Appium node run my …

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

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