forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (130 loc) · 4.83 KB
/
CMakeLists.txt
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.10)
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR
" In-source builds are not supported.\n"
" Please remove CMakeCache.txt and the CMakeFiles directory.\n"
" Then specify a build directory. Example: cmake -Bbuild ..."
)
endif()
if(NOT (${CMAKE_VERSION} VERSION_LESS "3.13.0"))
# CMake 3.13+ has less restrictive rules for target_link_libraries()
# Until we make 3.13 as required minimum version we want to
# use old behaviour for compatibility
cmake_policy(SET CMP0079 OLD)
endif()
option(BUILD_LIBRARY "Build library" OFF)
option(BUILD_UNIT_TESTS "Build unit tests" OFF)
if(BUILD_LIBRARY)
set(ARCH host)
else()
# firmware build supports only xtensa arch for now
set(ARCH xtensa)
endif()
# let user override built-in toolchains
if(DEFINED CMAKE_TOOLCHAIN_FILE)
set(TOOLCHAIN "${CMAKE_TOOLCHAIN_FILE}")
else()
include(scripts/cmake/${ARCH}-toolchain.cmake OPTIONAL)
endif()
include(scripts/cmake/misc.cmake)
project(SOF C ASM)
# intended to be used where PROJECT_* variables are not set
# for example in standalone scripts like version.cmake
set(SOF_ROOT_SOURCE_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(SOF_ROOT_BINARY_DIRECTORY "${PROJECT_BINARY_DIR}")
# check git hooks
include(scripts/cmake/git-hooks.cmake)
# most of other options are set on per-arch and per-target basis
set(CMAKE_ASM_FLAGS -DASSEMBLY)
# interface library that is used only as container for sof public header files
# that may be exported / installed
add_library(sof_public_headers INTERFACE)
target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/src/include)
# interface library that is used only as container for sof binary options
# other targets can use it to build with the same options
add_library(sof_options INTERFACE)
target_link_libraries(sof_options INTERFACE sof_public_headers)
# get compiler name and version
execute_process(
COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE cc_version_output
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
string(REGEX MATCH "^[^\r\n]+" CC_VERSION_TEXT "${cc_version_output}")
if(NOT CC_VERSION_TEXT)
message(WARNING "Couldn't get compiler version")
set(CC_VERSION_TEXT 0)
endif()
set(GENERATED_DIRECTORY ${PROJECT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${GENERATED_DIRECTORY}/include)
set(DOT_CONFIG_PATH ${GENERATED_DIRECTORY}/.config)
set(CONFIG_H_PATH ${GENERATED_DIRECTORY}/include/config.h)
set(VERSION_H_PATH ${GENERATED_DIRECTORY}/include/version.h)
include(scripts/cmake/version.cmake)
include(scripts/cmake/dist.cmake)
# cmake itself cannot depend on files that don't exist
# so to make it regenerate when .config file is created,
# we make it depend on containing directory
# NOTE: some filesystems may be unable to watch directory change,
# in that case cmake may need to be regenerated from CLI
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
${GENERATED_DIRECTORY} ${DOT_CONFIG_PATH})
if(EXISTS ${DOT_CONFIG_PATH})
read_kconfig_config(${DOT_CONFIG_PATH})
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# FindPythonInterp is bugged and may sometimes be unable to find
# Python 3 when both Python 2 & 3 are in PATH,
# so it's always better to use CMake 3.12+
find_package(PythonInterp 3.0)
set(PYTHON3 "${PYTHON_EXECUTABLE}")
else()
find_package(Python3 COMPONENTS Interpreter)
set(PYTHON3 "${Python3_EXECUTABLE}")
endif()
include(scripts/cmake/kconfig.cmake)
add_dependencies(sof_public_headers genconfig check_version_h)
target_include_directories(sof_public_headers INTERFACE ${GENERATED_DIRECTORY}/include)
if(BUILD_LIBRARY)
add_library(sof SHARED "")
target_link_libraries(sof PRIVATE sof_options)
install(TARGETS sof DESTINATION lib)
add_subdirectory(src)
get_target_property(incdirs sof_public_headers INTERFACE_INCLUDE_DIRECTORIES)
# we append slash at the end to make CMake copy contents of directories
# instead of directories
set(incdirs_for_install "")
foreach(d ${incdirs})
list(APPEND incdirs_for_install "${d}/")
endforeach()
install(DIRECTORY ${incdirs_for_install}
DESTINATION include
PATTERN "*.h"
)
# rest of this file is not needed for host build
return()
endif()
if(BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(src/arch/${ARCH})
add_subdirectory(test)
# rest of this file is not needed for unit tests
return()
endif()
# for FW just install uapi folder
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/include/uapi
DESTINATION include
PATTERN "*.h"
)
add_library(sof_ld_flags INTERFACE)
add_library(sof_ld_scripts INTERFACE)
# declare target with no sources to let cmake know about it
add_executable(sof "")
target_link_libraries(sof sof_options)
target_link_libraries(sof sof_ld_scripts)
target_link_libraries(sof sof_ld_flags)
sof_add_build_counter_rule()
add_subdirectory(src)
target_link_libraries(sof sof_lib)