Warning, /JETSCAPE/external_packages/trento/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001
0002 cmake_minimum_required(VERSION 3.4)
0003 project(trento VERSION 1.5.1 LANGUAGES CXX)
0004
0005
0006
0007 # require C++11
0008 set(CMAKE_CXX_STANDARD 11)
0009 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0010 set(CMAKE_CXX_EXTENSIONS OFF)
0011
0012 option(STATIC "build static executable" OFF)
0013 if(CMAKE_CXX_FLAGS MATCHES "(^| )-static($| )")
0014 set(STATIC ON)
0015 endif()
0016 # adapted from cmake source: Modules/Compiler/CrayPrgEnv.cmake
0017 if(STATIC)
0018 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
0019 set(CMAKE_LINK_SEARCH_START_STATIC TRUE)
0020 endif()
0021
0022
0023 #old
0024 #set(CMAKE_CXX_STANDARD 11)
0025 #set(CMAKE_CXX_STANDARD_REQUIRED ON)
0026 #include(CheckCXXCompilerFlag)
0027 #check_cxx_compiler_flag("-std=c++11" CXX11)
0028 #if(NOT CXX11)
0029 #message(FATAL_ERROR "Your compiler does not support C++11")
0030 #endif()
0031
0032
0033 # Find and use Boost.
0034 find_package(Boost 1.60 REQUIRED COMPONENTS filesystem program_options system)
0035 include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
0036 message(STATUS "${Boost_INCLUDE_DIRS}, ${Boost_LIBRARIES}")
0037 # Find and use GSL.
0038 #set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/CMake)
0039 FIND_PACKAGE(GSL REQUIRED)
0040 include_directories(${GSL_INCLUDE_DIR} ${GSLCBLAS_INCLUDE_DIR})
0041 message(STATUS ${GSL_INCLUDE_DIR} ${GSLCBLAS_INCLUDE_DIR})
0042 # Find the HDF5 C++ library. The CMake FindHDF5 module does not work reliably,
0043 # e.g. sometimes it links unnecessary libraries, other times it fails to include
0044 # libz. The following works on all systems I have tested (Ubuntu, Fedora, Arch,
0045 # Cray Linux at NERSC, RHEL on OSG).
0046
0047 # Read HDF5_ROOT either as a CMake option or environment variable.
0048 if(NOT HDF5_ROOT)
0049 set(HDF5_ROOT $ENV{HDF5_ROOT})
0050 endif()
0051
0052 # If HDF5_ROOT was set, search for the header and libraries in that location,
0053 # otherwise try to extract the locations from the h5c++ compiler wrapper.
0054 if(HDF5_ROOT)
0055 set(HDF5_INCLUDE_HINT "${HDF5_ROOT}/include")
0056 set(HDF5_LIBRARY_HINT "${HDF5_ROOT}/lib")
0057 else()
0058 find_program(H5CXX h5c++)
0059 if(H5CXX)
0060 if(STATIC)
0061 set(H5CXX_ARG "-noshlib")
0062 else()
0063 set(H5CXX_ARG "-shlib")
0064 endif()
0065 # parse output to extract include and library dirs (-I and -L flags)
0066 execute_process(COMMAND ${H5CXX} -show ${H5CXX_ARG} OUTPUT_VARIABLE H5CXX_OUTPUT)
0067 foreach(TYPE "INCLUDE" "LIBRARY")
0068 string(SUBSTRING ${TYPE} 0 1 FLAG)
0069 set(FLAG " -${FLAG}")
0070 string(REGEX MATCH "${FLAG}[^ ]+" FLAG_HINT ${H5CXX_OUTPUT})
0071 string(REPLACE "${FLAG}" "" HDF5_${TYPE}_HINT "${FLAG_HINT}")
0072 endforeach()
0073 endif()
0074 endif()
0075
0076 # Find all required HDF5 components.
0077 find_path(HDF5_INCLUDE_DIRS H5Cpp.h HINTS ${HDF5_INCLUDE_HINT})
0078 find_library(HDF5_CXX_LIB hdf5_cpp HINTS ${HDF5_LIBRARY_HINT})
0079 find_library(HDF5_C_LIB hdf5 HINTS ${HDF5_LIBRARY_HINT})
0080 find_library(ZLIB z)
0081
0082 # Group HDF5 components by whether they were found or not.
0083 set(HDF5_VARS_FOUND "")
0084 set(HDF5_VARS_MISSING "")
0085 set(HDF5_FOUND TRUE)
0086 foreach(VAR HDF5_INCLUDE_DIRS HDF5_CXX_LIB HDF5_C_LIB ZLIB)
0087 if(${VAR})
0088 set(HDF5_VARS_FOUND "${HDF5_VARS_FOUND} ${${VAR}}")
0089 else()
0090 set(HDF5_FOUND FALSE)
0091 set(HDF5_VARS_MISSING "${HDF5_VARS_MISSING} ${VAR}")
0092 endif()
0093 endforeach()
0094
0095 # Report HDF5 status and set relevant variables if found.
0096 if(HDF5_FOUND)
0097 set(HDF5_LIBRARIES ${HDF5_CXX_LIB} ${HDF5_C_LIB} ${ZLIB})
0098 include_directories(SYSTEM ${HDF5_INCLUDE_DIRS})
0099 add_definitions(-DTRENTO_HDF5)
0100 message(STATUS "Found HDF5:${HDF5_VARS_FOUND}")
0101 else()
0102 message(STATUS "HDF5 not found (missing:${HDF5_VARS_MISSING}, found:${HDF5_VARS_FOUND})")
0103 endif()
0104
0105
0106 set(PROJECT_VERSION_MAJOR 1)
0107 set(PROJECT_VERSION_MINOR 0)
0108 set(PROJECT_VERSION_PATCH 0)
0109 set(PROJECT_VERSION
0110 "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
0111
0112 # default build type: Release
0113 if(NOT CMAKE_BUILD_TYPE)
0114 set(CMAKE_BUILD_TYPE "Release")
0115 endif()
0116
0117 # default install prefix: ~/.local
0118 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
0119 set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local"
0120 CACHE PATH "Install path prefix, prepended onto install directories."
0121 FORCE)
0122 endif()
0123
0124 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
0125 message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
0126
0127 # By default, optimize for the system's native architecture. Disable via the
0128 # NATIVE option. In addition, detect if another architecture flag is already
0129 # set and do not override it.
0130 option(NATIVE "compile for native architecture" ON)
0131 if(NATIVE)
0132 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
0133 # Intel compiler: search for -m, -x, -ax flags; if not found add -xHost.
0134 if(NOT CMAKE_CXX_FLAGS MATCHES "(^| )-(m|x|ax)[^ ]+")
0135 string(APPEND CMAKE_CXX_FLAGS " -xHost")
0136 endif()
0137 else()
0138 # All other compilers (gcc-like): search for -m flags;
0139 # if not found add -march=native.
0140 if(NOT CMAKE_CXX_FLAGS MATCHES "(^| )-m[^ ]+")
0141 #string(APPEND CMAKE_CXX_FLAGS " -march=native")
0142 endif()
0143 endif()
0144 endif()
0145
0146 string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra")
0147
0148 option(MORE_WARNINGS "enable more compiler warnings" ON)
0149 if(MORE_WARNINGS AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
0150 # adapted from http://stackoverflow.com/a/9862800
0151 string(APPEND CMAKE_CXX_FLAGS " -Wpedantic -Wcast-align -Wcast-qual -Wdisabled-optimization -Wformat=2 -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wsign-conversion -Wsign-promo -Wstrict-overflow=2 -Wundef")
0152 endif()
0153
0154 # disable silly clang warnings
0155 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0156 string(APPEND CMAKE_CXX_FLAGS " -Wno-missing-braces -Wno-c++11-narrowing")
0157 endif()
0158
0159 string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Werror")
0160
0161 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0162 string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Og")
0163 endif()
0164
0165 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
0166 # Check for sanitizer support.
0167 # (see e.g. https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer)
0168 # check_cxx_compiler_flag() doesn't work here because it doesn't set the test
0169 # flag at link time, so use check_cxx_source_compiles() instead.
0170 include(CheckCXXSourceCompiles)
0171 set(CMAKE_REQUIRED_QUIET TRUE)
0172
0173 # First try both AddressSanitizer and UndefinedBehaviorSanitizer.
0174 # Disable the vptr sanitizer because it throws errors with boost::any.
0175 set(CMAKE_REQUIRED_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr")
0176 check_cxx_source_compiles("int main() { return 0; }" AddrUndefSanitizer)
0177
0178 # Lacking that, try AddressSanitizer only.
0179 if(NOT AddrUndefSanitizer)
0180 set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
0181 check_cxx_source_compiles("int main() { return 0; }" AddrSanitizer)
0182 if(NOT AddrSanitizer)
0183 # out of luck...
0184 set(CMAKE_REQUIRED_FLAGS "")
0185 endif()
0186 endif()
0187 endif()
0188
0189 string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${CMAKE_REQUIRED_FLAGS} --coverage")
0190
0191 set(LIBRARY_NAME "lib${PROJECT_NAME}")
0192
0193 add_subdirectory(src)
0194 add_subdirectory(test)
0195 add_subdirectory(doc)