Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure a basic CMake library #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__/
111 changes: 96 additions & 15 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 @@ -50,17 +45,103 @@ add_executable(Portduino
cores/portduino/Arduino.h
cores/portduino/itoa.cpp
cores/portduino/dtostrf.c
cores/portduino/main.cpp
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"
)
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]")