-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
176 lines (159 loc) · 6.04 KB
/
Copy pathCMakeLists.txt
File metadata and controls
176 lines (159 loc) · 6.04 KB
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
# ____ _ _
# | _ \| |_ _ __ _(_)_ __
# | |_) | | | | |/ _` | | '_ \
# | __/| | |_| | (_| | | | | |
# |_| |_|\__,_|\__, |_|_| |_|
# |___/
# A Template for UsbsourcePlugin, a Source Plugin
# Generated by the command: plugin -t source -d ArduinoIO_plugin USBSource
# Hostname: Fram-IV
# Current working directory: /Users/p4010/Develop/MADS_plugins
# Creation date: 2026-09-02T21:59:15.981+0200
# NOTICE: MADS Version 2.4.3
cmake_minimum_required(VERSION 3.28)
project(usbsource VERSION 2.4.3 LANGUAGES CXX)
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
execute_process(
COMMAND mads -p
OUTPUT_VARIABLE MADS_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(MADS_PREFIX)
set(CMAKE_INSTALL_PREFIX "${MADS_PREFIX}" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
endif()
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
set(PLUGIN_SUFFIX "" CACHE STRING "Suffix for the plugin file, identifying the architecture, e.g. arm64, x86_64, etc.")
if(PLUGIN_SUFFIX STREQUAL "")
message(WARNING "No PLUGIN_SUFFIX set, using default plugin name. In multi-platform environment with OTA plugins it is advised to set PLUGIN_SUFFIX to the architecture, e.g. arm64, x86_64, etc.")
else()
message(STATUS "PLUGIN_SUFFIX set to: ${PLUGIN_SUFFIX}")
endif()
# PROJECT SETTINGS #############################################################
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
add_compile_options(-fPIC)
endif()
# DEPENDENCIES #################################################################
include(FetchContent)
# pugg is for the plugin system
FetchContent_Declare(pugg
GIT_REPOSITORY https://github.com/pbosetti/pugg.git
GIT_TAG 1.2.0
GIT_SHALLOW TRUE
EXCLUDE_FROM_ALL
)
set(BUILD_TESTING OFF CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "")
FetchContent_Declare(json
URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
EXCLUDE_FROM_ALL
)
set(ARDUINODRIVER_BUILD_CLI ON CACHE INTERNAL "")
FetchContent_Declare(ArduinoDriver
GIT_REPOSITORY https://github.com/pbosetti/ArduinoDriver.git
GIT_TAG v0.3.1
GIT_SHALLOW TRUE
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(pugg json ArduinoDriver)
FetchContent_Populate(plugin
GIT_REPOSITORY https://github.com/pbosetti/mads_plugin.git
GIT_TAG v2.4-P8
GIT_SHALLOW TRUE
SUBBUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/plugin-subbuild
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/plugin-src
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/plugin-build
)
include_directories(BEFORE
${plugin_SOURCE_DIR}/src
${json_SOURCE_DIR}/include
)
# MACROS #######################################################################
# Call: add_plugin(name [SRCS src1 src2 ...] [LIBS lib1 lib2 ...])
# the source file ${SRC_DIR}/plugin/<name>.cpp is implicitly added
macro(add_plugin name)
# on MacOS only, plugins can be compiled as executables
set(multiValueArgs LIBS SRCS)
cmake_parse_arguments(plugin "" "" "${multiValueArgs}" ${ARGN})
if (APPLE)
add_executable(${name} ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
set_target_properties(${name} PROPERTIES ENABLE_EXPORTS TRUE)
set(${name}_EXEC ${name}.plugin)
else()
add_library(${name} SHARED ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
add_executable(${name}_main ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
target_include_directories(${name}_main BEFORE PRIVATE ${json_SOURCE_DIR}/include)
target_link_libraries(${name}_main PRIVATE pugg ${plugin_LIBS})
if(WIN32)
set_target_properties(${name}_main PROPERTIES
OUTPUT_NAME ${name}
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/exe"
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/exe")
else()
set_target_properties(${name}_main PROPERTIES OUTPUT_NAME ${name})
endif()
set(${name}_EXEC ${name})
list(APPEND TARGET_LIST ${name}_main)
endif()
target_include_directories(${name} BEFORE PRIVATE ${json_SOURCE_DIR}/include)
target_link_libraries(${name} PRIVATE pugg ${plugin_LIBS})
set_target_properties(${name} PROPERTIES PREFIX "")
if (PLUGIN_SUFFIX)
set_target_properties(${name} PROPERTIES SUFFIX "_${PLUGIN_SUFFIX}.plugin")
target_compile_definitions(${name} PRIVATE PLUGIN_NAME="${name}_${PLUGIN_SUFFIX}")
else()
set_target_properties(${name} PROPERTIES SUFFIX ".plugin")
target_compile_definitions(${name} PRIVATE PLUGIN_NAME="${name}")
endif()
list(APPEND TARGET_LIST ${name})
endmacro()
# BUILD SETTINGS ###############################################################
if (APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
include_directories(/opt/homebrew/include)
link_directories(/opt/homebrew/lib)
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib;/usr/local/lib")
endif()
include_directories(${json_SOURCE_DIR}/include)
# These plugins are always build and use for testing
add_plugin(arduinousb LIBS ArduinoDriver::arduino_driver)
add_plugin(arduinostream LIBS ArduinoDriver::arduino_driver)
# ArduinoDriver's CLI tool (arduino-io) lives in an EXCLUDE_FROM_ALL
# subdirectory, so pull it back into the default build.
if(TARGET arduino-io)
set_target_properties(arduino-io PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif()
# INSTALL ######################################################################
if(APPLE)
install(TARGETS ${TARGET_LIST}
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT MadsApps
)
else()
install(TARGETS ${TARGET_LIST}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
COMPONENT MadsApps
)
endif()
if(TARGET arduino-io)
install(TARGETS arduino-io
RUNTIME DESTINATION bin
COMPONENT MadsApps
)
endif()