-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
142 lines (113 loc) · 4.51 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
cmake_minimum_required(VERSION 3.12)
project(fastkpm)
set(FASTKPM_VERSION 0.1.0)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
# -- COMPILE OPTIONS -------------------------------------------
# Installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
set(INSTALL_CMAKE_DIR lib/CMake/fastkpm CACHE PATH "Installation directory for CMake files")
# Performance/debug options
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -gdwarf-3")
add_definitions(-D_GLIBCXX_DEBUG=1) # libstdc++
add_definitions(-D_LIBCPP_DEBUG2=1) # libc++
# C++11
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(NOT COMPILER_SUPPORTS_CXX11)
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Aborting.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# Mac fixes
if (APPLE)
cmake_policy(SET CMP0042 NEW) # @rpath
set(LIBS ${LIBS} "-framework Accelerate")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
endif()
# -- DEPENDENCIES -------------------------------------------
# Thread Building Blocks
find_package(TBB)
if (TBB_FOUND)
include_directories(SYSTEM ${TBB_INCLUDE_DIRS})
set(LIBS ${LIBS} ${TBB_LIBRARIES})
add_definitions(-DWITH_TBB)
endif()
# Fast Fourier Transform
find_package(FFTW)
if (FFTW_FOUND)
include_directories(SYSTEM ${FFTW_INCLUDE_DIRS})
set(LIBS ${LIBS} ${FFTW_LIBRARIES})
add_definitions(-DWITH_FFTW)
endif()
# MPI
find_package(MPI)
if (MPI_FOUND)
include_directories(${MPI_INCLUDE_PATH})
set(LIBS ${LIBS} ${MPI_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_LINK_FLAGS}")
add_definitions(-DWITH_MPI)
endif()
# CUDA
find_package(CUDA 9.0)
if (CUDA_FOUND)
message(STATUS "Found CUDA " ${CUDA_VERSION})
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_cusparse_LIBRARY})
add_definitions(-DWITH_CUDA)
if (APPLE)
# With recent versions of Xcode, must explicitly use clang
set(CUDA_HOST_COMPILER /usr/bin/clang)
endif()
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-O2;-Xcompiler=-fPIC;
-gencode=arch=compute_52,code=sm_52;
-gencode=arch=compute_60,code=sm_60;
-gencode=arch=compute_61,code=sm_61;
-gencode=arch=compute_70,code=sm_70;
-gencode=arch=compute_70,code=compute_70)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
endif()
# Armadillo
find_package(Armadillo REQUIRED)
include_directories(SYSTEM ${ARMADILLO_INCLUDE_DIRS})
set(LIBS ${LIBS} ${ARMADILLO_LIBRARIES})
# Boost
find_package(Boost 1.55.0 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
# -- BUILD -------------------------------------------
add_subdirectory(src)
# -- INSTALLATION -------------------------------------------
# Generate fastkpmTargets.cmake suitable for use by downstreams
export(TARGETS fastkpm FILE "${PROJECT_BINARY_DIR}/fastkpmTargets.cmake")
# Register the build-tree with a global CMake-registry
export(PACKAGE fastkpm)
# Create the fastkpmConfig.cmake and fastkpmConfigVersion files
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src")
configure_file(fastkpmConfig.cmake.in "${PROJECT_BINARY_DIR}/fastkpmConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}")
configure_file(fastkpmConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/fastkpmConfig.cmake" @ONLY)
# ... for both
configure_file(fastkpmConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/fastkpmConfigVersion.cmake" @ONLY)
# Install fastkpmConfig.cmake and fastkpmConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/fastkpmConfig.cmake"
"${PROJECT_BINARY_DIR}/fastkpmConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install fastkpmTargets.cmake
install(EXPORT fastkpmTargets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# -- REPORT -------------------------------------------
message("")
message("Configuration results")
message("---------------------")
message("C++ compiler : ${CMAKE_CXX_COMPILER}")
message("C++ compiler flags : ${CMAKE_CXX_FLAGS}")
get_property(INC_DIRS DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message("LIBS: ${LIBS}")
message("INCLUDES: ${INC_DIRS}")
message("WITH_MPI: ${MPI_FOUND}")
message("")