Domanda

Is there a concise way to pass almost all build flags to an external project in CMake? Essentially, I have a project that uses ExternalProject_Add in order to download and compile an external CMake project. On one particular platform, I need to modify most of the build flags like CMAKE_OBJCOPY, CMAKE_OBJDUMP, CMAKE_RANLIB, etc. to something other than the system default. Now, while I do this for the parent project that calls ExternalProject_Add, I would also like to pass down these options to the external project. Certainly, I can do this by setting the CMAKE_ARGS option in ExternalProject_Add, but there's quite a few flags to copy. Really, I'm looking for an option that copies all flags and then allows me to overwrite a few. As a final note, since I use ExternalProject_Add to download an archive, I have been hesitant to use add_subdirectory, which would copy all flags, since I can't give a URL.

È stato utile?

Soluzione

You can list all flags that you need in cmake toolchain file and pass to ExternalProject_Add only one option: CMAKE_TOOLCHAIN_FILE.

> cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(Foo)

message("SOME_ARG1: ${SOME_ARG1}")
message("SOME_ARG2: ${SOME_ARG2}")

> cat MyToolchain.cmake
set(SOME_ARG1 "arg1")
set(SOME_ARG2 "arg2")

> cmake -H. -B_builds/notoolchain
...
-- Detecting CXX compiler ABI info - done
SOME_ARG1:
SOME_ARG2:
-- Configuring done

> cmake -H. -B_builds/toolchain -DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake
...
-- Detecting CXX compiler ABI info - done
SOME_ARG1: arg1
SOME_ARG2: arg2
-- Configuring done
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top