forked from neo-ai/treelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
151 lines (127 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
149
150
151
cmake_minimum_required (VERSION 3.1)
project(treelite)
include(cmake/Utils.cmake)
find_package(OpenMP)
# Use RPATH on Mac OS X as flexible mechanism for locating dependencies
# See https://blog.kitware.com/upcoming-in-cmake-2-8-12-osx-rpath-support/
set(CMAKE_MACOSX_RPATH TRUE)
# Set BUILD_SHARED_LIBS as option. By default, build shared libraries;
# User can set this to OFF to build static libraries instead.
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(ENABLE_PROTOBUF "Enable Protobuf" OFF)
option(ENABLE_S3 "Build with S3 support" OFF)
option(TEST_COVERAGE "C++ test coverage" OFF)
# enable custom logging facility in dmlc-core
add_definitions(-DDMLC_LOG_CUSTOMIZE)
# use fPIC globally
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Protobuf
if (ENABLE_PROTOBUF)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for protobuf" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for protobuf" FORCE)
add_subdirectory(3rdparty/protobuf/cmake)
set(PROTOBUF_PROTOC_EXECUTABLE protoc)
set(PROTOBUF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/3rdparty/protobuf/src")
set(PROTOBUF_LIBRARIES libprotobuf)
add_definitions(-DTREELITE_PROTOBUF_SUPPORT)
else()
set(PROTOBUF_LIBRARIES "")
endif()
# check MSVC version
if(MSVC)
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "Need Visual Studio 2015 or newer to compile treelite")
endif()
endif()
set_default_configuration_release()
msvc_use_static_runtime()
# dmlc-core option
include(dmlc-core/cmake/Utils.cmake)
if (ENABLE_S3)
dmlccore_option(USE_S3 "Build with S3 support" ON)
endif()
# OpenMP check
if(OPENMP_FOUND)
add_definitions(-DTREELITE_OPENMP_SUPPORT)
else(OPENMP_FOUND)
dmlccore_option(USE_OPENMP "Build with OpenMP" OFF)
endif(OPENMP_FOUND)
# Compiler flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif(OPENMP_FOUND)
if(MSVC)
# Multithreaded compilation
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
# Performance
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")
endif()
if(TEST_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
endif()
include_directories (
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/dmlc-core/include
${PROJECT_SOURCE_DIR}/runtime/native/include
${PROJECT_SOURCE_DIR}/3rdparty/fmt # fmtlib
)
# use fmtlib as header-only
add_definitions(-DFMT_HEADER_ONLY)
add_subdirectory(3rdparty/fmt EXCLUDE_FROM_ALL)
file(GLOB_RECURSE SOURCES
src/*.cc
src/*.h
include/*.h
)
# Protobuf library
if (ENABLE_PROTOBUF)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(TREE_PROTO_SRCS TREE_PROTO_HDRS src/tree.proto)
PROTOBUF_GENERATE_JAVA(tree_proto_java src/tree.proto)
PROTOBUF_GENERATE_PYTHON(tree_proto_python src/tree.proto)
list(INSERT SOURCES 0 ${TREE_PROTO_SRCS} ${TREE_PROTO_HDRS})
endif()
# dmlc-core
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}") # Save BUILD_SHARED_LIBS
set(BUILD_SHARED_LIBS OFF) # dmlc lib must always be static
add_subdirectory(dmlc-core)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}") # Restore BUILD_SHARED_LIBS
if (TARGET dmlc_unit_tests)
set_target_properties(dmlc_unit_tests PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
set(LINK_LIBRARIES dmlc)
# Protobuf library
list(APPEND LINK_LIBRARIES ${PROTOBUF_LIBRARIES})
add_library(objtreelite OBJECT ${SOURCES})
# Native runtime
add_subdirectory(runtime/native)
# JNI runtime
find_package(JNI)
if(JNI_FOUND)
add_subdirectory(runtime/java)
endif()
# Shared library
add_library(treelite $<TARGET_OBJECTS:objtreelite>)
target_link_libraries(treelite ${LINK_LIBRARIES})
set_output_directory(treelite ${PROJECT_SOURCE_DIR}/lib)
if(MINGW)
# remove the 'lib' prefix to conform to windows convention for shared library names
set_target_properties(treelite PROPERTIES PREFIX "")
endif()
# Group sources
auto_source_group("${SOURCES}")
if(WIN32)
install(TARGETS treelite
RUNTIME DESTINATION lib)
else()
install(TARGETS treelite
LIBRARY DESTINATION lib)
endif()
install(DIRECTORY include/treelite DESTINATION include
FILES_MATCHING PATTERN "*.h")