forked from rtlabs-com/cmake-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddOsal.cmake
63 lines (58 loc) · 2.1 KB
/
AddOsal.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# www.rt-labs.com
# Copyright 2020 rt-labs AB, Sweden.
#
# This software is licensed under the terms of the BSD 3-clause
# license. See the file LICENSE distributed with this software for
# full license information.
#*******************************************************************/
# Find OSAL library. This module supports three use-cases:
#
# 1) OSAL sibling project
#
# If a target named OSAL exists then this module does nothing. This
# would be the case if OSAL is managed by a superproject.
#
# 2) External OSAL
#
# Search for and use an external OSAL. CMake will find the external
# OSAL library if it is installed in a default location such as
# /usr/include or /usr/local/include. You can also give a search hint
# by setting the Osal_DIR variable. This could be the case for a
# native build or a cross-compiled Linux system with a staging folder.
#
# 3) Automatic download and build of OSAL
#
# Finally, if OSAL is not found in the system it will be downloaded
# and built automatically.
cmake_minimum_required(VERSION 3.14)
if (NOT TARGET osal)
# Attempt to find externally built OSAL
find_package(Osal QUIET)
if (NOT Osal_FOUND)
# Download and build OSAL locally as a static library
include(FetchContent)
FetchContent_Declare(
osal
GIT_REPOSITORY https://github.com/rtlabs-com/osal.git
GIT_TAG 57b4ae2
)
FetchContent_GetProperties(osal)
if(NOT osal_POPULATED)
FetchContent_Populate(osal)
set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${osal_SOURCE_DIR} ${osal_BINARY_DIR} EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD} CACHE BOOL "" FORCE)
endif()
# Hide Osal_DIR to avoid confusion, as it is not used in this
# configuration
mark_as_advanced(Osal_DIR)
endif()
endif()