-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (151 loc) · 5.43 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
IF(${CMAKE_VERSION} GREATER_EQUAL "3.15")
CMAKE_POLICY(SET CMP0091 NEW)
ENDIF()
IF(${CMAKE_VERSION} GREATER_EQUAL "3.19")
CMAKE_POLICY(SET CMP0114 NEW)
ENDIF()
PROJECT(pixelpipes)
CMAKE_MINIMUM_REQUIRED(VERSION 3.11 FATAL_ERROR)
INCLUDE(GNUInstallDirs)
INCLUDE(FetchContent)
INCLUDE(ExternalProject)
SET(PROJECT_VERSION 0.1.0)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
SET(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_EXTENSIONS OFF)
option(BUILD_INPLACE "Build to source directory" OFF)
option(BUILD_PYTHON "Build the Python wrapper" ON)
option(BUILD_DEBUG "Enable debug output" OFF)
option(BUILD_TOOL "Build CLI tool" ON)
SET(CMAKE_EXTERNALS_DIR "${CMAKE_BINARY_DIR}/external/")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
ADD_COMPILE_OPTIONS(/W4 /WX /WL /wd4251 /permissive-)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
ADD_COMPILE_OPTIONS(-Wall -Wextra -pedantic -Werror)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
ADD_COMPILE_OPTIONS(-Wall -Wextra -pedantic -Werror)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
endif()
FIND_PACKAGE(Threads REQUIRED)
LINK_LIBRARIES(Threads::Threads)
if(BUILD_DEBUG)
add_definitions(-DPIXELPIPES_DEBUG)
add_definitions(-DPIXELPIPES_SOURCE_COMPILE_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/src/")
endif()
IF (NOT CMAKE_CXX_BYTE_ORDER)
SET(BIG_ENDIAN 1)
SET(LITTLE_ENDIAN 1)
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
SET(CMAKE_CXX_BYTE_ORDER BIG_ENDIAN)
else()
SET(CMAKE_CXX_BYTE_ORDER LITTLE_ENDIAN)
endif()
ENDIF()
IF (CMAKE_CXX_BYTE_ORDER EQUAL BIG_ENDIAN)
add_definitions(-DPIXELPIPES_BIGENDIAN)
ENDIF()
INCLUDE(cmake/lodepng.cmake)
INCLUDE(cmake/zlib.cmake)
INCLUDE(cmake/opencv.cmake)
INCLUDE(cmake/xtensor.cmake)
add_compile_definitions(XTENSOR_USE_XSIMD)
#add_compile_options(-march=native)
SET(CORE_SOURCE
src/type.cpp
src/token.cpp
src/module.cpp
src/operation.cpp
src/random.cpp
src/arithmetic.cpp
src/buffer.cpp
src/tensor.cpp
src/geometry.cpp
src/image.cpp
src/io.cpp
src/list.cpp
src/pipeline/queue.cpp
src/pipeline/optimization.cpp
src/pipeline/pipeline.cpp
src/serialization/compression.cpp
src/serialization/serialization.cpp
)
INCLUDE_DIRECTORIES(SYSTEM ${OPENCV_INCLUDE_DIRS} ${lodepng_SOURCE_DIR} ${ZLIB_INCLUDE_DIRS}
${XTENSOR_INCLUDE_DIRS} ${lodepng_SOURCE_DIR}/include )
INCLUDE_DIRECTORIES(include/)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/deps/lib)
ADD_LIBRARY(pixelpipes SHARED ${CORE_SOURCE})
ADD_DEPENDENCIES(pixelpipes ${XTENSOR_TARGET})
TARGET_LINK_LIBRARIES(pixelpipes ${CMAKE_DL_LIBS} lodepng ${ZLIB_LIBS})
target_compile_definitions(pixelpipes PRIVATE PIXELPIPES_BUILD_CORE)
ADD_LIBRARY(pixelpipes_opencv SHARED
src/opencv/common.cpp
src/opencv/loading.cpp
src/opencv/view.cpp
src/opencv/filter.cpp
src/opencv/geometry.cpp
src/opencv/processing.cpp
src/opencv/render.cpp
src/opencv/morphology.cpp
)
TARGET_LINK_LIBRARIES(pixelpipes_opencv pixelpipes ${OPENCV_LIBS})
# CMake config file
INCLUDE(CMakePackageConfigHelpers)
SET(BINARY_TARGETS pixelpipes pixelpipes_opencv)
# https://martinopilia.com/posts/2018/09/15/building-python-extension.html
IF(BUILD_PYTHON)
find_package (pybind11)
find_package (Python COMPONENTS Interpreter Development NumPy)
INCLUDE_DIRECTORIES(${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS} ${pybind11_INCLUDE_DIRS})
ADD_LIBRARY(pypixelpipes SHARED
src/python/wrapper.cpp
src/python/array.cpp
)
TARGET_LINK_LIBRARIES(pypixelpipes pixelpipes ${Python_LIBRARIES})
set_target_properties(
pypixelpipes
PROPERTIES
PREFIX ""
OUTPUT_NAME "pypixelpipes"
LINKER_LANGUAGE C
)
LIST(APPEND BINARY_TARGETS pypixelpipes)
ENDIF()
# Where to place outputs
IF (BUILD_INPLACE)
set_target_properties(${BINARY_TARGETS}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/pixelpipes"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/pixelpipes"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/pixelpipes"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/pixelpipes"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/pixelpipes"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/pixelpipes"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/pixelpipes"
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/pixelpipes"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/pixelpipes"
)
ELSE()
set_target_properties(${BINARY_TARGETS}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}"
)
ENDIF()
if(MSVC)
target_link_options(pixelpipes PUBLIC /DEBUG)
endif()
IF (BUILD_TOOL)
ADD_EXECUTABLE(pixelpipes_cli src/tool/main.cpp)
SET_TARGET_PROPERTIES(pixelpipes_cli PROPERTIES OUTPUT_NAME "pixelpipes")
TARGET_LINK_LIBRARIES(pixelpipes_cli pixelpipes)
ENDIF()