2019-06-02 03:33:40 +08:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2021-09-09 05:54:20 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
2019-01-12 03:43:00 +08:00
|
|
|
|
2019-01-28 03:57:31 +08:00
|
|
|
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()
|
|
|
|
|
2021-09-09 05:54:20 +08:00
|
|
|
find_package(Python3 COMPONENTS Interpreter)
|
|
|
|
set(PYTHON3 "${Python3_EXECUTABLE}")
|
2021-02-05 16:20:16 +08:00
|
|
|
|
2019-01-15 09:49:50 +08:00
|
|
|
option(BUILD_UNIT_TESTS "Build unit tests" OFF)
|
2021-04-17 05:27:34 +08:00
|
|
|
option(BUILD_UNIT_TESTS_HOST "Build unit tests for host" OFF)
|
2021-04-18 22:46:09 +08:00
|
|
|
option(BUILD_UNIT_TESTS_XTENSA_GCC "Build xtensa unit test using GCC" OFF)
|
2020-02-27 21:28:25 +08:00
|
|
|
option(BUILD_CLANG_SCAN "Build for clang's scan-build" OFF)
|
2020-08-27 13:35:46 +08:00
|
|
|
option(BUILD_COUNTERS "Enable build counter(s), timestamps and any other
|
|
|
|
non-deterministic build features" OFF)
|
2019-01-15 17:46:20 +08:00
|
|
|
|
2021-04-17 05:27:34 +08:00
|
|
|
if(CONFIG_LIBRARY OR BUILD_UNIT_TESTS_HOST)
|
2019-01-15 17:46:20 +08:00
|
|
|
set(ARCH host)
|
|
|
|
else()
|
|
|
|
# firmware build supports only xtensa arch for now
|
|
|
|
set(ARCH xtensa)
|
|
|
|
endif()
|
2019-01-12 03:43:00 +08:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2019-02-09 05:49:47 +08:00
|
|
|
# intended to be used where PROJECT_* variables are not set
|
2019-02-08 08:16:09 +08:00
|
|
|
# for example in standalone scripts like version.cmake
|
|
|
|
set(SOF_ROOT_SOURCE_DIRECTORY "${PROJECT_SOURCE_DIR}")
|
2019-02-09 05:49:47 +08:00
|
|
|
set(SOF_ROOT_BINARY_DIRECTORY "${PROJECT_BINARY_DIR}")
|
2019-02-08 08:16:09 +08:00
|
|
|
|
2019-03-20 19:57:10 +08:00
|
|
|
# check git hooks
|
|
|
|
include(scripts/cmake/git-hooks.cmake)
|
|
|
|
|
2020-04-05 17:19:44 +08:00
|
|
|
# checkout submodules
|
|
|
|
include(scripts/cmake/git-submodules.cmake)
|
|
|
|
|
2019-01-15 17:46:20 +08:00
|
|
|
# most of other options are set on per-arch and per-target basis
|
|
|
|
set(CMAKE_ASM_FLAGS -DASSEMBLY)
|
|
|
|
|
2019-04-29 17:54:55 +08:00
|
|
|
# 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)
|
|
|
|
|
2019-01-15 17:46:20 +08:00
|
|
|
# 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)
|
|
|
|
|
2019-04-29 17:54:55 +08:00
|
|
|
target_link_libraries(sof_options INTERFACE sof_public_headers)
|
2019-01-15 17:46:20 +08:00
|
|
|
|
2020-08-27 13:35:46 +08:00
|
|
|
if(BUILD_COUNTERS)
|
|
|
|
target_compile_definitions(sof_options INTERFACE BLD_COUNTERS=1)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(sof_options INTERFACE BLD_COUNTERS=0)
|
|
|
|
endif()
|
|
|
|
|
2019-08-09 18:59:20 +08:00
|
|
|
# interface library that is used only as container for sof statically
|
|
|
|
# linked libraries
|
|
|
|
add_library(sof_static_libraries INTERFACE)
|
|
|
|
|
2019-01-12 03:43:00 +08:00
|
|
|
# get compiler name and version
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} --version
|
2019-01-30 15:46:04 +08:00
|
|
|
OUTPUT_VARIABLE cc_version_output
|
2019-01-12 03:43:00 +08:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
|
2019-01-30 15:46:04 +08:00
|
|
|
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()
|
|
|
|
|
2019-01-12 03:43:00 +08:00
|
|
|
set(GENERATED_DIRECTORY ${PROJECT_BINARY_DIR}/generated)
|
|
|
|
file(MAKE_DIRECTORY ${GENERATED_DIRECTORY}/include)
|
|
|
|
|
|
|
|
set(DOT_CONFIG_PATH ${GENERATED_DIRECTORY}/.config)
|
2020-06-16 14:15:01 +08:00
|
|
|
set(CONFIG_H_PATH ${GENERATED_DIRECTORY}/include/autoconfig.h CACHE
|
2020-06-16 17:25:05 +08:00
|
|
|
PATH "Path to kconfig's .h output file")
|
2022-01-14 07:56:15 +08:00
|
|
|
set(VERSION_H_PATH ${GENERATED_DIRECTORY}/include/sof_versions.h)
|
2019-01-12 03:43:00 +08:00
|
|
|
|
|
|
|
include(scripts/cmake/version.cmake)
|
|
|
|
|
2019-02-05 19:41:25 +08:00
|
|
|
include(scripts/cmake/dist.cmake)
|
|
|
|
|
2019-02-07 03:42:34 +08:00
|
|
|
include(scripts/cmake/kconfig.cmake)
|
2021-02-05 16:20:16 +08:00
|
|
|
read_kconfig_config(${DOT_CONFIG_PATH})
|
|
|
|
|
|
|
|
# FIXME: this successful triggers CMake to re-run, however -imacros
|
|
|
|
# hides the generated .h dependency from CMake and most sources are NOT
|
|
|
|
# recompiled.
|
|
|
|
set_property(DIRECTORY APPEND
|
|
|
|
PROPERTY CMAKE_CONFIGURE_DEPENDS ${DOT_CONFIG_PATH})
|
2019-01-12 03:43:00 +08:00
|
|
|
|
2019-04-29 17:54:55 +08:00
|
|
|
add_dependencies(sof_public_headers genconfig check_version_h)
|
|
|
|
target_include_directories(sof_public_headers INTERFACE ${GENERATED_DIRECTORY}/include)
|
2019-01-15 09:49:50 +08:00
|
|
|
|
2020-04-23 21:02:43 +08:00
|
|
|
if(CONFIG_LIBRARY)
|
2020-10-07 07:48:08 +08:00
|
|
|
if (CONFIG_LIBRARY_STATIC)
|
|
|
|
add_library(sof STATIC "")
|
|
|
|
else()
|
|
|
|
add_library(sof SHARED "")
|
|
|
|
endif()
|
2019-04-26 03:56:19 +08:00
|
|
|
target_link_libraries(sof PRIVATE sof_options)
|
2019-08-09 18:59:20 +08:00
|
|
|
target_link_libraries(sof PRIVATE sof_static_libraries)
|
2019-04-26 03:56:19 +08:00
|
|
|
install(TARGETS sof DESTINATION lib)
|
|
|
|
|
2019-04-25 21:44:21 +08:00
|
|
|
add_subdirectory(src)
|
2019-04-29 17:54:55 +08:00
|
|
|
|
2019-11-08 01:54:27 +08:00
|
|
|
sof_append_relative_path_definitions(sof)
|
|
|
|
|
2019-04-29 17:54:55 +08:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2019-04-25 21:44:21 +08:00
|
|
|
# rest of this file is not needed for host build
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2019-01-15 09:49:50 +08:00
|
|
|
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()
|
|
|
|
|
2019-06-10 18:19:31 +08:00
|
|
|
# for FW just install api folders
|
|
|
|
install(
|
|
|
|
DIRECTORY
|
|
|
|
${PROJECT_SOURCE_DIR}/src/include/ipc
|
|
|
|
${PROJECT_SOURCE_DIR}/src/include/kernel
|
|
|
|
${PROJECT_SOURCE_DIR}/src/include/user
|
2020-04-05 17:19:44 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/rimage/src/include/sof/kernel
|
|
|
|
${PROJECT_SOURCE_DIR}/rimage/src/include/sof/user
|
2019-06-10 18:19:31 +08:00
|
|
|
DESTINATION include/sof
|
2019-05-13 19:29:06 +08:00
|
|
|
PATTERN "*.h"
|
|
|
|
)
|
|
|
|
|
2019-01-12 03:43:00 +08:00
|
|
|
add_library(sof_ld_flags INTERFACE)
|
|
|
|
add_library(sof_ld_scripts INTERFACE)
|
|
|
|
|
2020-07-15 00:46:27 +08:00
|
|
|
target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/third_party_include)
|
|
|
|
link_directories(${PROJECT_SOURCE_DIR}/third_party_libraries)
|
|
|
|
|
2019-01-12 03:43:00 +08:00
|
|
|
# declare target with no sources to let cmake know about it
|
|
|
|
add_executable(sof "")
|
2019-08-08 16:44:40 +08:00
|
|
|
target_link_libraries(sof PRIVATE sof_options)
|
|
|
|
target_link_libraries(sof PRIVATE sof_ld_scripts)
|
|
|
|
target_link_libraries(sof PRIVATE sof_ld_flags)
|
2019-08-09 18:59:20 +08:00
|
|
|
target_link_libraries(sof PRIVATE sof_static_libraries)
|
2019-01-12 03:43:00 +08:00
|
|
|
|
2020-08-27 13:35:46 +08:00
|
|
|
if (BUILD_COUNTERS)
|
2019-02-09 05:49:47 +08:00
|
|
|
sof_add_build_counter_rule()
|
2020-08-27 13:35:46 +08:00
|
|
|
endif()
|
2019-02-09 05:49:47 +08:00
|
|
|
|
2019-01-12 03:43:00 +08:00
|
|
|
add_subdirectory(src)
|
2019-11-08 01:54:27 +08:00
|
|
|
|
|
|
|
sof_append_relative_path_definitions(sof)
|