Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force building external project (with buildtools) before main project with CMake

Tags:

cmake

I want to build gsl before I start building my main project. I added following lines to root CMakeLists.txt file.

cmake_minimum_required(VERSION 2.8)
project(moose)
include(CheckIncludeFiles)
include(ExternalProject)
# Use local gsl
ExternalProject_Add(gsl_local
    URL ${CMAKE_CURRENT_SOURCE_DIR}/external/gsl/gsl-1.16.tar.gz
    PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/gsl
    CONFIGURE_COMMAND ./../gsl_local/configure --prefix=${CMAKE_CURRENT_SOURCE_DIR}/gsl
    BUILD_COMMAND make
    INSTALL_COMMAND ""
    )

The trouble is that it does not build gsl first but goes on to build project moose which requires gsl/gsl.h. It fails because gsl/gsl.h is not in proper place. How to force CMake to build external project before it starts building main project.

like image 695
Dilawar Avatar asked Dec 19 '22 16:12

Dilawar


1 Answers

After you define your main library/executable with add_library/add_executable, set gsl_local as a dependency of your project using the add_dependencies command (link).

add_dependencies(moosebin gsl_local)

Note that "moosebin" here is the name of the target you create with add_library or add_executable, which is not necessarily the same as what you define with project().

like image 153
jhauris Avatar answered Dec 28 '22 20:12

jhauris