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.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With