forked from PlusToolkit/ndicapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
176 lines (150 loc) · 5.74 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
PROJECT(ndicapi)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
SET(ndicapi_VERSION 1.6.0)
# --------------------------------------------------------------------------
# Configure output paths for libraries and executables.
IF(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
ENDIF()
IF(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
ENDIF()
IF(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/share")
ENDIF()
IF(NOT DEFINED BUILD_SHARED_LIBS)
SET(BUILD_SHARED_LIBS ON)
ENDIF()
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ${BUILD_SHARED_LIBS})
# --------------------------------------------------------------------------
# Export variables
SET(_targets ndicapi)
# --------------------------------------------------------------------------
# Configure options
OPTION(ndicapi_BUILD_APPLICATIONS "Build applications." OFF)
# --------------------------------------------------------------------------
# build documentation if enabled
option(BUILD_DOC "Build documentation." OFF)
if (BUILD_DOC)
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_LIST_DIR}/docs/ndicapi.dox)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(
${PROJECT_NAME}_doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
endif (DOXYGEN_FOUND)
endif (BUILD_DOC)
# --------------------------------------------------------------------------
# Configure library
SET(${PROJECT_NAME}_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/source
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}
)
SET(${PROJECT_NAME}_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/source/ndicapi.cxx
${CMAKE_CURRENT_SOURCE_DIR}/source/ndicapi_math.cxx
${CMAKE_CURRENT_SOURCE_DIR}/source/ndicapi_serial.cxx
${CMAKE_CURRENT_SOURCE_DIR}/source/ndicapi_thread.cxx
${CMAKE_CURRENT_SOURCE_DIR}/source/ndicapi_socket.cxx
)
#IF(MSVC OR ${CMAKE_GENERATOR} MATCHES "Xcode")
SET(${PROJECT_NAME}_HDRS
${CMAKE_CURRENT_LIST_DIR}/ndicapiExport.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ndicapi_math.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ndicapi_thread.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ndicapi_serial.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ndicapi.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ndicapi_socket.h
)
#ENDIF()
OPTION(BUILD_PYTHON "Ensure the python module will build." OFF)
IF(BUILD_PYTHON)
IF(NOT BUILD_SHARED_LIBS)
MESSAGE(FATAL_ERROR
"The Python extension only works with shared libraries"
" (DLLs on Windows). Please enable building as a"
" shared library (CMake option BUILD_SHARED_LIBS)."
)
ENDIF()
SET(SETUP_PY_FILEPATH ${CMAKE_CURRENT_SOURCE_DIR}/setup.py)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
${SETUP_PY_FILEPATH}
)
MESSAGE(
"Successfully generated ${SETUP_PY_FILEPATH} for the Python"
" extension module. To install the Python extension module:"
"\n\t0) Install the C++ library: make && make install"
" (might need admin access)"
"\n\t1) Go to ${CMAKE_CURRENT_SOURCE_DIR}"
"\n\t2) Build and install the Python extension:"
" python setup.py install (might require admin access)"
)
ENDIF()
FIND_PACKAGE(Threads)
LIST(APPEND ${PROJECT_NAME}_LIBS
${CMAKE_THREAD_LIBS_INIT}
)
# macro for CXX_STANDARD
SET(NDICAPI_CXX_STANDARD 11)
ADD_LIBRARY(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_LIBS})
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD ${NDICAPI_CXX_STANDARD})
IF(NOT WIN32)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC")
ENDIF()
target_include_directories(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_INCLUDE_DIRS})
IF(WIN32)
target_link_libraries(${PROJECT_NAME} PUBLIC wsock32 ws2_32)
ENDIF()
INSTALL(TARGETS ${PROJECT_NAME} EXPORT ndicapi
RUNTIME DESTINATION bin COMPONENT RuntimeLibraries
LIBRARY DESTINATION lib COMPONENT RuntimeLibraries
ARCHIVE DESTINATION lib COMPONENT Development
)
INSTALL(FILES ${${PROJECT_NAME}_HDRS}
DESTINATION include COMPONENT Development
)
GET_TARGET_PROPERTY(_library_type ndicapi TYPE)
IF(${_library_type} STREQUAL SHARED_LIBRARY AND MSVC)
INSTALL(FILES "$<TARGET_PDB_FILE:ndicapi>" OPTIONAL
DESTINATION "bin" COMPONENT RuntimeLibraries
)
ENDIF()
#-----------------------------------------------------------------------------
# CMake target details
SET(${PROJECT_NAME}_TARGETS_FILE "${CMAKE_BINARY_DIR}/ndicapiTargets.cmake")
SET(${PROJECT_NAME}_LIBRARIES ndicapi)
IF(BUILD_SHARED_LIBS)
SET(CLEAR ${PROJECT_NAME}_STATIC)
ELSE()
SET(${PROJECT_NAME}_STATIC ON)
ENDIF()
IF(ndicapi_BUILD_APPLICATIONS)
ADD_EXECUTABLE(ndiBasicExample Applications/ndiBasicExample.cxx)
TARGET_LINK_LIBRARIES(ndiBasicExample PUBLIC ndicapi)
SET_PROPERTY(TARGET ndiBasicExample PROPERTY CXX_STANDARD ${NDICAPI_CXX_STANDARD})
LIST(APPEND _targets ndiBasicExample)
ENDIF()
export(TARGETS ${_targets}
FILE ${ndicapi_TARGETS_FILE}
)
CONFIGURE_FILE(ndicapiConfig.cmake.in
"${CMAKE_BINARY_DIR}/ndicapiConfig.cmake" @ONLY)
CONFIGURE_FILE(ndicapiConfigVersion.cmake.in
"${CMAKE_BINARY_DIR}/ndicapiConfigVersion.cmake" @ONLY)
CONFIGURE_FILE(ndicapiExport.h.in
"${CMAKE_BINARY_DIR}/ndicapiExport.h" @ONLY)
# Enable building of python module, configure the export file in the source directory as well
CONFIGURE_FILE(ndicapiExport.h.in
"${CMAKE_SOURCE_DIR}/ndicapiExport.h" @ONLY)
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE ndicapi)