-
Notifications
You must be signed in to change notification settings - Fork 48
/
CMakeLists.txt
222 lines (184 loc) · 7.63 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Copyright (C) 2015 Analog Devices, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
cmake_minimum_required(VERSION 2.8.12)
project(ad9361 C)
set(LIBAD9361_VERSION_MAJOR 0)
set(LIBAD9361_VERSION_MINOR 2)
set(VERSION ${LIBAD9361_VERSION_MAJOR}.${LIBAD9361_VERSION_MINOR})
include(GNUInstallDirs)
if (WIN32)
string(TIMESTAMP BUILD_YEAR "%Y")
endif()
option(OSX_FRAMEWORK "Create a OSX_FRAMEWORK" ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND OSX_FRAMEWORK)
option(OSX_PACKAGE "Create a OSX package" ON)
set(OSX_INSTALL_FRAMEWORKSDIR "/Library/Frameworks" CACHE STRING "Installation directory for frameworks")
get_filename_component(OSX_INSTALL_FRAMEWORKSDIR "${OSX_INSTALL_FRAMEWORKSDIR}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
set(CMAKE_MACOSX_RPATH ON)
set(SKIP_INSTALL_ALL ${OSX_PACKAGE})
endif()
include(FindGit OPTIONAL)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIBAD9361_GIT_REPO
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if ("${LIBAD9361_GIT_REPO}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIBAD9361_VERSION_GIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
if (NOT LIBAD9361_VERSION_GIT)
set(LIBAD9361_VERSION_GIT v${VERSION})
endif()
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()
# based on host, set these on macos
if(APPLE)
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
add_definitions(-D_DARWIN_C_SOURCE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE=1")
add_definitions(-D_GNU_SOURCE=1)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|DragonFly|OpenBSD|NetBSD")
set(CMAKE_REQUIRED_DEFINITIONS "-D__BSD_VISIBLE")
add_definitions(-D__BSD_VISIBLE=1)
endif()
add_definitions(-D_POSIX_C_SOURCE=200809L -D__XSI_VISIBLE=500 -DLIBAD9361_EXPORTS=1)
find_library(LIBIIO_LIBRARIES iio)
find_path(LIBIIO_INCLUDEDIR iio.h)
set(LIBAD9361_HEADERS ad9361.h)
file(GLOB_RECURSE FD_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/filterdesigner/*.c)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${LIBIIO_INCLUDEDIR})
add_library(ad9361 ad9361_multichip_sync.c
ad9361_baseband_auto_rate.c
ad9361_design_taps.c
ad9361_calculate_rf_clock_chain.c
ad9361_fmcomms5_phase_sync.c
${FD_SRC_FILES}
${LIBAD9361_HEADERS})
enable_testing()
add_subdirectory(test)
set_target_properties(ad9361 PROPERTIES
VERSION ${VERSION}
SOVERSION ${LIBAD9361_VERSION_MAJOR}
FRAMEWORK ${OSX_FRAMEWORK}
PUBLIC_HEADER ${LIBAD9361_HEADERS}
C_STANDARD 99
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)
target_link_libraries(ad9361 LINK_PRIVATE ${LIBIIO_LIBRARIES})
if (MSVC)
set_target_properties(ad9361 PROPERTIES OUTPUT_NAME libad9361)
endif()
configure_file(libad9361-iio.iss.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libad9361-iio.iss @ONLY)
set(LIBAD9361_PC ${CMAKE_CURRENT_BINARY_DIR}/libad9361.pc)
configure_file(libad9361.pc.cmakein ${LIBAD9361_PC} @ONLY)
if(NOT SKIP_INSTALL_ALL)
install(TARGETS ad9361
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${OSX_INSTALL_FRAMEWORKSDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${LIBAD9361_PC} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/${PROJECT_NAME}${LIBAD9361_VERSION_MAJOR}-doc)")
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}${LIBAD9361_VERSION_MAJOR}-doc")
find_package(Doxygen)
if(DOXYGEN_FOUND)
option(WITH_DOC "Generate documentation with Doxygen" ON)
if (WITH_DOC)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
set(HTML_DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/html)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/doc DESTINATION ${HTML_DEST_DIR})
add_custom_command(TARGET ad9361 POST_BUILD
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
if(NOT SKIP_INSTALL_ALL)
install(DIRECTORY ${HTML_DEST_DIR} DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()
endif()
else()
message(STATUS "Doxygen not found, API documentation won't be generated")
endif()
option(PYTHON_BINDINGS "Install Python bindings" OFF)
option(MATLAB_BINDINGS "Install MATLAB bindings" OFF)
option(LIB_CHECK_PYINSTALL "Check for library during python install" OFF)
add_subdirectory(bindings)
# Create an installer if compiling for OSX
if(OSX_PACKAGE AND OSX_FRAMEWORK)
set(LIBAD9361_PKG ${CMAKE_CURRENT_BINARY_DIR}/libad9361-${VERSION}.pkg)
set(LIBAD9361_TEMP_PKG ${CMAKE_CURRENT_BINARY_DIR}/libad9361-${VERSION}-temp.pkg)
set(LIBAD9361_DISTRIBUTION_XML ${CMAKE_CURRENT_BINARY_DIR}/Distribution.xml)
set(LIBAD9361_FRAMEWORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/ad9361.framework)
configure_file(Distribution.xml.cmakein ${LIBAD9361_DISTRIBUTION_XML} @ONLY)
find_program(PKGBUILD_EXECUTABLE
NAMES pkgbuild
DOC "OSX Package builder (pkgbuild)")
mark_as_advanced(PKGBUILD_EXECUTABLE)
find_program(PRODUCTBUILD_EXECUTABLE
NAMES productbuild
DOC "OSX Package builder (productbuild)")
mark_as_advanced(PRODUCTBUILD_EXECUTABLE)
add_custom_command(OUTPUT ${LIBAD9361_PKG}
COMMAND ${PKGBUILD_EXECUTABLE}
--component ${LIBAD9361_FRAMEWORK_DIR}
--identifier com.adi.ad9361 --version ${VERSION}
--install-location /Library/Frameworks ${LIBAD9361_TEMP_PKG}
COMMAND ${PRODUCTBUILD_EXECUTABLE}
--distribution ${LIBAD9361_DISTRIBUTION_XML} ${LIBAD9361_PKG}
COMMAND ${CMAKE_COMMAND} -E remove ${LIBAD9361_TEMP_PKG}
DEPENDS ad9361 ${LIBAD9361_DISTRIBUTION_XML}
)
if (PKGBUILD_EXECUTABLE AND PRODUCTBUILD_EXECUTABLE)
add_custom_target(libad9361-pkg ALL DEPENDS ${LIBAD9361_PKG})
install(CODE "execute_process(COMMAND /usr/sbin/installer -pkg ${LIBAD9361_PKG} -target /)")
else()
message(WARNING "Missing pkgbuild or productbuild: OSX installer won't be created.")
endif()
endif()
if (NOT OSX_PACKAGE)
# Support creating some basic binpkgs via `make package`.
# Disabled if OSX_PACKAGE is enabled, as tarballs would
# end up empty otherwise.
option(ENABLE_PACKAGING "Create .deb/.rpm or .tar.gz packages via 'make package'" ON)
if(ENABLE_PACKAGING)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include(cmake/DarwinPackaging.cmake)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
include(cmake/LinuxPackaging.cmake)
endif()
endif()
endif()
########################################################################
# uninstall target
########################################################################
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)