forked from VowpalWabbit/vowpal_wabbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
156 lines (123 loc) · 4.92 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
cmake_minimum_required(VERSION 3.5)
# Only allow Release and Debug configurations
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE TYPE INTERNAL FORCE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
project(vowpal_wabbit C CXX)
set(CMAKE_CXX_STANDARD 11)
# VW targets Windows 8.1 SDK
if(WIN32)
set(CMAKE_SYSTEM_VERSION 8.1 CACHE TYPE INTERNAL FORCE)
endif()
# Read version into variable
file(READ version.txt PACKAGE_VERSION)
string(STRIP ${PACKAGE_VERSION} PACKAGE_VERSION)
message(STATUS "VowpalWabbit Version: ${PACKAGE_VERSION}")
include(ProcessorCount)
ProcessorCount(NumProcessors)
message(STATUS "Number of processors: ${NumProcessors}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/nprocs.txt ${NumProcessors})
option(PROFILE "Turn on flags required for profiling" OFF)
option(VALGRIND_PROFILE "Turn on flags required for profiling with valgrind" OFF)
option(GCOV "Turn on flags required for gcov" OFF)
option(WARNINGS "Turn on warning flags. ON by default." ON)
option(STATIC_LINK_VW "Link VW executable statically. Off by default." OFF)
option(VW_INSTALL "Add install targets." ON)
option(BUILD_TESTS "Build and enable tests." ON)
option(BUILD_JAVA "Add Java targets." Off)
option(BUILD_PYTHON "Add Python targets." Off)
option(BUILD_DOCS "Add documentation targets." Off)
option(LTO "Enable Link Time optimization (Requires Release build, only works with clang and linux/mac for now)." Off)
string(TOUPPER "${CMAKE_BUILD_TYPE}" CONFIG)
# Add -ffast-math for speed, remove for testability.
set(linux_release_config -O3 -fno-strict-aliasing -msse2 -mfpmath=sse)
set(linux_debug_config -g -O0)
if((NOT PROFILE) AND (NOT GCOV))
set(linux_release_config ${linux_release_config} -fomit-frame-pointer)
endif()
#Use default visiblity on UNIX otherwise a lot of the C++ symbols end up for exported and interpose'able
set(linux_flags -fvisibility=hidden $<$<CONFIG:DEBUG>:${linux_debug_config}> $<$<CONFIG:RELEASE>:${linux_release_config}>)
if(LTO)
if(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message(FATAL_ERROR "LTO requires Clang")
endif()
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "8.0.0")
message(FATAL_ERROR "LTO requires Clang 8.0 (llvm 3.9) or later")
endif()
If("${CONFIG}" STREQUAL "DEBUG")
message(FATAL_ERROR "LTO only works with Release builds")
endif()
set(linux_flags ${linux_flags} -flto=thin)
endif()
# for profiling -- note that it needs to be gcc
if(PROFILE)
set(linux_flags ${linux_flags} -fno-strict-aliasing -pg)
endif()
# for valgrind profiling: run 'valgrind --tool=callgrind PROGRAM' then 'callgrind_annotate --tree=both --inclusive=yes'
if(VALGRIND_PROFILE)
set(linux_flags ${linux_flags} -g -fomit-frame-pointer -fno-strict-aliasing)
endif()
# gcov configuration
if(GCOV)
set(linux_flags ${linux_flags} -g -O0 -fprofile-arcs -ftest-coverage -fno-strict-aliasing -pg)
endif()
set(windows_release_config /GL /O2 /Gy /Oi /Ob2 /Ot /Oy /GT /MD)
set(windows_debug_config /INCREMENTAL /Od /Zi /analyze-)
set(windows_flags $<$<CONFIG:DEBUG>:${windows_debug_config}> $<$<CONFIG:RELEASE>:${windows_release_config}>)
# TODO move to consuming vcpkg of this dependency
add_library(rapidjson INTERFACE)
target_include_directories(rapidjson INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/include)
# Use folders in VS solution
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(explore_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/explore/")
if(STATIC_LINK_VW)
set(Boost_USE_STATIC_LIBS ON)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBS OFF)
else()
set(Boost_USE_STATIC_LIBS OFF)
endif()
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LINK_THREADS Threads::Threads)
if(STATIC_LINK_VW)
set(LINK_THREADS -Wl,--whole-archive -lpthread -Wl,--no-whole-archive)
endif()
# Align and foreach are also required, for some reason they can't be specified as components though.
find_package(Boost REQUIRED COMPONENTS program_options system thread unit_test_framework)
find_package(ZLIB REQUIRED)
add_subdirectory(cluster)
add_subdirectory(library)
add_subdirectory(vowpalwabbit)
if(BUILD_DOCS)
add_subdirectory(doc)
endif()
if(BUILD_JAVA)
add_subdirectory(java)
endif()
if(BUILD_PYTHON)
add_subdirectory(python)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
# Don't offer these make dependent targets on Windows
if(NOT WIN32)
# make bigtests BIG_TEST_ARGS="<args here>"
add_custom_target(bigtests
DEPENDS vw
COMMAND make \${BIG_TEST_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/big_tests)
endif()
endif()
# TODO convert cs directory to cmake
# TODO convert c_test directory to cmake
# PkgConfig
if(VW_INSTALL)
configure_file(libvw.pc.in libvw.pc)
configure_file(libvw_c_wrapper.pc.in libvw_c_wrapper.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libvw.pc ${CMAKE_CURRENT_BINARY_DIR}/libvw_c_wrapper.pc DESTINATION lib/pkgconfig)
endif()