forked from fixstars/ion-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
195 lines (172 loc) · 6.13 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
project(ion-kit LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.6)
#
# Options
#
if (UNIX)
set(DEFAULT_TARGET_BB "base;dnn;image-io;image-processing;opencv;sgm")
else()
set(DEFAULT_TARGET_BB "base;image-io;image-processing;opencv;sgm")
endif()
set(ION_TARGET_BB ${DEFAULT_TARGET_BB} CACHE STRING "A List of building blocks to build (This overrides ION_BUILD_ALL_BB)")
option(ION_BUILD_DOC "Build documents." OFF)
option(ION_BUILD_TEST "Enable to build tests" ON)
option(ION_BUILD_EXAMPLE "Enable to build examples" ON)
option(ION_BUNDLE_HALIDE "Enable to bundle Halide binary into package" OFF)
#TODO: Enable define HALIDE_FOR_FPGA into compile option if it is ON
option(ION_ENABLE_HALIDE_FPGA_BACKEND "Enable to Halide FPGA backend" OFF)
option(WITH_CUDA "Enable CUDA with buliding examples." ON)
#
# CMake common settings
#
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # This is required to export symbols on windows platform
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
#
# Dependent libraries
#
find_package(Halide REQUIRED COMPONENTS shared)
if (WITH_CUDA)
find_package(CUDA REQUIRED)
endif()
#
# Version
#
execute_process(COMMAND git describe --tags
OUTPUT_VARIABLE GIT_DESCRIBE_RESULT
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
message(STATUS "Version: ${GIT_DESCRIBE_RESULT}")
string(STRIP "${GIT_DESCRIBE_RESULT}" ION_KIT_VERSION_S)
add_definitions("-DION_KIT_VERSION=\"${ION_KIT_VERSION_S}\"")
string(REPLACE "v" "" ION_KIT_VERSION ${ION_KIT_VERSION_S})
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/VERSION CONTENT "${ION_KIT_VERSION_S}")
#
# ion utilities
#
include(IonUtil)
#
# Enable FPGA feature
#
if (ION_ENABLE_HALIDE_FPGA_BACKEND)
add_compile_definitions(HALIDE_FOR_FPGA)
endif()
#
# Build main library
#
file(GLOB ION_CORE_SRC LIST_DIRECTORIES false ${PROJECT_SOURCE_DIR}/src/*)
add_library(ion-core SHARED ${ION_CORE_SRC})
target_include_directories(ion-core PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src)
if (UNIX)
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime dl pthread z)
else()
target_link_libraries(ion-core PUBLIC Halide::Halide Halide::Runtime)
endif()
#
# ion-bb
#
add_subdirectory(src/bb)
#
# Test
#
if (ION_BUILD_TEST)
enable_testing()
add_subdirectory(test)
endif()
#
# Examples
#
if(ION_BUILD_EXAMPLE)
enable_testing()
add_subdirectory(example)
endif()
#
# Documentation
#
if (ION_BUILD_DOC)
find_package(Doxygen)
find_package(Sphinx)
if (Doxygen_FOUND AND Sphinx_FOUND)
file(GLOB_RECURSE FILES ${CMAKE_SOURCE_DIR}/include/*.h)
list(APPEND PUBLIC_HEADERS ${FILES})
set(DOXYGEN_INDEX_FILE ${CMAKE_BINARY_DIR}/xml/index.xml)
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/Doxyfile
DEPENDS ${PUBLIC_HEADERS}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/Doxyfile
COMMENT "Generating docs")
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
set(SPHINX_INDEX_FILE ${CMAKE_BINARY_DIR}/doc/index.html)
add_custom_command(OUTPUT ${SPHINX_INDEX_FILE}
COMMAND ${SPHINX_EXECUTABLE} -b html
-Dbreathe_projects.ion-core=${CMAKE_BINARY_DIR}/xml
${CMAKE_SOURCE_DIR}/doc ${CMAKE_BINARY_DIR}/doc
DEPENDS ${DOXYGEN_INDEX_FILE}
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/doc/index.rst)
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION .)
endif()
endif()
#
# Install
#
if (UNIX)
install(TARGETS ion-core DESTINATION lib)
else()
install(FILES ${CMAKE_BINARY_DIR}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/ion-core.dll DESTINATION bin)
install(FILES ${CMAKE_BINARY_DIR}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/ion-core.lib DESTINATION lib)
# These lines is for backward compatibility.
# TODO: Deprecate old name of dll/lib.
install(FILES ${CMAKE_BINARY_DIR}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/ion-core.dll DESTINATION bin RENAME ion.dll)
install(FILES ${CMAKE_BINARY_DIR}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/ion-core.lib DESTINATION lib RENAME ion.lib)
endif()
install(DIRECTORY include DESTINATION .)
install(FILES
${CMAKE_BINARY_DIR}/VERSION
DESTINATION .)
install(FILES
${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION license)
install(FILES
${CMAKE_SOURCE_DIR}/thirdparty_notice.txt
DESTINATION license)
# Halide
if (ION_BUNDLE_HALIDE)
set(HALIDE_ROOT ${Halide_DIR}/../../..)
file(GLOB HALIDE_HEADERS ${HALIDE_ROOT}/include/Halide*.h ${HALIDE_ROOT}/include/wasm*.h)
install(FILES ${HALIDE_HEADERS} DESTINATION include)
file(GLOB HALIDE_BINS
${HALIDE_ROOT}/bin/featurization_to_sample*
${HALIDE_ROOT}/bin/get_host_target*
${HALIDE_ROOT}/bin/retrain_cost_model*
${HALIDE_ROOT}/bin/weightsdir_to_weightsfile*)
install(FILES ${HALIDE_BINS} DESTINATION bin)
install(DIRECTORY ${HALIDE_ROOT}/lib/cmake/Halide DESTINATION lib/cmake/)
if (EXISTS ${HALIDE_ROOT}/lib/cmake/HalideHelpers)
install(DIRECTORY ${HALIDE_ROOT}/lib/cmake/HalideHelpers DESTINATION lib/cmake/)
endif()
if (UNIX)
file(GLOB HALIDE_LIBRARIES ${HALIDE_ROOT}/lib/libHalide*)
install(FILES ${HALIDE_LIBRARIES} DESTINATION lib)
file(GLOB HALIDE_LIBRARIES ${HALIDE_ROOT}/lib/libautoschedule*)
install(FILES ${HALIDE_LIBRARIES} DESTINATION lib)
else()
install(FILES ${HALIDE_ROOT}/bin/Release/Halide.dll DESTINATION bin)
install(FILES ${HALIDE_ROOT}/lib/Release/Halide.lib DESTINATION lib)
endif()
endif()
#
# Packaging
#
if (UNIX)
set(CPACK_GENERATOR "TGZ" "DEB")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Fixstars Corporation Inc.")
configure_file(${CMAKE_SOURCE_DIR}/ion-kit.pc.in ${CMAKE_BINARY_DIR}/ion-kit.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/ion-kit.pc DESTINATION lib/pkgconfig/)
else ()
set(CPACK_GENERATOR "ZIP")
endif ()
set(CPACK_PACKAGE_VERSION ${ION_KIT_VERSION})
include(CPack)