78 lines
2.4 KiB
CMake
78 lines
2.4 KiB
CMake
cmake_minimum_required(VERSION 3.0)
|
|
|
|
project(cnorxz)
|
|
|
|
execute_process(COMMAND bash "-c" "git rev-parse HEAD" OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
execute_process(COMMAND bash "-c" "git tag -l --sort=refname 'v*' | tail -n1" OUTPUT_VARIABLE GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
execute_process(COMMAND bash "-c" "git rev-list -n 1 ${GIT_TAG}" OUTPUT_VARIABLE GIT_TAG_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
string(SUBSTRING ${GIT_TAG} 1 -1 VERSION)
|
|
if(NOT ("${GIT_HASH}" EQUAL "${GIT_TAG_HASH}"))
|
|
string(SUBSTRING ${GIT_HASH} 0 7 GIT_HASH_SHORT)
|
|
set(VERSION "${VERSION}-${GIT_HASH_SHORT}")
|
|
endif()
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
|
|
message(FATAL_ERROR "require gcc version >= 7.0")
|
|
endif()
|
|
else()
|
|
message(WARNING "compiler ${CMAKE_CXX_COMPILER_ID} officially not supported")
|
|
endif()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++17 -Wpedantic -O2 -march=native -faligned-new -funroll-loops -fopenmp")
|
|
|
|
enable_testing()
|
|
|
|
if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}")
|
|
set(INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
|
|
else()
|
|
#set(INSTALL_PATH ${CMAKE_SOURCE_DIR}/install)
|
|
get_filename_component(INSTALL_PATH ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_PREFIX} ABSOLUTE)
|
|
endif()
|
|
message(STATUS "found absolute install path '${INSTALL_PATH}'")
|
|
|
|
find_package( GTest REQUIRED )
|
|
if(GTest_FOUND)
|
|
include_directories(${GTEST_INCLUDE_DIRS})
|
|
else()
|
|
message(FATAL_ERROR "GTest not found")
|
|
endif()
|
|
|
|
find_package(Threads REQUIRED)
|
|
if(Threads_FOUND)
|
|
#include_directories(${Threads_INCLUDE_DIRS})
|
|
else()
|
|
message(FATAL_ERROR "Threads not found")
|
|
endif()
|
|
|
|
if(DEFINED ENABLE_hdf5)
|
|
set(ENABLE_hdf5 ${ENABLE_hdf5} CACHE BOOL "enable hdf5")
|
|
else()
|
|
set(ENABLE_hdf5 TRUE CACHE BOOL "enable hdf5")
|
|
endif()
|
|
|
|
if(DEFINED ENABLE_cereal)
|
|
set(ENABLE_cereal ${ENABLE_cereal} CACHE BOOL "enable hdf5")
|
|
else()
|
|
set(ENABLE_cereal TRUE CACHE BOOL "enable hdf5")
|
|
endif()
|
|
|
|
find_package(cereal QUIET)
|
|
if(cereal_FOUND)
|
|
message(STATUS "found cereal")
|
|
if(ENABLE_cereal)
|
|
message(STATUS "enable cereal")
|
|
add_definitions(-DHAVE_CEREAL)
|
|
endif()
|
|
else()
|
|
message(STATUS "no cereal")
|
|
if(ENABLE_cereal)
|
|
message(FATAL_ERROR "cereal has been enabled but the cereal library has not been found")
|
|
endif()
|
|
endif()
|
|
|
|
add_definitions(-DVERSION="${VERSION}")
|
|
add_definitions(-DGIT_COMMIT="${GIT_HASH}")
|
|
add_definitions(-DCXX_FLAGS="${CMAKE_CXX_FLAGS}")
|
|
|
|
add_subdirectory(src)
|