Skip to content
Permalink
Browse files

Integrate krims: Changes to the build system

The build system now uses the cmake modules shipped with krims
Linalgwarp depends on krims but uses no features of the librar
  • Loading branch information...
mfherbst committed Sep 1, 2016
1 parent 8cc5974 commit 2b24dabc16a8954a410e53a8d0ff021e6afdb35d
@@ -9,3 +9,8 @@

# our build directory
build

# building external projects:
external/.last_pull
external/rapidcheck
external/krims
@@ -1,6 +0,0 @@
[submodule "external/rapidcheck"]
path = external/rapidcheck
url = https://github.com/emil-e/rapidcheck.git
[submodule "external/catch"]
path = external/catch
url = https://github.com/philsquared/Catch
@@ -21,12 +21,10 @@

cmake_minimum_required(VERSION 3.0.0)

# Set the module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")

# Load the DebugReleaseBuild module for a simultaneous Debug and Release
# and release build and initialise it.
include(DebugReleaseBuild)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/IncludeKrimsCmakeModule.cmake")
include_krims_cmake_module(DebugReleaseBuild)
drb_init()

##########################################################################
@@ -39,31 +37,28 @@ set(PackageModuleLocation share/cmake)
option(LINALGWRAP_ENABLE_TESTS "Build linalgwrap tests" ON)
option(LINALGWRAP_ENABLE_EXAMPLES "Build linalgwrap examples" ON)

option(LINALGWRAP_WITH_EXTERNAL_RAPIDCHECK "Use external rapidcheck from git repository (ON) or system-provided (OFF)." ON)
option(LINALGWRAP_INSTALL_RAPIDCHECK "If LINALGWRAP_WITH_EXTERNAL_RAPIDCHECK is ON, should rapidcheck be installed as well?" OFF)

option(LINALGWRAP_WITH_EXTERNAL_CATCH "Use external catch library from git repository (ON) or system-provided version (OFF)." ON)
option(LINALGWRAP_INSTALL_CATCH "If LINALGWRAP_WITH_EXTERNAL_CATCH is ON, should catch be installed as well?" OFF)

##########################################################################
# Project setup

# enable the new version feature introduced in cmake 3.0.0
cmake_policy(SET CMP0048 NEW)
project(linalgwrap VERSION 0.1.0)
message("\n#")
message("# Configuring ${PROJECT_NAME}")
message("#")

# Global include directories for this project:
include_directories("${linalgwrap_SOURCE_DIR}/src") # for default sources
include_directories("${linalgwrap_BINARY_DIR}/src") # for generated sources
include_directories("${PROJECT_SOURCE_DIR}/src") # for default sources
include_directories("${PROJECT_BINARY_DIR}/src") # for generated sources

# enable testing of this project
enable_testing()

##########################################################################
# Setup hard and optional dependencies and find components

# Determine and setup compiler flags:
drb_setup_compiler_flags()
# Determine and setup compiler flags, enforcing C++11
drb_setup_compiler_flags(11)

# setup hard dependencies
include(cmake/setup_dependencies.cmake)
@@ -74,13 +69,13 @@ include(cmake/setup_optional.cmake)
##########################################################################
# Pass on to subdirectories:

# The external dependencies via submodules or similar
add_subdirectory(external)

# The src directory does most of the work: Here the library is build and
# installation is configured.
add_subdirectory(src)

# The external dependencies via submodules or similar
add_subdirectory(external)

# Add subdirectories for the test.
if(LINALGWRAP_ENABLE_TESTS)
add_subdirectory(tests)
@@ -93,4 +88,4 @@ endif()

##########################################################################
# Finally install modules and packages:
include(cmake/install_modules_packages.cmake)
include(cmake/install_package.cmake)
@@ -0,0 +1,82 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2016 by the linalgwrap authors
##
## This file is part of linalgwrap.
##
## linalgwrap is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## linalgwrap is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with linalgwrap. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------

# Try to find a cmake module which gets shipped with krims.
#
# In case the module is not found and AUTOCHECKOUT_MISSING_LIBS is set to
# on, krims is automatically checked out and the module is loaded from there.
# Otherwise a fatal error is produced.
#

option(AUTOCHECKOUT_MISSING_REPOS "Automatically checkout missing repositories" OFF)

if (NOT DEFINED EXTERNAL_DIR)
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../external/get_krims.sh")
set(EXTERNAL_DIR "${CMAKE_CURRENT_LIST_DIR}/../external")
else()
message(FATAL_ERROR "Could not determine the location of the external \
projects. Try to specify it manually using the variable EXTERNAL_DIR.")
endif()
endif()

function(include_krims_cmake_module MODULE)
# Sanity check
if(NOT EXISTS "${EXTERNAL_DIR}/get_krims.sh")
message(FATAL_ERROR "get_krims.sh does not exist in EXTERNAL_DIR \
== ${EXTERNAL_DIR}.")
endif()

# First try to load it plainly as a module:
include(${MODULE} OPTIONAL RESULT_VARIABLE RES)

if (NOT "${RES}" STREQUAL "NOTFOUND")
message(STATUS "Found ${MODULE} file at ${RES}.")
return()
endif()

# We could not "just" find it. Try the krims_DIR hint:
include("$ENV{krims_DIR}/share/cmake/modules/${MODULE}.cmake"
OPTIONAL RESULT_VARIABLE RES)

if (NOT "${RES}" STREQUAL "NOTFOUND")
message(STATUS "Found ${MODULE} file at ${RES}")
return()
endif()

# Try autocheckout
if (AUTOCHECKOUT_MISSING_REPOS)
execute_process(
COMMAND "sh" "get_krims.sh"
WORKING_DIRECTORY "${EXTERNAL_DIR}"
RESULT_VARIABLE RES
)
if (NOT RES EQUAL 0)
message(FATAL_ERROR "Getting krims from git failed with error: ${RES}")
endif()

include("${EXTERNAL_DIR}/krims/cmake/modules/${MODULE}.cmake")
return()
endif()

message(FATAL_ERROR "Could not find the ${MODULE} module.
Either provide the installation prefix of the krims library in the environment \
variable krims_DIR or enable autocheckout via -DAUTOCHECKOUT_MISSING_REPOS=ON.")
endfunction(include_krims_cmake_module)
@@ -0,0 +1,102 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2016 by the linalgwrap authors
##
## This file is part of linalgwrap.
##
## linalgwrap is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## linalgwrap is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with linalgwrap. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------

# Finds and sets up catch under the target name stored in
# catch_TARGET
# such that just linking against it as a dependency does everything automatically.
#
# In case the catch library is not found and AUTOCHECKOUT_MISSING_LIBS is set to
# on, catch is automatically checked out and built.
# Otherwise a fatal error is produced.
#

#
# Options and properties required
#
option(AUTOCHECKOUT_MISSING_REPOS "Automatically checkout missing repositories" OFF)
set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)

#
# -------
#

# The name for the catch target.
# Note that just "catch" cannot be used since rapidcheck (which is usually
# checked out as well) uses this.
set(catch_TARGET "catch_hdr")

if (TARGET "${catch_TARGET}")
message(STATUS "Found target catch, assume catch already configured for build.")
return()
endif()

# Try to find catch somewhere
find_path(catch_INCLUDE_DIR catch.hpp
PATHS
$ENV{catch_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/external/rapidcheck/ext/catch/include
${PROJECT_SOURCE_DIR}/../catch/include
${PROJECT_SOURCE_DIR}/../krims/modules/catch/include
DOC "catch include directory"
)

string(TOUPPER "${PROJECT_NAME}" PROJECT_UPPER)
if ("${catch_INCLUDE_DIR}" STREQUAL "catch_INCLUDE_DIR-NOTFOUND")
if (AUTOCHECKOUT_MISSING_REPOS)
include(ExternalProject)
ExternalProject_Add(catchFromGit
PREFIX "${PROJECT_BINARY_DIR}/external/catch"
GIT_REPOSITORY "https://github.com/philsquared/Catch"
#
# No configure or build neccessary
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
# INSTALL_DIR
# TEST_COMMAND
)

# Setup catch target
add_library(${catch_TARGET} INTERFACE)
add_dependencies(${catch_TARGET} catchFromGit)

ExternalProject_Get_Property(catchFromGit source_dir)
target_include_directories(${catch_TARGET} INTERFACE
"${source_dir}/include")
unset(source_dir)

# Print message and return
message(STATUS "Using catch from git repository.")
return()
endif()

message(FATAL_ERROR "Could not find catch include directory.
Either disable testing of ${PROJECT_NAME} by setting ${PROJECT_UPPER}_ENABLE_TESTS to OFF \
or enable autocheckout via -DAUTOCHECKOUT_MISSING_REPOS=ON \
or provide a hint where the catch include file can be found via \
the environment variable catch_INCLUDE_DIR.")
endif()

# Add library
add_library(${catch_TARGET} INTERFACE IMPORTED)
message(STATUS "Found catch at ${catch_INCLUDE_DIR}/catch.hpp")
include_directories(${catch_INCLUDE_DIR})
@@ -0,0 +1,94 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2016 by the linalgwrap authors
##
## This file is part of linalgwrap.
##
## linalgwrap is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## linalgwrap is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with linalgwrap. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------

# Finds and sets up krims under the target names stored in
# krims_DEBUG_TARGET (Debug version)
# krims_RELEASE_TARGET (Release version)
# such that just linking against it as a dependency does everything
# automatically.
#
# In case the krims library is not found and AUTOCHECKOUT_MISSING_LIBS is set to
# on, krims is automatically checked out and built.
# Otherwise a fatal error is produced.
#

#
# Options and properties required
#
option(AUTOCHECKOUT_MISSING_REPOS "Automatically checkout missing repositories" OFF)

#
# -------
#
# Unset building rapidcheck in this scope
set(BUILD_EXTERNAL_KRIMS off)

if (TARGET "${krims_DEBUG_TARGET}" OR TARGET "${krims_RELEASE_TARGET}")
message(STATUS "Found target krims, assume krims already configured for build.")
return()
endif()

# Try to find krims somewhere
find_package(krims ${KRIMS_VERSION} QUIET CONFIG)
string(TOUPPER "${PROJECT_NAME}" PROJECT_UPPER)
if ("${krims_DIR}" STREQUAL "krims_DIR-NOTFOUND")
if (AUTOCHECKOUT_MISSING_REPOS)
execute_process(
COMMAND "sh" "get_krims.sh"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/external"
RESULT_VARIABLE RES
)
if (NOT RES EQUAL 0)
message(FATAL_ERROR "Getting krims from git failed with error: ${RES}")
endif()

# TODO check version of krims!

# Print message and return
set(BUILD_EXTERNAL_KRIMS on)
return()
endif()

message(FATAL_ERROR "Could not find krims library.
Either provide the installation prefix of the krims library in the environment \
variable krims_DIR or enable autocheckout via -DAUTOCHECKOUT_MISSING_REPOS=ON.")
endif()

message(WARNING "This part of findKrims has never been tested.")

# Setup library targets
set(krims_DEBUG_TARGET "Upstream::krims.g"
CACHE INTERNAL "Target name of debug version of krims")
set(krims_RELEASE_TARGET "Upstream::krims"
CACHE INTERNAL "Target name of release version of krims")

# Check that all required targets are available.
foreach(build ${DRB_BUILD_TYPES})
if(NOT TARGET "${krims_${build}_TARGET}")
message(FATAL_ERROR "We could not find a ${build} version of krims at this location. \
Either disable building a ${build} version of ${CMAKE_PROJECT_NAME} or else \
rebuild krims with a ${build} version as well.")
endif()
endforeach()

#TODO check that we don't need extra stuff like in findLinalgwrap in gscf

message(STATUS "Found krims config at ${krims_CONFIG}")

0 comments on commit 2b24dab

Please sign in to comment.
You can’t perform that action at this time.