forked from spglib/spglib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (106 loc) · 4.58 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
cmake_minimum_required(VERSION 2.8.12)
project(spglib C)
option(WITH_Fortran "enable f08 interface" OFF)
set(CMAKE_MACOSX_RPATH 1)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_definitions(-DSPGDEBUG -DSPGWARNING)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if (USE_SANITIZER STREQUAL "Address")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
elseif (USE_SANITIZER STREQUAL "Thread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
elseif (USE_SANITIZER STREQUAL "Undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
elseif (USE_SANITIZER STREQUAL "Leak")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
elseif (USE_SANITIZER STREQUAL "Memory")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory")
endif()
include(GNUInstallDirs)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(USE_OMP "Build with OpenMP support" ON)
if (USE_OMP)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
endif()
# Version numbers
file(READ ${PROJECT_SOURCE_DIR}/src/version.h version_file)
string(REGEX MATCH "SPGLIB_MAJOR_VERSION ([0-9]+)" spglib_major_version ${version_file})
set(spglib_major_version ${CMAKE_MATCH_1})
string(REGEX MATCH "SPGLIB_MINOR_VERSION ([0-9]+)" spglib_minor_version ${version_file})
set(spglib_minor_version ${CMAKE_MATCH_1})
string(REGEX MATCH "SPGLIB_MICRO_VERSION ([0-9]+)" spglib_micro_version ${version_file})
set(spglib_micro_version ${CMAKE_MATCH_1})
set(serial "${spglib_major_version}.${spglib_minor_version}.${spglib_micro_version}")
set(soserial "1")
# Source code
include_directories("${PROJECT_SOURCE_DIR}/src")
set(SOURCES ${PROJECT_SOURCE_DIR}/src/arithmetic.c
${PROJECT_SOURCE_DIR}/src/cell.c
${PROJECT_SOURCE_DIR}/src/debug.c
${PROJECT_SOURCE_DIR}/src/delaunay.c
${PROJECT_SOURCE_DIR}/src/determination.c
${PROJECT_SOURCE_DIR}/src/hall_symbol.c
${PROJECT_SOURCE_DIR}/src/kgrid.c
${PROJECT_SOURCE_DIR}/src/kpoint.c
${PROJECT_SOURCE_DIR}/src/magnetic_spacegroup.c
${PROJECT_SOURCE_DIR}/src/mathfunc.c
${PROJECT_SOURCE_DIR}/src/msg_database.c
${PROJECT_SOURCE_DIR}/src/niggli.c
${PROJECT_SOURCE_DIR}/src/overlap.c
${PROJECT_SOURCE_DIR}/src/pointgroup.c
${PROJECT_SOURCE_DIR}/src/primitive.c
${PROJECT_SOURCE_DIR}/src/refinement.c
${PROJECT_SOURCE_DIR}/src/site_symmetry.c
${PROJECT_SOURCE_DIR}/src/sitesym_database.c
${PROJECT_SOURCE_DIR}/src/spacegroup.c
${PROJECT_SOURCE_DIR}/src/spg_database.c
${PROJECT_SOURCE_DIR}/src/spglib.c
${PROJECT_SOURCE_DIR}/src/spin.c
${PROJECT_SOURCE_DIR}/src/symmetry.c)
# avoid One Definition Rule problems
# only available since 3.16.0
# VERSION_GREATER_EQUAL only available since 3.7.0, so let's do it manually
if (NOT CMAKE_MAJOR_VERSION LESS "3")
if (CMAKE_MAJOR_VERSION GREATER "3" OR NOT CMAKE_MINOR_VERSION LESS "16")
set_source_files_properties(
${SOURCES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON
)
endif()
endif()
# Shared library
add_library(symspg SHARED ${SOURCES})
if(NOT MSVC)
target_link_libraries(symspg PUBLIC m)
endif()
set_property(TARGET symspg PROPERTY VERSION ${serial})
set_property(TARGET symspg PROPERTY SOVERSION ${soserial})
install(TARGETS symspg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Static link library
add_library(symspg_static STATIC ${SOURCES})
set_property(TARGET symspg_static PROPERTY VERSION ${serial})
set_property(TARGET symspg_static PROPERTY SOVERSION ${soserial})
set_property(TARGET symspg_static PROPERTY OUTPUT_NAME symspg)
install(TARGETS symspg_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/src/spglib.h
${PROJECT_SOURCE_DIR}/fortran/spglib_f08.f90
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if (WITH_Fortran)
enable_language(Fortran)
add_subdirectory(fortran)
endif()
configure_file(spglib.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/spglib.pc)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/spglib.pc
DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig
COMPONENT pkgconfig)