-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
148 lines (136 loc) · 4.28 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
143
144
145
146
147
148
cmake_minimum_required (VERSION 3.12.4)
project (readsparse VERSION 0.1.5)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 11)
set(SRC_FILES ${PROJECT_SOURCE_DIR}/src/reader.cpp
${PROJECT_SOURCE_DIR}/src/writer.cpp)
set(BUILD_SHARED_LIBS True)
add_library(readsparse SHARED ${SRC_FILES})
add_compile_definitions(READSPARSE_COMPILE)
if (WIN32 OR MSVC)
add_compile_definitions(_FILE_OFFSET_BITS=64)
endif()
# Compiler optimizations
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <cstddef>
int main(int argc, char **argv)
{
double *__restrict x = nullptr;
return 0;
}
"
SUPPORTS_RESTRICT
)
if (SUPPORTS_RESTRICT)
add_compile_definitions(SUPPORTS_RESTRICT=1)
endif()
if (MSVC)
if (NOT (${CMAKE_CXX_FLAGS_RELEASE} MATCHES "/O2"))
set(OLD_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "/O2")
check_cxx_source_compiles(
"
int main(int argc, char **argv)
{
return 0;
}
"
SUPPORTS_O2
)
set(CMAKE_REQUIRED_FLAGS ${OLD_FLAGS})
if (SUPPORTS_O2)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
endif()
endif()
else()
if (NOT (${CMAKE_CXX_FLAGS_RELEASE} MATCHES "-O3 "))
set(OLD_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-O3")
check_cxx_source_compiles(
"
int main(int argc, char **argv)
{
return 0;
}
"
SUPPORTS_O3
)
set(CMAKE_REQUIRED_FLAGS ${OLD_FLAGS})
if (SUPPORTS_O3)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
else()
set(CMAKE_REQUIRED_FLAGS "-O2")
check_cxx_source_compiles(
"
int main(int argc, char **argv)
{
return 0;
}
"
SUPPORTS_O2
)
set(CMAKE_REQUIRED_FLAGS ${OLD_FLAGS})
if (SUPPORTS_O2)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
endif()
endif()
endif()
option(USE_MARCH_NATIVE "Build with -march=native" OFF)
if (USE_MARCH_NATIVE AND NOT MSVC)
set(OLD_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-march=native")
check_cxx_source_compiles(
"
int main(int argc, char **argv)
{
return 0;
}
"
SUPPORTS_MARCH_NATIVE
)
set(CMAKE_REQUIRED_FLAGS ${OLD_FLAGS})
if (SUPPORTS_MARCH_NATIVE)
message(STATUS "Adding flag -march=native.")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
else()
set(CMAKE_REQUIRED_FLAGS "-mcpu=native")
check_cxx_source_compiles(
"
int main(int argc, char **argv)
{
return 0;
}
"
SUPPORTS_MCPU_NATIVE
)
set(CMAKE_REQUIRED_FLAGS ${OLD_FLAGS})
if (SUPPORTS_MCPU_NATIVE)
message(STATUS "Adding flag -mcpu=native.")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mcpu=native")
else()
message(WARNING "Flags -march=native and -mcpu=native not supported by the compiler.")
endif()
endif()
endif()
set(HEADER_FILES ${PROJECT_SOURCE_DIR}/src/readsparse.hpp
${PROJECT_SOURCE_DIR}/src/readsparse_detemplated.hpp)
set_target_properties(readsparse PROPERTIES PUBLIC_HEADER HEADER_FILES SOVERSION 0 VERSION ${PROJECT_VERSION})
# Install target
include(GNUInstallDirs)
install(TARGETS readsparse
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_file(readsparse.pc.in readsparse.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/readsparse.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()