Commit 3ca8f36f authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

Initial commit (with build system)

parents
.*.sw*
build
docs
cmake_minimum_required(VERSION 3.10)
project(seatrac_driver VERSION 0.1)
find_package(Boost COMPONENTS system thread REQUIRED)
message(STATUS "Boost version : ${Boost_VERSION}")
message(STATUS "Boost location : ${Boost_INCLUDE_DIRS}")
list(APPEND seatrac_driver_headers
include/seatrac_driver/SerialHandler.h
)
add_library(seatrac_driver SHARED
src/SerialHandler.cpp
)
set_target_properties(seatrac_driver PROPERTIES
NARVAL_PUBLIC_HEADER "${seatrac_driver_headers}"
INSTALL_RPATH_USE_LINK_PATH True
)
target_include_directories(seatrac_driver PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(seatrac_driver PUBLIC
Boost::system
Boost::thread
)
target_compile_features(seatrac_driver PUBLIC cxx_std_11)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/narval_installation.cmake)
narval_install_target(seatrac_driver)
add_subdirectory(tests)
# seatrac_driver
This is a driver for the Blueprint Subsea Seatrac USBL receiver.
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_package(Boost COMPONENTS system thread REQUIRED)
@NARVAL_INSTALLATION_ADDITIONAL_CONFIG_BODY@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGET_EXPORT_NAME@.cmake")
# set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
check_required_components("@PROJECT_NAME@")
function(target_add_docs TARGET_NAME)
find_package(Doxygen REQUIRED)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "BUILD_DOCUMENTATION option is enabled but "
"Doxygen was not found. Please install Doxygen or "
"set -DBUILD_DOCUMENTATION to off")
endif()
get_target_property(DOXYGEN_EXECUTABLE Doxygen::doxygen IMPORTED_LOCATION)
# message(STATUS "DOXYGEN_EXECUTABLE : ${DOXYGEN_EXECUTABLE}")
add_custom_target(${TARGET_NAME}_docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building documentation for ${TARGET_NAME}"
VERBATIM)
add_dependencies(${TARGET_NAME}_docs ${TARGET_NAME})
endfunction()
function(narval_install_target TARGET_NAME)
set(multiValueArgs
ADDITIONAL_CONFIG_FILES
ADDITIONAL_CONFIG_COMMANDS)
cmake_parse_arguments(NARVAL_INSTALLATION "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
# message(STATUS "=== ${NARVAL_INSTALLATION_ADDITIONAL_CONFIG_COMMANDS}")
set(NARVAL_INSTALLATION_ADDITIONAL_CONFIG_BODY "")
foreach(command ${NARVAL_INSTALLATION_ADDITIONAL_CONFIG_COMMANDS})
# message(STATUS " === ${command}")
set(NARVAL_INSTALLATION_ADDITIONAL_CONFIG_BODY
"${NARVAL_INSTALLATION_ADDITIONAL_CONFIG_BODY}${command}\n")
endforeach()
# RPATH related configuration (see https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling for details)
set_target_properties(${TARGET_NAME} PROPERTIES
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH FALSE
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set_target_properties(${TARGET_NAME} PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" # redundant with above ??
)
endif()
include(GNUInstallDirs)
# Configuration
set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/generated/${TARGET_NAME}ConfigVersion.cmake")
set(PROJECT_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/generated/${TARGET_NAME}Config.cmake")
set(TARGET_EXPORT_NAME "${TARGET_NAME}Targets")
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${VERSION_CONFIG}" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"cmake/Config.cmake.in"
"${PROJECT_CONFIG}"
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
# get_target_property(HEADERS ${TARGET_NAME} PUBLIC_HEADER)
# message(STATUS "Public headers : ${HEADERS}")
# Installation
install(
TARGETS "${TARGET_NAME}"
EXPORT "${TARGET_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
# INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
# PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${INSTALLATION_HEADER_PREFIX}"
)
list(APPEND CONFIG_FILES_TO_INSTALL
${PROJECT_CONFIG}
${VERSION_CONFIG}
${NARVAL_INSTALLATION_ADDITIONAL_CONFIG_FILES}
)
install(
FILES ${CONFIG_FILES_TO_INSTALL}
DESTINATION "${CONFIG_INSTALL_DIR}"
)
# Installing header files
get_target_property(TARGET_TYPE_VALUE ${TARGET_NAME} TYPE)
if(${TARGET_TYPE_VALUE} STREQUAL "INTERFACE_LIBRARY")
get_target_property(HEADER_FILES ${TARGET_NAME} INTERFACE_PUBLIC_HEADER)
else()
get_target_property(HEADER_FILES ${TARGET_NAME} NARVAL_PUBLIC_HEADERS)
endif()
if(NOT "${HEADER_FILES}" STREQUAL "HEADER_FILES-NOTFOUND")
# message(STATUS "HEADER_FILES : ${HEADER_FILES}")
foreach(header ${HEADER_FILES})
get_filename_component(header_dir ${header} DIRECTORY)
# message(STATUS "HEADER INSTALL : ${CMAKE_INSTALL_INCLUDEDIR}/../${header_dir}")
install(FILES ${header}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/../${header_dir}")
endforeach()
endif()
# Export ting target ?
install(
EXPORT "${TARGET_EXPORT_NAME}"
# NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CONFIG_INSTALL_DIR}"
)
endfunction()
#ifndef _DEF_SEATRAC_DRIVER_SERIAL_HANDLE_H_
#define _DEF_SEATRAC_DRIVER_SERIAL_HANDLE_H_
#endif //_DEF_SEATRAC_DRIVER_SERIAL_HANDLE_H_
#include <seatrac_driver/SerialHandler.h>
list(APPEND test_names
hello_test.cpp
)
list(APPEND test_deps
seatrac_driver
)
foreach(name ${test_names})
# Generating a unique target name to avoid name colision with other narval
# packages.
get_filename_component(executable_name ${name} NAME_WE)
set(test_target_name ${PROJECT_NAME}_test_${executable_name})
add_executable(${test_target_name} src/${name})
target_link_libraries(${test_target_name} ${test_deps})
set_target_properties(${test_target_name} PROPERTIES OUTPUT_NAME ${executable_name})
endforeach(name)
#include <iostream>
using namespace std;
int main()
{
cout << "Hello there" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment