Merge branch 'cmake-cross'

This commit is contained in:
Pavel Kirienko
2015-10-06 18:04:29 +03:00
5 changed files with 95 additions and 16 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
lib*.so
lib*.so.*
*.a
build
build*/
.dep
__pycache__
*.pyc
+64 -13
View File
@@ -4,29 +4,80 @@
cmake_minimum_required(VERSION 2.8)
if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Debug Release RelWithDebInfo MinSizeRel")
else()
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Debug Release RelWithDebInfo MinSizeRel")
project(uavcan C CXX)
#
# Build options
#
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(DEFAULT_UAVCAN_PLATFORM "linux")
endif()
project(uavcan)
# options are listed in a table format below
set(opts
# name: type: default value: string options list : description
"CMAKE_BUILD_TYPE:STRING:RelWithDebInfo:Debug Release RelWithDebInfo MinSizeRel:Build type."
"CMAKE_CXX_FLAGS:STRING:::C++ flags."
"CMAKE_C_FLAGS:STRING:::C flags."
"UAVCAN_USE_CPP03:BOOL:OFF::Use C++03 standard."
"UAVCAN_PLATFORM:STRING:generic:generic linux stm32:Platform."
)
foreach(_opt ${opts})
# arguments are : delimited
string(REPLACE ":" ";" _opt ${_opt})
list(GET _opt 0 _name)
list(GET _opt 1 _type)
list(GET _opt 2 _default)
list(GET _opt 3 _options)
list(GET _opt 4 _descr)
# options are space delimited
string(REPLACE " " ";" _options "${_options}")
# if a default has not already been defined, use default from table
if(NOT DEFINED DEFAULT_${_name})
set(DEFAULT_${_name} ${_default})
endif()
# option has not been set already or it is empty, set it with the default
if(NOT DEFINED ${_name} OR ${_name} STREQUAL "")
set(${_name} ${DEFAULT_${_name}})
endif()
# create a cache from the variable and force it to set
message(STATUS "${_name}\t: ${${_name}} : ${_descr}")
set("${_name}" "${${_name}}" CACHE "${_type}" "${_descr}" FORCE)
# if an options list is provided for the cache, set it
if("${_type}" STREQUAL "STRING" AND NOT "${_options}" STREQUAL "")
set_property(CACHE ${_name} PROPERTY STRINGS ${_options})
endif()
endforeach()
#
# DSDL definitions
# Set flags
#
include_directories(
./libuavcan/include/
./libuavcan/include/dsdlc_generated
)
#
# Install
#
# DSDL definitions
install(DIRECTORY dsdl DESTINATION share/uavcan)
#
# libuavcan
# Subdirectories
#
# library
add_subdirectory(libuavcan)
#
# libuavcan drivers
#
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
message(STATUS "Adding Linux support library")
# drivers
if (${UAVCAN_PLATFORM} STREQUAL "linux")
message(STATUS "Adding Linux platform driver")
add_subdirectory(libuavcan_drivers/posix)
add_subdirectory(libuavcan_drivers/linux)
endif ()
elseif(${UAVCAN_PLATFORM} STREQUAL "stm32")
message(STATUS "Adding STM32 platform driver")
add_subdirectory(libuavcan_drivers/posix)
add_subdirectory(libuavcan_drivers/stm32/driver)
endif()
# vim: set et ft=cmake fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :
+9
View File
@@ -47,6 +47,15 @@ make -j8
sudo make install
```
For cross-compiling the procedure is similar.
```bash
mkdir build
cd build
cmake .. -D CMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-stm32-cortex-m4.cmake
make -j8
```
The following components will be installed into the system:
* Libuavcan headers and the static library
+4 -2
View File
@@ -43,11 +43,11 @@ include_directories(${DSDLC_OUTPUT})
#
if (COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wundef")
if (USE_CPP03)
if (UAVCAN_USE_CPP03)
message(STATUS "Using C++03")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -Wno-variadic-macros -Wno-long-long")
else ()
message(STATUS "Using C++11 (pass USE_CPP03=1 to override)")
message(STATUS "Using C++11 (pass UAVCAN_USE_CPP03=1 to override)")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()
endif ()
@@ -128,3 +128,5 @@ if (DEBUG_BUILD)
else ()
message(STATUS "Release build type: " ${CMAKE_BUILD_TYPE})
endif ()
# vim: set et ft=cmake fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :
@@ -0,0 +1,17 @@
include_directories(
./include
)
add_library(uavcan_stm32_driver STATIC
./src/uc_stm32_can.cpp
./src/uc_stm32_clock.cpp
./src/uc_stm32_thread.cpp
)
add_dependencies(uavcan_stm32_driver uavcan)
install(DIRECTORY include/uavcan_stm32 DESTINATION include)
install(TARGETS uavcan_stm32_driver DESTINATION lib)
# vim: set et ft=cmake fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :)