# Code

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

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

**Page:** 58

---

## [Run command at beginning of make](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649)

<div class="topic-metadata">

**Author:** [@jaykemper](https://discourse.cmake.org/u/jaykemper)\
**Replies:** 2\
**Last updated:** [June 28, 2021, 10:48pm UTC](https://discourse.cmake.org/t/run-command-at-beginning-of-make/3649 "2021-06-28T22:48:31Z")

</div>

I’m trying to get git information for my project build. The “execute\_process” command runs during the configuration of the project (“cmake /path/to/project/”): execute\_process( COMMAND git describe --tag --always WOR…

---

## [Connect libs folder](https://discourse.cmake.org/t/connect-libs-folder/3636)

<div class="topic-metadata">

**Author:** [@Snowii](https://discourse.cmake.org/u/Snowii)\
**Replies:** 7\
**Last updated:** [June 28, 2021, 7:22pm UTC](https://discourse.cmake.org/t/connect-libs-folder/3636 "2021-06-28T19:22:27Z")

</div>

Hello, I’m new to CMake and wanted to ask if someone can answer my question: How can I connect the whole libs tree folder because I don’t want to connect every single lib that is in there myself

---

## [Avoid repeating generator expression?](https://discourse.cmake.org/t/avoid-repeating-generator-expression/3645)

<div class="topic-metadata">

**Author:** [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Replies:** 2\
**Last updated:** [June 28, 2021, 5:56pm UTC](https://discourse.cmake.org/t/avoid-repeating-generator-expression/3645 "2021-06-28T17:56:33Z")

</div>

I have a CMakeLists.txt file which contains three targets. Two of these targets have target\_compile\_definitions which contain long but identical generator expressions. Since I try to adhere to the DRY principle I am wond…

---

## [Cmake build error hook](https://discourse.cmake.org/t/cmake-build-error-hook/3634)

<div class="topic-metadata">

**Author:** [@Christer\_Ekholm](https://discourse.cmake.org/u/Christer_Ekholm)\
**Replies:** 7\
**Last updated:** [June 28, 2021, 11:43am UTC](https://discourse.cmake.org/t/cmake-build-error-hook/3634 "2021-06-28T11:43:21Z")

</div>

Is it possible to add hooks to error in build? My target is fixing automatically problem with “file(GLOB” what will cause linking error if new files are coming to system after Cmake is runned. Idea would be that build …

---

## [CMAKE\_MSVCIDE\_RUN\_PATH](https://discourse.cmake.org/t/cmake-msvcide-run-path/3617)

<div class="topic-metadata">

**Author:** [@Maarten\_Braakhekke](https://discourse.cmake.org/u/Maarten_Braakhekke)\
**Replies:** 9\
**Last updated:** [June 25, 2021, 12:54pm UTC](https://discourse.cmake.org/t/cmake-msvcide-run-path/3617 "2021-06-25T12:54:19Z")

</div>

My project has a custom target that prepares some files that are later used in a test. The command of the custom target uses a tool that requires some shared libraries to be on the path. I don’t want to force my users to…

---

## [Using SWIG-generated files in another project](https://discourse.cmake.org/t/using-swig-generated-files-in-another-project/1748)

<div class="topic-metadata">

**Author:** [@harold.absalom](https://discourse.cmake.org/u/harold.absalom)\
**Replies:** 3\
**Last updated:** [June 24, 2021, 11:38pm UTC](https://discourse.cmake.org/t/using-swig-generated-files-in-another-project/1748 "2021-06-24T23:38:26Z")

</div>

I am attempting to use SWIG to generate a C# wrapper for some C++ code, and then use that generated code in another C# project. Right now, I’m just trying to get things working in an example project. Starting with the CM…

---

## [include cmake file generated by install step](https://discourse.cmake.org/t/include-cmake-file-generated-by-install-step/3568)

<div class="topic-metadata">

**Author:** [@cmak](https://discourse.cmake.org/u/cmak)\
**Replies:** 5\
**Last updated:** [June 24, 2021, 2:13pm UTC](https://discourse.cmake.org/t/include-cmake-file-generated-by-install-step/3568 "2021-06-24T14:13:55Z")

</div>

I’m building using ExternalProject\_Add. This will export a cmake file. Now I want to include that cmake file to import the targets. How can that be done? E.g. adding include requires the file to exist in the configure st…

---

## [Multiple library instances in superbuild structure.](https://discourse.cmake.org/t/multiple-library-instances-in-superbuild-structure/3605)

<div class="topic-metadata">

**Author:** [@codelimit](https://discourse.cmake.org/u/codelimit)\
**Replies:** 0\
**Last updated:** [June 22, 2021, 8:15am UTC](https://discourse.cmake.org/t/multiple-library-instances-in-superbuild-structure/3605 "2021-06-22T08:15:00Z")

</div>

Good day, dear community! I’m working on a project with superbuild structure. I have several executable targets which depend on same static library. This library is a framework (or some kind of engine), that hides all p…

---

## [Genex unexpected behavior](https://discourse.cmake.org/t/genex-unexpected-behavior/3598)

<div class="topic-metadata">

**Author:** [@serge](https://discourse.cmake.org/u/serge)\
**Replies:** 4\
**Last updated:** [June 21, 2021, 12:54pm UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598 "2021-06-21T12:54:21Z")

</div>

This is an example code that creates in windows two static libraries a.lib and b.lib while b.lib is a superset of a.lib with additional custom objects. I know that this could have been done in a simpler way - although t…

---

## [Windows librarian options issue](https://discourse.cmake.org/t/windows-librarian-options-issue/3597)

<div class="topic-metadata">

**Author:** [@serge](https://discourse.cmake.org/u/serge)\
**Replies:** 2\
**Last updated:** [June 21, 2021, 12:50pm UTC](https://discourse.cmake.org/t/windows-librarian-options-issue/3597 "2021-06-21T12:50:56Z")

</div>

I am building a static library in windows: add\_library(somelib STATIC asource.cpp) I would like to use the /NODEFAULTLIB option with the librarian command of windows so I call: add\_link\_options(/NODEFAULTLIB) or tar…

---

## [Exposing BUILD\_SHARED\_LIBS via option?](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595)

<div class="topic-metadata">

**Author:** [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Replies:** 3\
**Last updated:** [June 20, 2021, 11:44pm UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595 "2021-06-20T23:44:03Z")

</div>

I have a best practices question. I read in the documentation regarding BUILD\_SHARED\_LIBS: https://cmake.org/cmake/help/latest/variable/BUILD\_SHARED\_LIBS.html This documentation contains the following passage: This v…

---

## [Copying script files to bin, checking them, setting execute bit.](https://discourse.cmake.org/t/copying-script-files-to-bin-checking-them-setting-execute-bit/3577)

<div class="topic-metadata">

**Author:** [@Thorbjorn\_Willoch](https://discourse.cmake.org/u/Thorbjorn_Willoch)\
**Replies:** 6\
**Last updated:** [June 19, 2021, 2:46pm UTC](https://discourse.cmake.org/t/copying-script-files-to-bin-checking-them-setting-execute-bit/3577 "2021-06-19T14:46:00Z")

</div>

I have a project that consist of C/C++/proto/bash. The C/C++ now works fine. proto works via an add\_custom\_command. (The cpp\_generate\_proto did not work with my protofiles in subdirectories) But I have not found a sat…

---

## [FindPython3: how to specify local installation directory for Python module?](https://discourse.cmake.org/t/findpython3-how-to-specify-local-installation-directory-for-python-module/3580)

<div class="topic-metadata">

**Author:** [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Replies:** 4\
**Last updated:** [June 17, 2021, 1:14pm UTC](https://discourse.cmake.org/t/findpython3-how-to-specify-local-installation-directory-for-python-module/3580 "2021-06-17T13:14:06Z")

</div>

include(GNUInstallDirs) find\_package(Python3 COMPONENTS Interpreter Development REQUIRED) ... install(FILES ${CMAKE\_CURRENT\_BINARY\_DIR}/mymodule.py DESTINATION ${Python3\_SITELIB}) installs to /usr/lib/python3/…

---

## [CMake update, then: Built-in flow control command "add\_custom\_target" cannot be overridden.](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576)

<div class="topic-metadata">

**Author:** [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Replies:** 4\
**Last updated:** [June 16, 2021, 2:44pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576 "2021-06-16T14:44:19Z")

</div>

Today I updated from 3.10 to 3.20. Then I get a lot of errors: Built-in flow control command "install" cannot be overridden. Built-in flow control command "get\_target\_property" cannot be overridden. Built-in flow contro…

---

## [Get runtime library of my target](https://discourse.cmake.org/t/get-runtime-library-of-my-target/3563)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 9\
**Last updated:** [June 15, 2021, 12:52am UTC](https://discourse.cmake.org/t/get-runtime-library-of-my-target/3563 "2021-06-15T00:52:36Z")

</div>

Hi, I’m creating a library with add\_library(h5geo SHARED ${src\_files\_h5geo} ${include\_files\_h5geo}). Then I need to get path to h5geo runtime library (for now I’m on Windows so I would like to get path to h5geo.dll) I…

---

## [Changing Java Version inside CMake](https://discourse.cmake.org/t/changing-java-version-inside-cmake/3541)

<div class="topic-metadata">

**Author:** [@inevo](https://discourse.cmake.org/u/inevo)\
**Replies:** 3\
**Last updated:** [June 14, 2021, 11:24am UTC](https://discourse.cmake.org/t/changing-java-version-inside-cmake/3541 "2021-06-14T11:24:02Z")

</div>

Hi, I need to cross-compile a jar and a shared library so that they will be imported into an Android application and ran on a machine running Ubuntu. For this reason I would like to create a CMakeLists.txt file that will…

---

## [What is the correct way to set options of a project before Fetch Content?](https://discourse.cmake.org/t/what-is-the-correct-way-to-set-options-of-a-project-before-fetch-content/268)

<div class="topic-metadata">

**Author:** [@Adem\_Budak](https://discourse.cmake.org/u/Adem_Budak)\
**Replies:** 5\
**Last updated:** [June 14, 2021, 5:39am UTC](https://discourse.cmake.org/t/what-is-the-correct-way-to-set-options-of-a-project-before-fetch-content/268 "2021-06-14T05:39:54Z")

</div>

I want to disable some of the properties that the project I need to fetch, so I set the options just before the FetchContent declarations in my project/tests/CMakeLists.txt: set(XXX\_BUILD\_TESTING OFF) set(XXX\_ENABLE…

---

## [Problems when porting a library target from ExternalProject\_Add](https://discourse.cmake.org/t/problems-when-porting-a-library-target-from-externalproject-add/3522)

<div class="topic-metadata">

**Author:** [@psionic12](https://discourse.cmake.org/u/psionic12)\
**Replies:** 4\
**Last updated:** [June 14, 2021, 5:32am UTC](https://discourse.cmake.org/t/problems-when-porting-a-library-target-from-externalproject-add/3522 "2021-06-14T05:32:43Z")

</div>

I’m trying to import a Rust project to my C++ project, I write the CMake code as below: include(ExternalProject) ExternalProject\_Add( quiche\_source GIT\_REPOSITORY https://github.com/cloudflare/quiche.git…

---

## [What's the best way to add thirdparty lib with existing makefile?](https://discourse.cmake.org/t/whats-the-best-way-to-add-thirdparty-lib-with-existing-makefile/3397)

<div class="topic-metadata">

**Author:** [@Lin](https://discourse.cmake.org/u/Lin)\
**Replies:** 4\
**Last updated:** [June 14, 2021, 5:28am UTC](https://discourse.cmake.org/t/whats-the-best-way-to-add-thirdparty-lib-with-existing-makefile/3397 "2021-06-14T05:28:04Z")

</div>

Hi there, I’m new to CMake, and I’m currently trying to add a third-party library into my CMake project. My problem is that this third-party library only builds on Linux and comes with its own makefile. I figure this is…

---

## [CMake Invalid Preset](https://discourse.cmake.org/t/cmake-invalid-preset/3538)

<div class="topic-metadata">

**Author:** [@HackingPheasant](https://discourse.cmake.org/u/HackingPheasant)\
**Replies:** 7\
**Last updated:** [June 11, 2021, 4:31pm UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538 "2021-06-11T16:31:19Z")

</div>

My first attempt at creating a CMakePrests.json, when trying to list my presets, I get an invalid preset warning. I verified my preset validates against the scheme, so nothing obviously wrong jumps out at me, so any he…

---

## [How write CMakeLists.txt for Windows for wxWidgets and Boost ?](https://discourse.cmake.org/t/how-write-cmakelists-txt-for-windows-for-wxwidgets-and-boost/3512)

<div class="topic-metadata">

**Author:** [@AndrzejB](https://discourse.cmake.org/u/AndrzejB)\
**Replies:** 3\
**Last updated:** [June 9, 2021, 11:41pm UTC](https://discourse.cmake.org/t/how-write-cmakelists-txt-for-windows-for-wxwidgets-and-boost/3512 "2021-06-09T23:41:15Z")

</div>

Creating CMakeLists.txt on Linux for these is simple but are problems on Windows with MinGw or Visual (generating project from CMakeLists.txt). What are minimal examples for wxWidgets and Boost on Windows?

---

## [Reusing object files without creating targets](https://discourse.cmake.org/t/reusing-object-files-without-creating-targets/3529)

<div class="topic-metadata">

**Author:** [@Olsen\_Carter](https://discourse.cmake.org/u/Olsen_Carter)\
**Replies:** 1\
**Last updated:** [June 8, 2021, 10:48pm UTC](https://discourse.cmake.org/t/reusing-object-files-without-creating-targets/3529 "2021-06-08T22:48:36Z")

</div>

Hi, I have an interesting problem. Our current build system reuses object files from other directories all the time. I have played around with using Object Libraries for an implementation in CMake. This would work great…

---

## [How to properly strip release binaries](https://discourse.cmake.org/t/how-to-properly-strip-release-binaries/3521)

<div class="topic-metadata">

**Author:** [@eri0](https://discourse.cmake.org/u/eri0)\
**Replies:** 5\
**Last updated:** [June 8, 2021, 8:02pm UTC](https://discourse.cmake.org/t/how-to-properly-strip-release-binaries/3521 "2021-06-08T20:02:29Z")

</div>

Hi, I would like that my application binaries were stripped in the release builds. My application currently builds for Linux, Windows, MacOS and Android. What’s the proper CMake way of doing this?

---

## [Why can't I re-export an imported executable?](https://discourse.cmake.org/t/why-cant-i-re-export-an-imported-executable/3489)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 2\
**Last updated:** [June 8, 2021, 3:46am UTC](https://discourse.cmake.org/t/why-cant-i-re-export-an-imported-executable/3489 "2021-06-08T03:46:16Z")

</div>

I want to make Halide’s build support cross-compilation. Host Halide depends on: Host LLVM libraries Host LLVM tools: llvm-as and clang Target Halide depends on: Host Halide tools Host LLVM tools: llvm-as and clan…

---

## [How to Install with saving Build RPATH ?](https://discourse.cmake.org/t/how-to-install-with-saving-build-rpath/3514)

<div class="topic-metadata">

**Author:** [@Artalus](https://discourse.cmake.org/u/Artalus)\
**Replies:** 0\
**Last updated:** [June 7, 2021, 10:32am UTC](https://discourse.cmake.org/t/how-to-install-with-saving-build-rpath/3514 "2021-06-07T10:32:13Z")

</div>

Our current packaging process deeply relies on the fact that all the binaries and dependencies are being built into the same /opt/stuff directories that they will be placed into upon “installation”. Yes, I know that it s…

---

## [Problem with shell escaping when building from Xcode generated project](https://discourse.cmake.org/t/problem-with-shell-escaping-when-building-from-xcode-generated-project/3510)

<div class="topic-metadata">

**Author:** [@Zorro666](https://discourse.cmake.org/u/Zorro666)\
**Replies:** 2\
**Last updated:** [June 7, 2021, 5:12am UTC](https://discourse.cmake.org/t/problem-with-shell-escaping-when-building-from-xcode-generated-project/3510 "2021-06-07T05:12:36Z")

</div>

I had a problem using a cmake ExternalProject build command when using the Xcode generator and then building from inside Xcode. If one of the shell variables being used contained a special character that required escapin…

---

## [Is GLOB still considered harmful with CONFIGURE\_DEPENDS?](https://discourse.cmake.org/t/is-glob-still-considered-harmful-with-configure-depends/808)

<div class="topic-metadata">

**Author:** [@alex](https://discourse.cmake.org/u/alex)\
**Replies:** 17\
**Last updated:** [June 5, 2021, 3:10pm UTC](https://discourse.cmake.org/t/is-glob-still-considered-harmful-with-configure-depends/808 "2021-06-05T15:10:31Z")

</div>

Supposing you’re able to use the newest, shiniest version of CMake, what are the current drawbacks for globbing sources with CONFIGURE\_DEPENDS? The documentation reads: Note: We do not recommend using GLOB to collect …

---

## [Define new variable in cmake configure script](https://discourse.cmake.org/t/define-new-variable-in-cmake-configure-script/3480)

<div class="topic-metadata">

**Author:** [@kerim](https://discourse.cmake.org/u/kerim)\
**Replies:** 8\
**Last updated:** [June 3, 2021, 2:19pm UTC](https://discourse.cmake.org/t/define-new-variable-in-cmake-configure-script/3480 "2021-06-03T14:19:26Z")

</div>

Hi, Let suppose I have a file called myconf.cmake.in and inside it I have: set(MY\_VAR ${CMAKE\_SOURCE\_DIR}) message(CMAKE\_SOURCE\_DIR: ${CMAKE\_SOURCE\_DIR}) message(MY\_VAR: ${MY\_VAR}) After doing configure\_file(${CMAKE…

---

## [file(GENERATE OUTPUT ...) CONDITION problem](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462)

<div class="topic-metadata">

**Author:** [@mbee](https://discourse.cmake.org/u/mbee)\
**Replies:** 2\
**Last updated:** [June 2, 2021, 8:53am UTC](https://discourse.cmake.org/t/file-generate-output-condition-problem/3462 "2021-06-02T08:53:20Z")

</div>

In order to expand some generator expressions, I’m using the file interface: file(GENERATE OUTPUT "$\<TARGET\_FILE\_DIR:${target}\>/eh\_support/${\_outname}" CONTENT " set(eh\_userfile\_id ${eh\_userfile\_id}) include(${EH\_FRAME…

---

## [Linking static libraries with custom object files](https://discourse.cmake.org/t/linking-static-libraries-with-custom-object-files/3453)

<div class="topic-metadata">

**Author:** [@serge](https://discourse.cmake.org/u/serge)\
**Replies:** 4\
**Last updated:** [June 1, 2021, 8:28pm UTC](https://discourse.cmake.org/t/linking-static-libraries-with-custom-object-files/3453 "2021-06-01T20:28:45Z")

</div>

Hi everyone, something that looks basic and as a new one to cmake, I may miss: Windows environment: I have two directories A and B B is a subdirectory of A Both have their own cmake file: A: add\_subdirectory(B) ad…

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

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