-
Notifications
You must be signed in to change notification settings - Fork 57
/
CMakeLists.txt
199 lines (158 loc) · 6.1 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
cmake_minimum_required(VERSION 3.9)
project(BEAGLE)
set(BEAGLE_PACKAGE_NAME "libhmsbeagle")
set(BEAGLE_VERSION_MAJOR "4")
set(BEAGLE_VERSION_MINOR "0")
set(BEAGLE_VERSION_PATCH "1")
set(GENERIC_API_VERSION "1")
set(BEAGLE_VERSION "${BEAGLE_VERSION_MAJOR}.${BEAGLE_VERSION_MINOR}.${BEAGLE_VERSION_PATCH}")
set(BEAGLE_PLUGIN_VERSION "${BEAGLE_VERSION_MAJOR}${BEAGLE_VERSION_MINOR}")
message(STATUS "BEAGLE_VERSION = ${BEAGLE_VERSION}")
message(STATUS "BEAGLE_PLUGIN_VERSION = ${BEAGLE_PLUGIN_VERSION}")
set(BEAGLE_OPTIMIZE_FOR_NATIVE_ARCH true)
option(BUILD_OPENCL "Build beagle with OpenCL library" ON)
option(BUILD_CUDA "Build beagle with CUDA library" ON)
option(BUILD_JNI "Build beagle with JNI library" ON)
option(BUILD_SSE "Build beagle with SSE library" ON)
# Old config.h settings
add_definitions(
-DPACKAGE_BUGREPORT="[email protected]"
-DPACKAGE_NAME="${BEAGLE_PACKAGE_NAME}"
-DPACKAGE_STRING="${BEAGLE_PACKAGE_NAME} ${BEAGLE_VERSION}"
-DPACKAGE_TARNAME="${BEAGLE_PACKAGE_NAME}"
-DPACKAGE_VERSION="${BEAGLE_VERSION}"
-DPACKAGE_URL=""
-DPLUGIN_VERSION="${BEAGLE_PLUGIN_VERSION}"
)
set(CMAKE_CXX_STANDARD 11)
#SET(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
## flags for standard library
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ot /MT")
else(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -pthread")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -pthread")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
endif(WIN32)
#if(NOT WIN32)
# add_definitions(-DHAVE_CONFIG_H)
if(APPLE)
add_definitions(-DDLS_MACOS)
endif(APPLE)
#endif(NOT WIN32)
include_directories(
${PROJECT_SOURCE_DIR}
)
if(BUILD_JNI)
find_package(JNI)
if(JNI_FOUND)
message (STATUS "JAVA_HOME=$ENV{JAVA_HOME}")
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
include_directories(
$ENV{JAVA_HOME}/include
${JNI_INCLUDE_DIRS}
)
else(JNI_FOUND)
message (FATAL_ERROR "No JNI includes and libraries found")
endif(JNI_FOUND)
endif(BUILD_JNI)
link_directories(
${PROJECT_SOURCE_DIR}/libhmsbeagle
${PROJECT_SOURCE_DIR}/libhmsbeagle/CPU
${PROJECT_SOURCE_DIR}/libhmsbeagle/GPU
${PROJECT_SOURCE_DIR}/libhmsbeagle/JNI
)
# This statement let cmake look for libraries in the provided directories first.
# if failed, RUNTIME_LIB = NO_DEFAULT_PATH
#FIND_LIBRARY(RUNTIME_LIB rt /usr/lib /usr/local/lib NO_DEFAULT_PATH)
if(APPLE)
# execute_process(
# COMMAND uname -m
# RESULT_VARIABLE result
# OUTPUT_VARIABLE BEAGLE_OSX_NATIVE_ARCHITECTURE
# OUTPUT_STRIP_TRAILING_WHITESPACE#
# )
# Check if running under rosetta on arm64 hardware
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
execute_process(COMMAND sysctl -q hw.optional.arm64
OUTPUT_VARIABLE _sysctl_stdout
ERROR_VARIABLE _sysctl_stderr
RESULT_VARIABLE _sysctl_result
)
if(_sysctl_result EQUAL 0 AND _sysctl_stdout MATCHES "hw.optional.arm64: 1")
set(CMAKE_HOST_SYSTEM_PROCESSOR "arm64")
endif()
endif()
set(BEAGLE_OSX_NATIVE_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR})
if(BEAGLE_OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
message(STATUS "macOS universal (x86_64 / arm64) build")
else()
message(STATUS "macOS x86_64 build")
endif()
# Seems necessary from macOS 10.15
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif(APPLE)
if (BEAGLE_OPTIMIZE_FOR_NATIVE_ARCH)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
else()
CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)
if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
endif()
endif()
endif()
add_subdirectory(libhmsbeagle)
link_libraries(hmsbeagle)
enable_testing()
add_subdirectory(examples)
set(CPACK_PACKAGE_VERSION "${BEAGLE_VERSION}")
set(CPACK_PACKAGE_MAJOR "${BEAGLE_VERSION_MAJOR}")
set(CPACK_PACKAGE_MINOR "${BEAGLE_VERSION_MINOR}")
set(CPACK_PACKAGE_PATCH "${BEAGLE_VERSION_PATCH}")
if(WIN32)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_GENERATOR WIX)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Common Files/libhmsbeagle")
set(CPACK_WIX_UPGRADE_GUID "57FC5933-B420-4F10-97F3-B5DDCFF2AE13")
set(CPACK_WIX_LICENSE_RTF "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/LICENSE.rtf")
set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/banner.jpg")
set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/welcome.jpg")
set(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/patch.xml")
endif(WIN32)
if(APPLE)
set(CPACK_GENERATOR productbuild)
set(CPACK_BUNDLE_NAME "${BEAGLE_PACKAGE_NAME}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/LICENSE.rtf")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/project/beagle-macos/README.txt")
set(CPACK_PRODUCTBUILD_BACKGROUND_UTI "${CMAKE_CURRENT_SOURCE_DIR}/project/beagle-vs-2019-wix/welcome.jpg")
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
include(CPackComponent)
cpack_add_component(main
DISPLAY_NAME "Main library"
DESCRIPTION "BEAGLE main library"
REQUIRED)
cpack_add_component(cpu
DISPLAY_NAME "CPU plugin"
DESCRIPTION "CPU plugin"
REQUIRED)
cpack_add_component(cpu_sse
DISPLAY_NAME "CPU-SSE plugin"
DESCRIPTION "CPU-SSE plugin")
cpack_add_component(cuda
DISPLAY_NAME "CUDA plugin"
DESCRIPTION "CUDA plugin")
cpack_add_component(opencl
DISPLAY_NAME "OpenCL plugin"
DESCRIPTION "OpenCL plugin")
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
endif(APPLE)
include(CPack)