Skip to content

Commit

Permalink
Configure a basic CMake library
Browse files Browse the repository at this point in the history
Provides 2 targets: `Portduino::Portduino` and `Porduino::PortduinoMain`

Can be used like so:

```cmake
include(FetchContent)
FetchContent_Declare(Portduino
  GIT_REPOSITORY https://github.com/glebm/framework-portduino.git
  GIT_TAG ...
  EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(Portduino)

...

target_link_libraries(MyProject PRIVATE Portduino::Portduino)

```
  • Loading branch information
glebm committed Oct 6, 2024
1 parent ff34ba0 commit ad7d2f7
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
/build/
/build-*/
**/__pycache__/
122 changes: 105 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
cmake_minimum_required(VERSION 3.17)
project(Portduino)
project(Portduino VERSION 0.0.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 14)

include_directories(cores/arduino/api)
include_directories(cores/portduino)
include_directories(cores/portduino/FS)

add_executable(Portduino
add_library(
Portduino
cores/arduino/api/deprecated/Client.h
cores/arduino/api/deprecated/HardwareSerial.h
cores/arduino/api/deprecated/IPAddress.h
Expand Down Expand Up @@ -48,19 +43,112 @@ add_executable(Portduino
cores/arduino/api/USBAPI.h
cores/arduino/api/WCharacter.h
cores/portduino/Arduino.h
cores/portduino/itoa.cpp
cores/portduino/dtostrf.c
cores/portduino/main.cpp
# cores/portduino/itoa.cpp
# cores/portduino/dtostrf.c
cores/portduino/linux/millis.cpp
cores/portduino/simulated/SimCommon.cpp
cores/portduino/Utility.cpp
cores/portduino/Utility.h
cores/portduino/simulated/SimHardwareSPI.cpp
example/test.cpp
cores/portduino/simulated/SimHardwareI2C.cpp
cores/portduino/simulated/SimHardwareI2C.h
cores/portduino/linux/LinuxCommon.cpp
cores/portduino/linux/LinuxSerial.cpp
cores/portduino/simulated/SimHardwareI2C.cpp
cores/portduino/simulated/SimHardwareI2C.h
cores/portduino/linux/LinuxCommon.cpp
cores/portduino/linux/LinuxSerial.cpp
cores/portduino/linux/LinuxSerial.h
cores/portduino/linux/LinuxHardwareI2C.cpp
cores/portduino/linux/LinuxHardwareI2C.h)
cores/portduino/linux/LinuxHardwareI2C.h)
set_target_properties(Portduino PROPERTIES PUBLIC_HEADER
cores/arduino/api/ArduinoAPI.h
cores/arduino/api/Binary.h
cores/arduino/api/Client.h
cores/arduino/api/Common.h
cores/arduino/api/Compat.h
cores/arduino/api/HardwareI2C.h
cores/arduino/api/HardwareSerial.h
cores/arduino/api/HardwareSPI.h
cores/arduino/api/Interrupts.h
cores/arduino/api/IPAddress.h
cores/arduino/api/itoa.h
cores/arduino/api/PluggableUSB.h
cores/arduino/api/Printable.h
cores/arduino/api/RingBuffer.h
cores/arduino/api/Server.h
cores/arduino/api/Stream.h
cores/arduino/api/String.h
cores/arduino/api/Udp.h
cores/arduino/api/USBAPI.h
cores/arduino/api/WCharacter.h
cores/portduino/Arduino.h
cores/portduino/FS/FS.h
cores/portduino/FS/FSImpl.h
cores/portduino/FS/PortduinoFS.h
cores/portduino/FS/vfs_api.h
cores/portduino/linux/gpio/LinuxGPIOPin.h
cores/portduino/linux/LinuxHardwareI2C.h
cores/portduino/linux/LinuxSerial.h
cores/portduino/linux/PosixFile.h
cores/portduino/logging.h
cores/portduino/PortduinoGPIO.h
cores/portduino/simulated/SimHardwareI2C.h
cores/portduino/SPIChip.h
cores/portduino/Utility.h
cores/portduino/WString.h
)
target_include_directories(Portduino
SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cores/arduino/api>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cores/portduino>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cores/portduino/FS>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_library(Portduino::Portduino ALIAS Portduino)

add_library(PortduinoMain
cores/portduino/main.cpp
)
target_link_libraries(PortduinoMain PRIVATE Portduino)
add_library(Portduino::PortduinoMain ALIAS PortduinoMain)


install(
TARGETS
Portduino PortduinoMain
EXPORT
PortduinoTargets
PUBLIC_HEADER
CONFIGURATIONS Release
)

include(CMakePackageConfigHelpers)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/PortduinoConfig.cmake.in"
"${PROJECT_BINARY_DIR}/PortduinoConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/Portduino/cmake"
)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/PortduinoConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(
EXPORT PortduinoTargets
FILE PortduinoTargets.cmake
NAMESPACE Portduino::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/Portduino/cmake"
)

install(
FILES
"${PROJECT_BINARY_DIR}/PortduinoConfig.cmake"
"${PROJECT_BINARY_DIR}/PortduinoConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/Portduino/cmake"
)

install(
FILES
Portduino.h
Portduino.hpp
DESTINATION include
)
5 changes: 5 additions & 0 deletions cmake/PortduinoConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

check_required_components(Portduino)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

0 comments on commit ad7d2f7

Please sign in to comment.