2018-08-13 15:46:42 +08:00
|
|
|
cmake_minimum_required(VERSION 3.8.2)
|
2017-10-27 21:43:34 +08:00
|
|
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
|
|
project(NONE)
|
|
|
|
|
|
|
|
target_sources(app PRIVATE src/main.c)
|
|
|
|
|
|
|
|
# The external static library that we are linking with does not know
|
|
|
|
# how to build for this platform so we export all the flags used in
|
|
|
|
# this zephyr build to the external build system.
|
|
|
|
#
|
|
|
|
# Other external build systems may be self-contained enough that they
|
|
|
|
# do not need any build information from zephyr. Or they may be
|
|
|
|
# incompatible with certain zephyr options and need them to be
|
|
|
|
# filtered out.
|
2017-12-01 22:25:06 +08:00
|
|
|
zephyr_get_include_directories_for_lang_as_string( C includes)
|
|
|
|
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
|
|
|
|
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
|
|
|
|
zephyr_get_compile_options_for_lang_as_string( C options)
|
2017-10-27 21:43:34 +08:00
|
|
|
|
|
|
|
set(external_project_cflags
|
2017-12-01 22:25:06 +08:00
|
|
|
"${includes} ${definitions} ${options} ${system_includes}"
|
2017-10-27 21:43:34 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
include(ExternalProject)
|
|
|
|
|
|
|
|
# Add an external project to be able download and build the third
|
|
|
|
# party library. In this case downloading is not necessary as it has
|
|
|
|
# been committed to the repository.
|
2017-11-14 21:25:07 +08:00
|
|
|
set(mylib_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/mylib)
|
|
|
|
set(mylib_build_dir ${CMAKE_CURRENT_BINARY_DIR}/mylib)
|
2018-01-03 19:36:02 +08:00
|
|
|
|
|
|
|
set(MYLIB_LIB_DIR ${mylib_build_dir}/lib)
|
|
|
|
set(MYLIB_INCLUDE_DIR ${mylib_src_dir}/include)
|
|
|
|
|
2017-10-27 21:43:34 +08:00
|
|
|
ExternalProject_Add(
|
2017-11-14 21:25:07 +08:00
|
|
|
mylib_project # Name for custom target
|
|
|
|
PREFIX ${mylib_build_dir} # Root dir for entire project
|
|
|
|
SOURCE_DIR ${mylib_src_dir}
|
|
|
|
BINARY_DIR ${mylib_src_dir} # This particular build system is invoked from the root
|
2017-10-27 21:43:34 +08:00
|
|
|
CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf
|
|
|
|
BUILD_COMMAND
|
|
|
|
make
|
2017-11-14 21:25:07 +08:00
|
|
|
PREFIX=${mylib_build_dir}
|
2017-10-27 21:43:34 +08:00
|
|
|
CC=${CMAKE_C_COMPILER}
|
|
|
|
CFLAGS=${external_project_cflags}
|
|
|
|
INSTALL_COMMAND "" # This particular build system has no install command
|
2018-01-03 19:36:02 +08:00
|
|
|
BUILD_BYPRODUCTS ${MYLIB_LIB_DIR}/libmylib.a
|
2017-10-27 21:43:34 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
# Create a wrapper CMake library that our app can link with
|
2018-01-09 19:51:07 +08:00
|
|
|
add_library(mylib_lib STATIC IMPORTED GLOBAL)
|
2017-10-27 21:43:34 +08:00
|
|
|
add_dependencies(
|
|
|
|
mylib_lib
|
|
|
|
mylib_project
|
|
|
|
)
|
|
|
|
set_target_properties(mylib_lib PROPERTIES IMPORTED_LOCATION ${MYLIB_LIB_DIR}/libmylib.a)
|
|
|
|
set_target_properties(mylib_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${MYLIB_INCLUDE_DIR})
|
|
|
|
|
2018-06-22 20:35:44 +08:00
|
|
|
target_link_libraries(app PUBLIC mylib_lib)
|