Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
344 lines (300 sloc) 12.4 KB
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
# disable in source build
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory and run CMake from there.")
ENDIF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
PROJECT (vSMC C CXX)
# Version information
SET (VERSION_MAJOR 0)
SET (VERSION_MINOR 9)
SET (VERSION_PATCH 0)
# Global path configurations
SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
# Finding Packages
SET (Boost_NO_BOOST_CMAKE ON)
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
INCLUDE (FindBoost)
INCLUDE (FindEigen)
INCLUDE (FindRandom123)
INCLUDE (FindDoxygen)
INCLUDE (FindTBB)
INCLUDE (FindOpenCL)
INCLUDE (FindOpenMP)
# Configuration files generation
CONFIGURE_FILE (
${PROJECT_SOURCE_DIR}/config/version.hpp.in
${PROJECT_SOURCE_DIR}/include/vsmc/internal/version.hpp)
# Installation
IF (NOT INSTALL_INCLUDE_DIR)
SET (INSTALL_INCLUDE_DIR include)
ENDIF (NOT INSTALL_INCLUDE_DIR)
INSTALL (FILES include/vsmc.hpp DESTINATION ${INSTALL_INCLUDE_DIR})
INSTALL (DIRECTORY include/vsmc/ DESTINATION ${INSTALL_INCLUDE_DIR}/vsmc
PATTERN ".DS_Store" EXCLUDE
PATTERN "*.swp" EXCLUDE)
# Documentations
IF (DOXYGEN_FOUND)
SET (DOC_SOURCE ${PROJECT_SOURCE_DIR}/doc)
SET (DOC_INCLUDE ${PROJECT_SOURCE_DIR}/include)
FILE (GLOB_RECURSE DOC_SOURCE_FILES
${PROJECT_SOURCE_DIR}/doc/*.markdown)
FILE (GLOB_RECURSE DOC_INCLUDE_FILES
${PROJECT_SOURCE_DIR}/include/*.hpp)
CONFIGURE_FILE (
${PROJECT_SOURCE_DIR}/config/Doxyfile.in
${PROJECT_BINARY_DIR}/Doxyfile)
ADD_CUSTOM_COMMAND (
OUTPUT ${PROJECT_BINARY_DIR}/doc
DEPENDS ${PROJECT_BINARY_DIR}/Doxyfile
${DOC_SOURCE_FILES} ${DOC_INCLUDE_FILES}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ARGS Doxyfile)
ADD_CUSTOM_TARGET(docs DEPENDS ${PROJECT_BINARY_DIR}/doc)
ENDIF (DOXYGEN_FOUND)
# Testing
INCLUDE (CheckCXXSourceRuns)
SET (VSMC_CL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/include)
SET (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}
${PROJECT_SOURCE_DIR}/include)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES (SYSTEM ${Boost_INCLUDE_DIRS})
SET (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}
${Boost_INCLUDE_DIRS})
ENDIF (Boost_FOUND)
IF (Eigen_FOUND)
INCLUDE_DIRECTORIES (SYSTEM ${Eigen_INCLUDE_DIR})
SET (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}
${Eigen_INCLUDE_DIR})
ENDIF (Eigen_FOUND)
IF (Random123_FOUND)
INCLUDE_DIRECTORIES (SYSTEM ${Random123_INCLUDE_DIR})
SET (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}
${Random123_INCLUDE_DIR})
ENDIF (Random123_FOUND)
IF (TBB_FOUND)
INCLUDE_DIRECTORIES (SYSTEM ${TBB_INCLUDE_DIR})
ENDIF (TBB_FOUND)
IF (OPENCL_FOUND)
INCLUDE_DIRECTORIES (SYSTEM ${OPENCL_INCLUDE_DIR})
ENDIF (OPENCL_FOUND)
IF (OPENMP_FOUND)
IF (NOT MSVC)
SET (OpenMP_LINK_LIBRARIES ${OpenMP_CXX_FLAGS})
ENDIF (NOT MSVC)
ENDIF (OPENMP_FOUND)
SET (VSMC_TEST TRUE)
# Test OpenMP
IF (OPENMP_FOUND)
SET (CMAKE_REQUIRED_FLAGS ${OpenMP_CXX_FLAGS})
IF (OpenMP_LINK_LIBRARIES)
SET (CMAKE_REQUIRED_LIBRARIES ${OpenMP_LINK_LIBRARIES})
ENDIF (OpenMP_LINK_LIBRARIES)
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_openmp.cpp TRY_OPENMP_CPP)
CHECK_CXX_SOURCE_RUNS ("${TRY_OPENMP_CPP}" VSMC_OPENMP_FOUND)
IF (NOT VSMC_OPENMP_FOUND)
SET (OPENMP_FOUND FALSE)
ENDIF (NOT VSMC_OPENMP_FOUND)
ENDIF (OPENMP_FOUND)
# Test <chrono>
FIND_PACKAGE (Boost COMPONENTS chrono system REQUIRED)
IF (Boost_FOUND)
SET (CHRONO_LINK_LIBRARIES
${Boost_CHRONO_LIBRARY} ${Boost_SYSTEM_LIBRARY})
SET (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
${Boost_CHRONO_LIBRARY_DEBUG} ${Boost_SYSTEM_LIBRARY_DEBUG})
ENDIF (Boost_FOUND)
IF (UNIX AND NOT APPLE)
FIND_LIBRARY (LINUX_RT rt)
IF (LINUX_RT)
SET (CHRONO_LINK_LIBRARIES ${CHRONO_LINK_LIBRARIES} ${LINUX_RT})
SET (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
${LINUX_RT})
ENDIF (LINUX_RT)
ENDIF (UNIX AND NOT APPLE)
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_chrono.cpp TRY_CHRONO_CPP)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_CHRONO=1")
CHECK_CXX_SOURCE_RUNS ("${TRY_CHRONO_CPP}" VSMC_USE_STD_CHRONO)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_CHRONO=0")
CHECK_CXX_SOURCE_RUNS ("${TRY_CHRONO_CPP}" VSMC_USE_BOOST_CHRONO)
SET (CMAKE_REQUIRED_FLAGS)
SET (CMAKE_REQUIRED_LIBRARIES)
IF (VSMC_CHRONO)
STRING (REGEX MATCH "std" VSMC_STD_CHRONO ${VSMC_CHRONO})
STRING (REGEX MATCH "boost" VSMC_BOOST_CHRONO ${VSMC_CHRONO})
ENDIF (VSMC_CHRONO)
IF (NOT ( # No match between prefered and available
(VSMC_STD_CHRONO AND VSMC_USE_STD_CHRONO) OR
(VSMC_BOOST_CHRONO AND VSMC_USE_BOOST_CHRONO)))
SET (VSMC_STD_CHRONO TRUE)
SET (VSMC_BOOST_CHRONO TRUE)
ENDIF (NOT ( # No match between prefered and available
(VSMC_STD_CHRONO AND VSMC_USE_STD_CHRONO) OR
(VSMC_BOOST_CHRONO AND VSMC_USE_BOOST_CHRONO)))
SET (VSMC_USE_CHRONO FALSE)
IF (VSMC_STD_CHRONO AND VSMC_USE_STD_CHRONO)
SET (VSMC_USE_CHRONO TRUE)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_CHRONO=1")
ELSEIF (VSMC_BOOST_CHRONO AND VSMC_USE_BOOST_CHRONO)
SET (VSMC_USE_CHRONO TRUE)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_CHRONO=0")
ENDIF (VSMC_STD_CHRONO AND VSMC_USE_STD_CHRONO)
# Test <functional>
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_functional.cpp
TRY_FUNCTIONAL_CPP)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_FUNCTIONAL=1")
CHECK_CXX_SOURCE_RUNS ("${TRY_FUNCTIONAL_CPP}" VSMC_USE_STD_FUNCTIONAL)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_FUNCTIONAL=0")
CHECK_CXX_SOURCE_RUNS ("${TRY_FUNCTIONAL_CPP}" VSMC_USE_BOOST_FUNCTIONAL)
SET (CMAKE_REQUIRED_FLAGS)
IF (VSMC_FUNCTIONAL)
STRING (REGEX MATCH "std" VSMC_STD_FUNCTIONAL ${VSMC_FUNCTIONAL})
STRING (REGEX MATCH "boost" VSMC_BOOST_FUNCTIONAL ${VSMC_FUNCTIONAL})
ENDIF (VSMC_FUNCTIONAL)
IF (NOT ( # No match between prefered and available
(VSMC_STD_FUNCTIONAL AND VSMC_USE_STD_FUNCTIONAL) OR
(VSMC_BOOST_FUNCTIONAL AND VSMC_USE_BOOST_FUNCTIONAL)))
SET (VSMC_STD_FUNCTIONAL TRUE)
SET (VSMC_BOOST_FUNCTIONAL TRUE)
ENDIF (NOT ( # No match between prefered and available
(VSMC_STD_FUNCTIONAL AND VSMC_USE_STD_FUNCTIONAL) OR
(VSMC_BOOST_FUNCTIONAL AND VSMC_USE_BOOST_FUNCTIONAL)))
IF (VSMC_STD_FUNCTIONAL AND VSMC_USE_STD_FUNCTIONAL)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_FUNCTIONAL=1")
ELSEIF (VSMC_BOOST_FUNCTIONAL AND VSMC_USE_BOOST_FUNCTIONAL)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_FUNCTIONAL=0")
ELSE (VSMC_STD_FUNCTIONAL AND VSMC_USE_STD_FUNCTIONAL)
SET (VSMC_TEST FALSE)
ENDIF (VSMC_STD_FUNCTIONAL AND VSMC_USE_STD_FUNCTIONAL)
# Test <random>
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_random.cpp TRY_RANDOM_CPP)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_RANDOM=1")
CHECK_CXX_SOURCE_RUNS ("${TRY_RANDOM_CPP}" VSMC_USE_STD_RANDOM)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_RANDOM=0")
CHECK_CXX_SOURCE_RUNS ("${TRY_RANDOM_CPP}" VSMC_USE_BOOST_RANDOM)
SET (CMAKE_REQUIRED_FLAGS)
IF (VSMC_RANDOM)
STRING (REGEX MATCH "std" VSMC_STD_RANDOM ${VSMC_RANDOM})
STRING (REGEX MATCH "boost" VSMC_BOOST_RANDOM ${VSMC_RANDOM})
ENDIF (VSMC_RANDOM)
IF (NOT ( # No match between prefered and available
(VSMC_STD_RANDOM AND VSMC_USE_STD_RANDOM) OR
(VSMC_BOOST_RANDOM AND VSMC_USE_BOOST_RANDOM)))
SET (VSMC_STD_RANDOM TRUE)
SET (VSMC_BOOST_RANDOM TRUE)
ENDIF (NOT ( # No match between prefered and available
(VSMC_STD_RANDOM AND VSMC_USE_STD_RANDOM) OR
(VSMC_BOOST_RANDOM AND VSMC_USE_BOOST_RANDOM)))
IF (VSMC_STD_RANDOM AND VSMC_USE_STD_RANDOM)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_RANDOM=1")
ELSEIF (VSMC_BOOST_RANDOM AND VSMC_USE_BOOST_RANDOM)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_RANDOM=0")
ELSE (VSMC_STD_RANDOM AND VSMC_USE_STD_RANDOM)
SET (VSMC_TEST FALSE)
ENDIF (VSMC_STD_RANDOM AND VSMC_USE_STD_RANDOM)
# Test <type_traits>
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_type_traits.cpp
TRY_TYPE_TRAITS_CPP)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_TYPE_TRAITS=1")
CHECK_CXX_SOURCE_RUNS ("${TRY_TYPE_TRAITS_CPP}"
VSMC_USE_STD_TYPE_TRAITS)
SET (CMAKE_REQUIRED_FLAGS "-DVSMC_HAS_CXX11LIB_TYPE_TRAITS=0")
CHECK_CXX_SOURCE_RUNS ("${TRY_TYPE_TRAITS_CPP}"
VSMC_USE_BOOST_TYPE_TRAITS)
SET (CMAKE_REQUIRED_FLAGS)
IF (VSMC_TYPE_TRAITS)
STRING (REGEX MATCH "std" VSMC_STD_TYPE_TRAITS
${VSMC_TYPE_TRAITS})
STRING (REGEX MATCH "boost" VSMC_BOOST_TYPE_TRAITS
${VSMC_TYPE_TRAITS})
ENDIF (VSMC_TYPE_TRAITS)
IF (NOT ( # No match between prefered and available
(VSMC_STD_TYPE_TRAITS AND VSMC_USE_STD_TYPE_TRAITS) OR
(VSMC_BOOST_TYPE_TRAITS AND VSMC_USE_BOOST_TYPE_TRAITS)))
SET (VSMC_STD_TYPE_TRAITS TRUE)
SET (VSMC_BOOST_TYPE_TRAITS TRUE)
ENDIF (NOT ( # No match between prefered and available
(VSMC_STD_TYPE_TRAITS AND VSMC_USE_STD_TYPE_TRAITS) OR
(VSMC_BOOST_TYPE_TRAITS AND VSMC_USE_BOOST_TYPE_TRAITS)))
IF (VSMC_STD_TYPE_TRAITS AND VSMC_USE_STD_TYPE_TRAITS)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_TYPE_TRAITS=1")
ELSEIF (VSMC_BOOST_TYPE_TRAITS AND VSMC_USE_BOOST_TYPE_TRAITS)
SET (VSMC_TEST_FLAGS
"${VSMC_TEST_FLAGS} -DVSMC_HAS_CXX11LIB_TYPE_TRAITS=0")
ELSE (VSMC_STD_TYPE_TRAITS AND VSMC_USE_STD_TYPE_TRAITS)
SET (VSMC_TEST FALSE)
ENDIF (VSMC_STD_TYPE_TRAITS AND VSMC_USE_STD_TYPE_TRAITS)
# Test lgamma
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_lgamma.cpp TRY_LGAMMA_CPP)
CHECK_CXX_SOURCE_RUNS ("${TRY_LGAMMA_CPP}" VSMC_USE_C99_LGAMMA)
CHECK_CXX_SOURCE_RUNS ("${TRY_LGAMMA_CPP}" VSMC_USE_STD_LGAMMA)
CHECK_CXX_SOURCE_RUNS ("${TRY_LGAMMA_CPP}" VSMC_USE_BOOST_LGAMMA)
SET (VSMC_HAS_LGAMMA TRUE)
IF (VSMC_USE_C99_LGAMMA)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_C99_LGAMMA")
ELSEIF (VSMC_USE_STD_LGAMMA)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_STD_LGAMMA")
ELSEIF (VSMC_USE_BOOST_LGAMMA)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_BOOST_LGAMMA")
ELSE (VSMC_USE_C99_LGAMMA)
SET (VSMC_HAS_LGAMMA FALSE)
ENDIF (VSMC_USE_C99_LGAMMA)
# Test erf
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_erf.cpp TRY_ERF_CPP)
CHECK_CXX_SOURCE_RUNS ("${TRY_ERF_CPP}" VSMC_USE_C99_ERF)
CHECK_CXX_SOURCE_RUNS ("${TRY_ERF_CPP}" VSMC_USE_STD_ERF)
CHECK_CXX_SOURCE_RUNS ("${TRY_ERF_CPP}" VSMC_USE_BOOST_ERF)
SET (VSMC_HAS_ERF TRUE)
IF (VSMC_USE_C99_ERF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_C99_ERF")
ELSEIF (VSMC_USE_STD_ERF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_STD_ERF")
ELSEIF (VSMC_USE_BOOST_ERF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_BOOST_ERF")
ELSE (VSMC_USE_C99_ERF)
SET (VSMC_HAS_ERF FALSE)
ENDIF (VSMC_USE_C99_ERF)
# Test isfinite
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_isfinite.cpp TRY_ISFINITE_CPP)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISFINITE_CPP}" VSMC_USE_C99_ISFINITE)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISFINITE_CPP}" VSMC_USE_STD_ISFINITE)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISFINITE_CPP}" VSMC_USE_BOOST_ISFINITE)
SET (VSMC_HAS_ISFINITE TRUE)
IF (VSMC_USE_C99_ISFINITE)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_C99_ISFINITE")
ELSEIF (VSMC_USE_STD_ISFINITE)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_STD_ISFINITE")
ELSEIF (VSMC_USE_BOOST_ISFINITE)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_BOOST_ISFINITE")
ELSE (VSMC_USE_C99_ISFINITE)
SET (VSMC_HAS_ISFINITE FALSE)
ENDIF (VSMC_USE_C99_ISFINITE)
# Test isinf
FILE (READ ${PROJECT_SOURCE_DIR}/cmake/try_isinf.cpp TRY_ISINF_CPP)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISINF_CPP}" VSMC_USE_C99_ISINF)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISINF_CPP}" VSMC_USE_STD_ISINF)
CHECK_CXX_SOURCE_RUNS ("${TRY_ISINF_CPP}" VSMC_USE_BOOST_ISINF)
SET (VSMC_HAS_ISINF TRUE)
IF (VSMC_USE_C99_ISINF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_C99_ISINF")
ELSEIF (VSMC_USE_STD_ISINF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_STD_ISINF")
ELSEIF (VSMC_USE_BOOST_ISINF)
SET (VSMC_TEST_FLAGS "${VSMC_TEST_FLAGS} -DVSMC_USE_BOOST_ISINF")
ELSE (VSMC_USE_C99_ISINF)
SET (VSMC_HAS_ISINF FALSE)
ENDIF (VSMC_USE_C99_ISINF)
IF (VSMC_TEST)
MESSAGE (STATUS "Build tests")
ENABLE_TESTING ()
ADD_SUBDIRECTORY (test EXCLUDE_FROM_ALL)
ENDIF (VSMC_TEST)
Jump to Line
Something went wrong with that request. Please try again.