-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
148 lines (115 loc) · 3.95 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
cmake_minimum_required(VERSION 3.1)
project(pixy2)
# Include additional modules that are used inconditionnaly
include(GNUInstallDirs)
include(GenerateExportHeader)
# If conda build, always set lib dir to 'lib'
if($ENV{CONDA_BUILD})
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
# Set lower / upper case project names
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
# Set targets export name (used by lima and dependencies)
set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWER}-targets")
#set(namespace "${PROJECT_NAME}::")
# Check if project is being used directly or via add_subdirectory
set(CAMERA_MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CAMERA_MASTER_PROJECT ON)
endif()
if (CAMERA_MASTER_PROJECT)
find_package(Lima REQUIRED COMPONENTS devel tools)
endif()
# CMake additional macros
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${LIMA_CMAKE_INCLUDE_DIRS} ${CMAKE_MODULE_PATH})
include(LimaTools)
# Set version
include(project_version)
# Enable python binding code compilation using sip generator
if (CAMERA_MASTER_PROJECT)
option(LIMA_ENABLE_PYTHON "compile python binding code?" OFF)
option(LIMA_ENABLE_PYTANGO_SERVER "install python tango server?" OFF)
if (LIMA_ENABLE_PYTHON)
limatools_find_python_and_sip()
endif()
endif()
find_package(PixLib REQUIRED)
file(GLOB_RECURSE CAMERA_INCS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
# Library definition
add_library(pixy2 SHARED
src/Pixy2Camera.cpp
src/Pixy2CameraInterface.cpp
src/Pixy2CameraUtils.cpp
src/Pixy2Interface.cpp
src/Pixy2DetInfoCtrlObj.cpp
src/Pixy2ShutterCtrlObj.cpp
src/Pixy2SyncCtrlObj.cpp
${CAMERA_INCS}
)
# Generate export macros
generate_export_header(pixy2)
# Set version and output name
set_target_properties(pixy2 PROPERTIES
OUTPUT_NAME "lima${PROJECT_NAME_LOWER}"
VERSION "${PROJECT_VERSION}"
SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
# Add dependencies
target_include_directories(pixy2
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # For export header
PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_link_libraries(pixy2 PUBLIC limacore)
target_include_directories(pixy2 PUBLIC ${PixLib_INCLUDE_DIRS})
target_link_libraries(pixy2 PUBLIC libpixy2.a)
target_link_libraries(pixy2 PUBLIC libusb-1.0.so)
target_link_libraries(pixy2 PUBLIC ${OpenCV_LIBS})
if(WIN32)
target_compile_definitions(pixy2
PRIVATE pixy2_EXPORTS
PUBLIC NOMINMAX)
set_target_properties(pixy2 PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib")
endif()
# Binding code for python
if(LIMA_ENABLE_PYTHON)
limatools_run_sip_for_camera(pixy2)
endif()
# Generate and install package config file and version
if(CAMERA_MASTER_PROJECT)
set (PROJECT_LIBRARIES pixy2)
set(SIP_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/sip/lima)
set(CMAKE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/cmake/lima)
include(package_config)
endif()
## Installation
install(
TARGETS pixy2
EXPORT "${TARGETS_EXPORT_NAME}"
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # import library
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so files are libraries
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # .dll files are binaries
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # this does not actually install anything (but used by downstream projects)
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
COMPONENT devel
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/project_version.h
${PROJECT_BINARY_DIR}/pixy2_export.h
COMPONENT devel
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(LIMA_ENABLE_PYTHON)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/
DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/Lima/Pixy2"
)
if (LIMA_ENABLE_PYTANGO_SERVER)
add_subdirectory(tango)
endif()
endif()