-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
107 lines (87 loc) · 3.29 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
# napkinXC CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(napkinXC
VERSION 0.6.3
DESCRIPTION "Extremely simple and fast extreme multi-class and multi-label classifiers"
HOMEPAGE_URL https://github.com/mwydmuch/napkinXC
LANGUAGES C CXX)
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Building options
option(EXE "Build executable" ON)
option(PYTHON "Build Python binding" OFF)
set(PYTHON_VERSION "3" CACHE STRING "Build Python binding with specific Python version")
option(BACKWARD "Build with backward.cpp" OFF)
set(CMAKE_CXX_STANDARD 17)
# Set the release mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Add threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Configure file
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
configure_file(
${SRC_DIR}/version.h.in
${SRC_DIR}/version.h)
# Gather napkinXC source files
file(GLOB SOURCES
${SRC_DIR}/*.cpp
${SRC_DIR}/liblinear/*.cpp
${SRC_DIR}/liblinear/blas/*.c
${SRC_DIR}/models/*.cpp)
set(INCLUDES
${SRC_DIR}
${SRC_DIR}/liblinear
${SRC_DIR}/liblinear/blas
${SRC_DIR}/models)
set(LIBRARIES PRIVATE Threads::Threads)
set(DEPENDENCIES)
if (PYTHON)
# Set default install path to be dist so CMake by default installs to the same dist directory location as setuptools:
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist" CACHE PATH "default install path" FORCE )
endif()
# Get pybind11
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/pybind11/CMakeLists.txt)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(STATUS "Pybind11 submodule update")
file(REMOVE_RECURSE ${PY_SRC_DIR}/pybind11)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/pybind11/CMakeLists.txt)
message(FATAL_ERROR "The pybind11 submodule was not downloaded!")
endif()
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
find_package(Python ${PYTHON_VERSION} EXACT COMPONENTS Interpreter Development REQUIRED)
else()
find_package(Python ${PYTHON_VERSION} EXACT COMPONENTS Interpreter Development.Module REQUIRED)
endif()
add_subdirectory(pybind11)
add_subdirectory(python)
endif ()
if (EXE)
if (BACKWARD)
add_subdirectory(${SRC_DIR}/backward)
add_executable(nxc ${SOURCES} ${BACKWARD_ENABLE})
add_backward(nxc)
else()
add_executable(nxc ${SOURCES})
endif()
target_include_directories(nxc PUBLIC ${INCLUDES})
target_link_libraries(nxc PUBLIC ${LIBRARIES})
set_target_properties(nxc
PROPERTIES
OUTPUT_NAME nxc
PROJECT_LABEL "napkinXC")
if(NOT ${DEPENDENCIES} STREQUAL "")
add_dependencies(nxc ${DEPENDENCIES})
endif ()
endif ()