Skip to content
Merged
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
131 changes: 72 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,117 @@ project(openFrameworksArduino)
# ********** Setup CMake **********

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# enables building a static library but later link it into a dynamic library
add_compile_options(-fPIC)
endif()
if(NOT WIN32)
# About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of
# implicit sign conversions in gtest.cc, see https://ci.ros2.org/job/ci_osx/9381/clang/.
# Hence disabling -Wsign-conversion for now until all those have eventually been fixed.
# (from https://github.com/ros2/rcutils/pull/263#issuecomment-663252537)
add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic)
endif()
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# enables building a static library but later link it into a dynamic library
add_compile_options(-fPIC)
endif ()
if (NOT WIN32)
# About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of
# implicit sign conversions in gtest.cc, see https://ci.ros2.org/job/ci_osx/9381/clang/.
# Hence disabling -Wsign-conversion for now until all those have eventually been fixed.
# (from https://github.com/ros2/rcutils/pull/263#issuecomment-663252537)
add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic)
endif ()

# Setup Boost
find_package(Boost REQUIRED COMPONENTS thread)
include_directories(${Boost_INCLUDE_DIRS})

# ********** Setup openFrameworksArduino library **********

set(openFrameworksArduino_sources
set(lib_target ${PROJECT_NAME})

add_library(${lib_target})

target_sources(${lib_target} PRIVATE # These files will only be available during building
src/ofArduino.cpp
src/ofSerial.cpp
src/ofSerialLinux.cpp
src/ofSerialWin.cpp
)
set_source_files_properties(
${openFrameworksArduino_sources}
PROPERTIES language "CXX")
add_library(
${PROJECT_NAME}
${openFrameworksArduino_sources})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/>"
"$<INSTALL_INTERFACE:src/${PROJECT_NAME}>")


target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
)

set(public_headers
# Locate headers
# Using FILE_SET would be much cleaner, but needs CMake 3.23+ and ROS Humble ships with 3.22
set(public_headers # These files will be installed with the library
src/ofArduino.h
src/ofConstants.h
src/ofSerial.h
src/ofSerialLinux.h
src/ofSerialWin.h
src/ofTypes.h
src/StdAfx.h
)
set_property(TARGET ${lib_target} PROPERTY PUBLIC_HEADER ${public_headers})
target_include_directories(${lib_target} PUBLIC # Everything in this folder will be available during building
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/>"
"$<INSTALL_INTERFACE:include/>")

set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${public_headers}")
target_link_libraries(${lib_target} PRIVATE
Boost::thread
)

# ********** Setup ArduinoTest executable **********

set(arduino_test_target ArduinoTest)
set(arduino_test_sources

add_executable(${arduino_test_target})

target_sources(${arduino_test_target} PRIVATE
examples/ArduinoTest.cpp
examples/HexapodTimingTest.cpp
examples/PlaybackMovements.cpp
examples/Test.cpp
)
set_source_files_properties(
${arduino_test_sources}
PROPERTIES language "CXX")
add_executable(
${arduino_test_target}
${arduino_test_sources})
target_include_directories(${arduino_test_target} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/examples>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/examples>"
"$<INSTALL_INTERFACE:examples/${PROJECT_NAME}>")

target_link_libraries(${arduino_test_target}
${PROJECT_NAME}
${lib_target}
)

set_target_properties(${arduino_test_target} PROPERTIES LINKER_LANGUAGE CXX)

# ********** Setup packaging **********

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
COMPONENT ${PROJECT_NAME}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
include(CMakePackageConfigHelpers)

# Parse version number from the file
file(READ "version" version_input)
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${version_input})

# Fill in cmake variables in config template
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
@ONLY
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${version_input}
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)

install(TARGETS ${arduino_test_target}
EXPORT "${arduino_test_target}Targets"
COMPONENT ${arduino_test_target}
install(
TARGETS ${lib_target} ${arduino_test_target} # These targets will be packaged
EXPORT ${PROJECT_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
)

install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)

message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}")
include(cpack.cmake)
include(cpack.cmake)

4 changes: 4 additions & 0 deletions config.in.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy any dependencies here
find_dependency(Boost REQUIRED COMPONENTS thread)

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)
4 changes: 1 addition & 3 deletions cpack.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set(MAINTAINER_NAME "David Cofer <dcofer@neurorobotictech.com>")

# Parse version number from file
file(READ "version" version_input)
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${version_input})


set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.0.3
Loading