Skip to content

Commit c1415d3

Browse files
committed
Import cmake-tools
0 parents  commit c1415d3

File tree

10 files changed

+371
-0
lines changed

10 files changed

+371
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build*/
2+
*~
3+
*#
4+
5+
.cproject
6+
.project
7+
.dir-locals.el

AddGoogleTest.cmake

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#
2+
#
3+
# Downloads GTest and provides a helper macro to add tests. Add make check, as well, which
4+
# gives output on failed tests without having to set an environment variable.
5+
#
6+
#
7+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
8+
9+
if(CMAKE_VERSION VERSION_LESS 3.11)
10+
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
11+
12+
include(DownloadProject)
13+
download_project(PROJ googletest
14+
GIT_REPOSITORY https://github.com/rtlabs-com/googletest.git
15+
GIT_TAG cc602bd729c3acd610c3de5d65d1f1d598c41522
16+
UPDATE_DISCONNECTED 1
17+
QUIET
18+
)
19+
20+
# CMake warning suppression will not be needed in version 1.9
21+
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
22+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL)
23+
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
24+
else()
25+
include(FetchContent)
26+
FetchContent_Declare(googletest
27+
GIT_REPOSITORY https://github.com/rtlabs-com/googletest.git
28+
GIT_TAG cc602bd729c3acd610c3de5d65d1f1d598c41522)
29+
FetchContent_GetProperties(googletest)
30+
if(NOT googletest_POPULATED)
31+
FetchContent_Populate(googletest)
32+
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
33+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
34+
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
35+
endif()
36+
endif()
37+
38+
39+
if(CMAKE_CONFIGURATION_TYPES)
40+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
41+
--force-new-ctest-process --output-on-failure
42+
--build-config "$<CONFIGURATION>")
43+
else()
44+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
45+
--force-new-ctest-process --output-on-failure)
46+
endif()
47+
set_target_properties(check PROPERTIES FOLDER "Scripts")
48+
49+
#include_directories(${gtest_SOURCE_DIR}/include)
50+
51+
# More modern way to do the last line, less messy but needs newish CMake:
52+
# target_include_directories(gtest INTERFACE ${gtest_SOURCE_DIR}/include)
53+
54+
55+
if(GOOGLE_TEST_INDIVIDUAL)
56+
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
57+
include(GoogleTest)
58+
else()
59+
set(GOOGLE_TEST_INDIVIDUAL OFF)
60+
endif()
61+
endif()
62+
63+
# Target must already exist
64+
macro(add_gtest TESTNAME)
65+
target_link_libraries(${TESTNAME} PUBLIC gtest gmock gtest_main)
66+
67+
if(GOOGLE_TEST_INDIVIDUAL)
68+
if(CMAKE_VERSION VERSION_LESS 3.10)
69+
gtest_add_tests(TARGET ${TESTNAME}
70+
TEST_PREFIX "${TESTNAME}."
71+
TEST_LIST TmpTestList)
72+
set_tests_properties(${TmpTestList} PROPERTIES FOLDER "Tests")
73+
else()
74+
gtest_discover_tests(${TESTNAME}
75+
TEST_PREFIX "${TESTNAME}."
76+
PROPERTIES FOLDER "Tests")
77+
endif()
78+
else()
79+
add_test(${TESTNAME} ${TESTNAME})
80+
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
81+
endif()
82+
83+
endmacro()
84+
85+
mark_as_advanced(
86+
gmock_build_tests
87+
gtest_build_samples
88+
gtest_build_tests
89+
gtest_disable_pthreads
90+
gtest_force_shared_crt
91+
gtest_hide_internal_symbols
92+
BUILD_GMOCK
93+
BUILD_GTEST
94+
)
95+
96+
set_target_properties(gtest gtest_main gmock gmock_main
97+
PROPERTIES FOLDER "Extern")

AddOsal.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2020 rt-labs AB, Sweden.
10+
#
11+
# This software is licensed under the terms of the BSD 3-clause
12+
# license. See the file LICENSE distributed with this software for
13+
# full license information.
14+
#*******************************************************************/
15+
16+
cmake_minimum_required(VERSION 3.14)
17+
18+
find_package(Osal QUIET)
19+
20+
if (NOT Osal_FOUND)
21+
include(FetchContent)
22+
FetchContent_Declare(
23+
Osal
24+
GIT_REPOSITORY https://github.com/rtlabs-com/osal.git
25+
GIT_TAG c88f6bd
26+
)
27+
FetchContent_MakeAvailable(Osal)
28+
endif()

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020, rt-labs AB
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Platform/rt-kernel.cmake

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2017 rt-labs AB, Sweden.
10+
#
11+
# This software is licensed under the terms of the BSD 3-clause
12+
# license. See the file LICENSE distributed with this software for
13+
# full license information.
14+
#*******************************************************************/
15+
16+
include_guard()
17+
cmake_minimum_required (VERSION 3.1.2)
18+
19+
# Avoid warning when re-running cmake
20+
set(DUMMY ${CMAKE_TOOLCHAIN_FILE})
21+
22+
# No support for shared libs
23+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
24+
25+
set(UNIX 1)
26+
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
27+
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
28+
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
29+
30+
# Get environment variables
31+
set(RTK $ENV{RTK} CACHE STRING
32+
"Location of rt-kernel tree")
33+
set(COMPILERS $ENV{COMPILERS} CACHE STRING
34+
"Location of compiler toolchain")
35+
set(BSP $ENV{BSP} CACHE STRING
36+
"The name of the BSP to build for")
37+
38+
# Common flags
39+
add_definitions(
40+
-ffunction-sections
41+
-fomit-frame-pointer
42+
-fno-strict-aliasing
43+
-fshort-wchar
44+
)
45+
46+
# Common includes
47+
include_directories(
48+
${RTK}/bsp/${BSP}/include
49+
${RTK}/include
50+
${RTK}/include/arch/${ARCH}
51+
${RTK}/lwip/src/include
52+
)
53+
54+
link_libraries(
55+
${BSP}
56+
${ARCH}
57+
kern
58+
dev
59+
sio
60+
block
61+
fs
62+
usb
63+
lwip
64+
ptpd
65+
eth
66+
i2c
67+
rtc
68+
can
69+
nand
70+
spi
71+
nor
72+
pwm
73+
adc
74+
trace
75+
counter
76+
shell
77+
lua
78+
)
79+
80+
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostartfiles -L${RTK}/lib/${ARCH}/${VARIANT}/${CPU} -T${RTK}/bsp/${BSP}/${BSP}.ld -Wl,-Map=<TARGET>.map -Wl,--gc-sections -Wl,--start-group <LINK_LIBRARIES> -lstdc++ -lc -lm -Wl,--end-group")
81+
82+
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostartfiles -L${RTK}/lib/${ARCH}/${VARIANT}/${CPU} -T${RTK}/bsp/${BSP}/${BSP}.ld -Wl,-Map=<TARGET>.map -Wl,--gc-sections -Wl,--start-group <LINK_LIBRARIES> -lc -lm -Wl,--end-group")

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CMake tools and utilities
2+
=========================
3+
4+
This repository contains common cmake functionality for rt-labs
5+
open-source projects.

toolchain/rt-kernel-imx6.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2017 rt-labs AB, Sweden.
10+
#
11+
# This software is licensed under the terms of the BSD 3-clause
12+
# license. See the file LICENSE distributed with this software for
13+
# full license information.
14+
#*******************************************************************/
15+
16+
include_guard()
17+
18+
# the name of the target operating system
19+
set(CMAKE_SYSTEM_NAME rt-kernel)
20+
21+
# which compiler to use
22+
set(CMAKE_C_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
23+
set(CMAKE_CXX_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
24+
if(CMAKE_HOST_WIN32)
25+
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER}.exe)
26+
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}.exe)
27+
endif(CMAKE_HOST_WIN32)
28+
29+
set(ARCH imx6)
30+
set(CPU cortex-a9-vfp)
31+
32+
list(APPEND MACHINE
33+
-mcpu=cortex-a9
34+
-mfpu=vfpv3-d16
35+
-mfloat-abi=hard
36+
)
37+
38+
add_definitions(${MACHINE})
39+
add_link_options(${MACHINE})

toolchain/rt-kernel-stm32f4.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2017 rt-labs AB, Sweden.
10+
#
11+
# This software is licensed under the terms of the BSD 3-clause
12+
# license. See the file LICENSE distributed with this software for
13+
# full license information.
14+
#*******************************************************************/
15+
16+
include_guard()
17+
18+
# the name of the target operating system
19+
set(CMAKE_SYSTEM_NAME rt-kernel)
20+
21+
# which compiler to use
22+
set(CMAKE_C_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
23+
set(CMAKE_CXX_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
24+
if(CMAKE_HOST_WIN32)
25+
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER}.exe)
26+
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}.exe)
27+
endif(CMAKE_HOST_WIN32)
28+
29+
set(ARCH stm32)
30+
set(VARIANT stm32f4)
31+
set(CPU cortex-m4f)
32+
33+
list(APPEND MACHINE
34+
-mcpu=cortex-m4
35+
-mthumb
36+
-mfloat-abi=hard
37+
-mfpu=fpv4-sp-d16
38+
-Dstm32f4
39+
)
40+
41+
add_definitions(${MACHINE})
42+
add_link_options(${MACHINE})

toolchain/rt-kernel-xmc4.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#********************************************************************
2+
# _ _ _
3+
# _ __ | |_ _ | | __ _ | |__ ___
4+
# | '__|| __|(_)| | / _` || '_ \ / __|
5+
# | | | |_ _ | || (_| || |_) |\__ \
6+
# |_| \__|(_)|_| \__,_||_.__/ |___/
7+
#
8+
# www.rt-labs.com
9+
# Copyright 2017 rt-labs AB, Sweden.
10+
#
11+
# This software is licensed under the terms of the BSD 3-clause
12+
# license. See the file LICENSE distributed with this software for
13+
# full license information.
14+
#*******************************************************************/
15+
16+
include_guard()
17+
18+
# the name of the target operating system
19+
set(CMAKE_SYSTEM_NAME rt-kernel)
20+
21+
# which compiler to use
22+
set(CMAKE_C_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
23+
set(CMAKE_CXX_COMPILER $ENV{COMPILERS}/arm-eabi/bin/arm-eabi-gcc)
24+
if(CMAKE_HOST_WIN32)
25+
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER}.exe)
26+
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}.exe)
27+
endif(CMAKE_HOST_WIN32)
28+
29+
set(ARCH xmc4)
30+
set(CPU cortex-m4f)
31+
32+
list(APPEND MACHINE
33+
-mcpu=cortex-m4
34+
-mthumb
35+
-mfloat-abi=hard
36+
-mfpu=fpv4-sp-d16
37+
)
38+
39+
add_definitions(${MACHINE})
40+
add_link_options(${MACHINE})

0 commit comments

Comments
 (0)