diff --git a/CMakeLists.txt b/CMakeLists.txt index fa1e01b83..6bc1c1227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,17 @@ 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_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/include) +target_link_libraries(sof_options INTERFACE sof_public_headers) # get compiler name and version execute_process( @@ -104,8 +110,8 @@ endif() include(scripts/cmake/kconfig.cmake) -add_dependencies(sof_options genconfig check_version_h) -target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include) +add_dependencies(sof_public_headers genconfig check_version_h) +target_include_directories(sof_public_headers INTERFACE ${GENERATED_DIRECTORY}/include) if(BUILD_HOST) add_library(sof SHARED "") @@ -113,6 +119,22 @@ if(BUILD_HOST) 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() diff --git a/src/arch/host/CMakeLists.txt b/src/arch/host/CMakeLists.txt index ce21a08d6..9e812484f 100644 --- a/src/arch/host/CMakeLists.txt +++ b/src/arch/host/CMakeLists.txt @@ -1,6 +1,6 @@ # includes -target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/arch/host/include) -target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/platform/library/include) +target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/src/arch/host/include) +target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/src/platform/library/include) # C & ASM flags target_compile_options(sof_options INTERFACE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes -Wimplicit-fallthrough=3) diff --git a/src/arch/xtensa/CMakeLists.txt b/src/arch/xtensa/CMakeLists.txt index eb9b74dae..18b2b54ee 100644 --- a/src/arch/xtensa/CMakeLists.txt +++ b/src/arch/xtensa/CMakeLists.txt @@ -114,6 +114,13 @@ function(sof_add_ld_script binary_name script_name) list(APPEND glob_predicates "${d}/*.h") endforeach() + get_target_property(incdirs sof_public_headers INTERFACE_INCLUDE_DIRECTORIES) + + foreach(d ${incdirs}) + list(APPEND iflags "-I${d}") + list(APPEND glob_predicates "${d}/*.h") + endforeach() + file(GLOB lds_headers ${glob_predicates}) add_custom_command(OUTPUT ${lds_out}