Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the compiler for CMAKE external project?

Tags:

c++

cmake

I am including an external project with ExternalProject_Add. What I want is to be able to do

cmake -DCMAKE_CXX_COMPILER=<some compiler> <assume correct path>

for the top-level project so that my chosen compiler propagates to the externally included projects. I expect something that I can put in the ExternalProject_Add command:

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 ?
)
like image 567
dow Avatar asked Jan 28 '17 22:01

dow


People also ask

How does CMake know which compiler to use?

CMake needs a way to determine which compiler to use to invoke the linker. This is determined by the LANGUAGE property of source files of the target , and in the case of static libraries, the LANGUAGE of the dependent libraries.

What is a CMake external project?

CMake ExternalProject allows building a wide variety of subprojects isolated from the main CMake project. For GNU Make Makefile projects, it is necessary to invoke the make command.

Can you use CMake with C?

In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).


1 Answers

The following worked for me in the top-level project:

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}
)
like image 149
dow Avatar answered Sep 28 '22 05:09

dow