Skip to content

Commit

Permalink
Rework dependencies to be dynamic, i.e. can be overridden when using …
Browse files Browse the repository at this point in the history
…from install (BlueBrain#255)

We now create an INTERFACE target to hold dependencies info
This target is created on every configure, from HighFive itself or any
using project, trigerred from HighFiveConfig.cmake

* WINDOWS: Dont auto-link
* Activate c++11 if not specified
* Added depend deploy mode. Prefix USE_x w HIGHFIVE_
* HIGHFIVE_USE_INSTALL_DEPS as an option with default
  • Loading branch information
ferdonline committed Jan 13, 2020
1 parent d7c8ed0 commit 2f07be8
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 119 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ matrix:
- os: linux
dist: trusty
env:
- USE_XTENSOR=False
- HIGHFIVE_USE_XTENSOR=False
- HIGHFIVE_PARALLEL_HDF5=False
addons:
apt:
Expand All @@ -65,7 +65,7 @@ matrix:
dist: xenial
env:
- GCC_VERSION=7
- USE_XTENSOR=True
- HIGHFIVE_USE_XTENSOR=True
- HIGHFIVE_PARALLEL_HDF5=True
addons: *gcc7

Expand All @@ -84,21 +84,21 @@ matrix:
dist: xenial
env:
- CLANG_VERSION=7
- USE_XTENSOR=True
- HIGHFIVE_USE_XTENSOR=True
- HIGHFIVE_PARALLEL_HDF5=True
addons: *clang7

# Mac OSX
- os: osx
osx_image: xcode10.3
env:
- USE_XTENSOR=True
- HIGHFIVE_USE_XTENSOR=True
- HIGHFIVE_PARALLEL_HDF5=False

# Windows
- os: windows
env:
- USE_XTENSOR=True
- HIGHFIVE_USE_XTENSOR=True
- HIGHFIVE_PARALLEL_HDF5=False

env:
Expand Down Expand Up @@ -132,7 +132,7 @@ install:
- conda update -q conda
- conda install -c conda-forge xtl xsimd xtensor
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
conda install -c conda-forge boost hdf5 eigen;
conda install -c conda-forge boost-cpp hdf5 eigen;
fi

before_script:
Expand All @@ -152,8 +152,8 @@ script:
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
-DHIGHFIVE_TEST_SINGLE_INCLUDES:BOOL=ON
-DHIGHFIVE_PARALLEL_HDF5:BOOL=${HIGHFIVE_PARALLEL_HDF5}
-DUSE_EIGEN:BOOL=ON
-DUSE_XTENSOR:BOOL=${USE_XTENSOR}
-DHIGHFIVE_USE_EIGEN:BOOL=ON
-DHIGHFIVE_USE_XTENSOR:BOOL=${HIGHFIVE_USE_XTENSOR}
-G "${CMAKE_GENERATOR}" ../
- cmake --build .
- CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target ${TESTS_TARGET}
Expand Down
22 changes: 22 additions & 0 deletions CMake/HighFiveConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@

# Get HighFive targets
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/HighFiveTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/HighFiveTargets.cmake")
endif()

# If the user sets this flag, all dependencies are preserved.
# Useful in central deployments where dependencies are not prepared later
option(HIGHFIVE_USE_INSTALL_DEPS "Use original Highfive dependencies" @HIGHFIVE_USE_INSTALL_DEPS@)
if(HIGHFIVE_USE_INSTALL_DEPS)
return()
endif()

# Options when used from external projects. Keep defaults
if(NOT DEFINED HIGHFIVE_PARALLEL_HDF5)
option(HIGHFIVE_PARALLEL_HDF5 "Enable Parallel HDF5 support" @HIGHFIVE_PARALLEL_HDF5@)
endif()
if(NOT DEFINED HIGHFIVE_USE_BOOST)
option(HIGHFIVE_USE_BOOST "Enable Boost Support" @HIGHFIVE_USE_BOOST@)
endif()

# Pass on dependencies in target project build
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/HighFiveTargetDeps.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/HighFiveTargetDeps.cmake")
endif()
67 changes: 67 additions & 0 deletions CMake/HighFiveTargetDeps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Link against target system libs
# -------------------------------

# therefore making it possible to have new dependencies each build
if(NOT TARGET highfive_deps)
add_library(highfive_deps INTERFACE)
else()
# Reset if imported
set_target_properties(highfive_deps PROPERTIES
INTERFACE_COMPILE_DEFINITIONS ""
INTERFACE_COMPILE_OPTIONS ""
INTERFACE_INCLUDE_DIRECTORIES ""
INTERFACE_LINK_LIBRARIES ""
INTERFACE_LINK_OPTIONS ""
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ""
)
endif()


# HDF5
if(NOT DEFINED HDF5_C_LIBRARIES)
set(HDF5_NO_FIND_PACKAGE_CONFIG_FILE TRUE) # Consistency
set(HDF5_PREFER_PARALLEL ${HIGHFIVE_PARALLEL_HDF5})
find_package(HDF5 REQUIRED)
endif()

if(HIGHFIVE_PARALLEL_HDF5 AND NOT HDF5_IS_PARALLEL)
message(WARNING "Parallel HDF5 requested but libhdf5 doesnt support it")
endif()

target_include_directories(highfive_deps SYSTEM INTERFACE ${HDF5_INCLUDE_DIRS})
target_link_libraries(highfive_deps INTERFACE ${HDF5_C_LIBRARIES})
target_compile_definitions(highfive_deps INTERFACE ${HDF5_DEFINITIONS})

# Boost
if(HIGHFIVE_USE_BOOST)
set(Boost_NO_BOOST_CMAKE TRUE) # Consistency
find_package(Boost REQUIRED COMPONENTS system serialization)
# Dont use imported targets yet, not avail before cmake 3.5
target_include_directories(highfive_deps SYSTEM INTERFACE ${Boost_INCLUDE_DIR})
target_compile_definitions(highfive_deps INTERFACE BOOST_ALL_NO_LIB H5_USE_BOOST)
endif()

# MPI
if(HIGHFIVE_PARALLEL_HDF5 OR HDF5_IS_PARALLEL)
find_package(MPI REQUIRED)
target_include_directories(highfive_deps SYSTEM INTERFACE ${MPI_CXX_INCLUDE_PATH})
target_link_libraries(highfive_deps INTERFACE ${MPI_CXX_LIBRARIES})
if(CMAKE_VERSION VERSION_LESS 3.13)
target_link_libraries(highfive_deps INTERFACE ${MPI_CXX_LINK_FLAGS})
else()
target_link_options(highfive_deps INTERFACE "SHELL:${MPI_CXX_LINK_FLAGS}")
endif()
endif()

# Propagate to HighFive
target_link_libraries(HighFive INTERFACE highfive_deps)
target_compile_definitions(HighFive INTERFACE MPI_NO_CPPBIND) # No c++ bindings

# Ensure we activate at least C++11
if(NOT DEFINED CMAKE_CXX_STANDARD)
if(CMAKE_VERSION VERSION_LESS "3.1")
message(WARNING "HighFive requires at least c++11. You may need to set CMAKE_CXX_STANDARD.")
else()
target_compile_features(HighFive INTERFACE cxx_std_11)
endif()
endif()
48 changes: 48 additions & 0 deletions CMake/HighFiveTargetExport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
add_library(HighFive INTERFACE)
add_library(highfive_deps INTERFACE)

# Public headers
target_include_directories(HighFive INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")


# Generate ${PROJECT_NAME}Config.cmake

include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/HighFiveConfig.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION share/${PROJECT_NAME}/CMake)

write_basic_package_version_file(
${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES
CMake/HighFiveTargetDeps.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION share/${PROJECT_NAME}/CMake)


# Generate ${PROJECT_NAME}Targets.cmake;
# Provides IMPORTED targets when using this project from build/install trees.

# NOTE: the export file is ${PROJECT_NAME}Targets to support when HighFive
# is built within a 3rd-party project (X). Other projects can find and import
# X-Targets.cmake containing the HighFive target

# Specify targets to include in the HighFive Export
install(TARGETS HighFive highfive_deps
EXPORT HighFiveTargets
INCLUDES DESTINATION include)

# Generate & install the Export for the INSTALL_INTERFACE
install(EXPORT HighFiveTargets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION share/${PROJECT_NAME}/CMake)

# Generate the Export for the BUILD_INTERACE (hardly used)
export(EXPORT HighFiveTargets
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
57 changes: 0 additions & 57 deletions CMake/PackageConfig.cmake

This file was deleted.

12 changes: 8 additions & 4 deletions CMake/config/CompilerFlagsHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})

## GCC, CLANG, rest of the world
else()
string(APPEND CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL
" -Wall -Wextra -Werror -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual"
string(APPEND CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL " -Wall -Wextra")
set(CMAKE_${COMPILER_LANGUAGE}_WARNING_DEBUG)
string(APPEND CMAKE_${COMPILER_LANGUAGE}_WARNING_DEBUG
" -Werror -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual"
" -Wformat=2 -Wconversion -Wsign-conversion"
" -Wno-error=conversion -Wno-error=sign-conversion") # Too common to be considered errors
)
if(NOT CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_ICC)
string(APPEND CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL " -Wcast-align -Wpedantic -Wdouble-promotion")
string(APPEND CMAKE_${COMPILER_LANGUAGE}_WARNING_DEBUG
" -Wpedantic -Wcast-align -Wdouble-promotion"
)
endif()

set(CMAKE_${COMPILER_LANGUAGE}_DEBUGINFO_FLAGS "-g")
Expand Down
9 changes: 4 additions & 5 deletions CMake/config/ReleaseDebugAutoFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ include(CompilerFlagsHelpers)


set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_NORMAL}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_NONE} ${CMAKE_C_STACK_PROTECTION}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_NORMAL}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_WARNING_DEBUG} ${CMAKE_C_OPT_NONE} ${CMAKE_C_STACK_PROTECTION}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_WARNING_DEBUG} ${CMAKE_C_OPT_NORMAL}")
set(CMAKE_C_FLAGS_FAST "${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_FASTEST} ${CMAKE_C_LINK_TIME_OPT} ${CMAKE_C_GEN_NATIVE}")



set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_NORMAL}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_NORMAL}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_WARNING_DEBUG} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_C_WARNING_DEBUG} ${CMAKE_CXX_OPT_NORMAL}")
set(CMAKE_CXX_FLAGS_FAST "${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_FASTEST} ${CMAKE_CXX_LINK_TIME_OPT} ${CMAKE_CXX_GEN_NATIVE}")

Loading

0 comments on commit 2f07be8

Please sign in to comment.