-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
93 lines (75 loc) · 3.37 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
cmake_minimum_required(VERSION 3.2)
project(sp2 CXX)
set(${PROJECT_NAME}_VERSION 0.1)
# add our custom module directory to the CMake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
################################################################################
## Options ##
################################################################################
option(SP2_ENABLE_MPI "Enable MPI" ON)
option(SP2_ENABLE_LAMMPS "Enable LAMMPS" ON)
option(SP2_ENABLE_PHONOPY "Enable Phonopy" ON)
option(SP2_ENABLE_TESTS "Enable/build tests" OFF)
option(SP2_ENABLE_PYTHON "Enable Python bindings" ON)
option(SP2_BUILD_LIB "Build library instead of binary" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
# interface target to carry along compile definitions related to project options
add_library(project-options INTERFACE)
# for each option, if it is enabled, it is added to the project-options target
# as an interface compile definition
include(VarsToDefines)
vars_to_defines(project-options INTERFACE
SP2_ENABLE_MPI
SP2_ENABLE_LAMMPS
SP2_ENABLE_PHONOPY
SP2_ENABLE_TESTS
SP2_ENABLE_PYTHON)
# setup special per-file compilation flags
# This should be present on any .cpp file that imports CPython headers.
set(SP2_PYTHON_O_FLAGS -fno-strict-aliasing)
################################################################################
## Misc ##
################################################################################
if(NOT UNIX)
message(FATAL_ERROR "${PROJECT_NAME} is supported on unix only." )
endif()
# prevent people from building in-source (aka in the source tree)
include(PreventInSourceBuilds)
# set default build type to release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: \n\
None Debug Release RelWithDebInfo MinSizeRel Coverage."
FORCE)
endif()
# set some variable to check the compiler in an easier way
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CXX_CLANG 1)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CXX_GNU 1)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CXX_INTEL 1)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CXX_MSVC 1)
else()
message(FATAL_ERROR
"Unknown/unsupported compiler with ID \"${CMAKE_CXX_COMPILER_ID}\".")
endif()
# enable ctest
enable_testing()
################################################################################
## Sources ##
################################################################################
# documentation, target is 'docs', must be made explicitly (e.g. make docs)
add_subdirectory(docs EXCLUDE_FROM_ALL)
# interface target populated in the libs/ subdir in order to pass along new
# dependencies to the main target
add_library(project-deps INTERFACE)
# pass along project-options' compile definitions to the deps target
target_link_libraries(project-deps INTERFACE
project-options)
# add subdirectories for external libraries/code, populates dependencies for
# the project-deps target
add_subdirectory(deps)
# main target directory
add_subdirectory(src)