如何为CMAKE外部项目指定编译器?

dow*_*dow 1 c++ cmake

我在ExternalProject_Add中包含一个外部项目。我想要做的是

cmake -DCMAKE_CXX_COMPILER=<some compiler> <assume correct path>
Run Code Online (Sandbox Code Playgroud)

顶级项目,以便我选择的编译器传播到外部包含的项目。我希望可以在ExternalProject_Add命令中添加一些内容:

ExternalProject_Add (

  some_external_project

  PREFIX ...            # Assume this works.
  GIT_REPOSITORY ...    # Assume this works too.

  # What should I write here to tell it to use the ${CMAKE_CXX_COMPILER}
  # of the top-level project ?
)
Run Code Online (Sandbox Code Playgroud)

dow*_*dow 6

以下内容为我在顶级项目中工作:

ExternalProject_Add (

  some_external_project

  PREFIX ...          # Assume this works.
  GIT_REPOSITORY ...  # Assume this works too.

  # This did the trick for me.
  CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
)
Run Code Online (Sandbox Code Playgroud)

  • 为什么这会被否决?似乎是一种有效的方法。 (5认同)