-
Notifications
You must be signed in to change notification settings - Fork 102
/
CMakeLists.txt
110 lines (96 loc) · 3.9 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
set (CMAKE_FIND_NO_INSTALL_PREFIX TRUE FORCE)
cmake_minimum_required (VERSION 3.13)
project(treelite LANGUAGES CXX C VERSION 1.3.0)
set(CMAKE_CXX_STANDARD 14)
# check MSVC version
if(MSVC)
if(MSVC_VERSION LESS 1910)
message(FATAL_ERROR "Need Visual Studio 2017 or newer to compile Treelite")
endif()
endif()
option(TEST_COVERAGE "C++ test coverage" OFF)
option(USE_OPENMP "Use OpenMP" ON)
option(BUILD_CPP_TEST "Build C++ tests" OFF)
option(BUILD_STATIC_LIBS "Build static libs, in addition to dynamic libs" OFF)
option(DETECT_CONDA_ENV "Enable detection of conda environment for dependencies" ON)
option(BUILD_JVM_RUNTIME "Build Treelite runtime for JVM" OFF)
option(ENABLE_ALL_WARNINGS "Enable all compiler warnings. Only effective for GCC/Clang" OFF)
if(ENABLE_ALL_WARNINGS)
if((NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
message(SEND_ERROR "ENABLE_ALL_WARNINGS is only available for Clang and GCC.")
endif()
endif()
# When installing dependencies, use Conda environment if available
if(DETECT_CONDA_ENV)
if(DEFINED ENV{CONDA_PREFIX})
set(CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX};${CMAKE_PREFIX_PATH}")
message(STATUS "Detected Conda environment, CMAKE_PREFIX_PATH set to: ${CMAKE_PREFIX_PATH}")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "No CMAKE_INSTALL_PREFIX argument detected, setting to: $ENV{CONDA_PREFIX}")
set(CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX})
endif()
else()
message(STATUS "No Conda environment detected")
endif()
endif()
include(cmake/ExternalLibs.cmake)
include(cmake/Utils.cmake)
include(cmake/Version.cmake)
add_subdirectory(src)
if(BUILD_JVM_RUNTIME)
add_subdirectory(runtime/java)
endif()
if(BUILD_CPP_TEST)
add_subdirectory(tests/cpp)
endif()
add_library(treelite SHARED)
add_library(treelite_runtime SHARED)
target_link_libraries(treelite PRIVATE objtreelite objtreelite_common)
target_link_libraries(treelite_runtime PRIVATE objtreelite_runtime objtreelite_common)
set(TREELITE_TARGETS treelite treelite_runtime)
if(BUILD_STATIC_LIBS)
add_library(treelite_static STATIC)
add_library(treelite_runtime_static STATIC)
target_link_libraries(treelite_static PRIVATE objtreelite objtreelite_common)
target_link_libraries(treelite_runtime_static PRIVATE objtreelite_runtime objtreelite_common)
list(APPEND TREELITE_TARGETS treelite_static treelite_runtime_static)
endif()
foreach(lib ${TREELITE_TARGETS})
set_output_directory(${lib} ${PROJECT_BINARY_DIR})
target_link_libraries(${lib} INTERFACE dmlc)
endforeach()
# Export install targets
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(INSTALL_TARGETS ${TREELITE_TARGETS}
objtreelite objtreelite_common objtreelite_runtime dmlc rapidjson)
if(NOT FMTLIB_FROM_SYSTEM_ROOT)
list(APPEND INSTALL_TARGETS fmt-header-only)
endif()
install(TARGETS ${INSTALL_TARGETS}
EXPORT TreeliteTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION include)
install(DIRECTORY include/treelite ${PROJECT_BINARY_DIR}/include/treelite
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT TreeliteTargets
FILE TreeliteTargets.cmake
NAMESPACE treelite::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/treelite)
configure_package_config_file(
cmake/TreeliteConfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/TreeliteConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/treelite)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/cmake/TreeliteConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES
${PROJECT_BINARY_DIR}/cmake/TreeliteConfig.cmake
${PROJECT_BINARY_DIR}/cmake/TreeliteConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/treelite)
write_version()
set_default_configuration_release()
msvc_use_static_runtime()