Introducing CMake is an important step in a larger effort to make Zephyr easy to use for application developers working on different platforms with different development environment needs. Simplified, this change retains Kconfig as-is, and replaces all Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild offers is replaced by a set of CMake extentions. These extentions have either provided simple one-to-one translations of KBuild features or introduced new concepts that replace KBuild concepts. This is a breaking change for existing test infrastructure and build scripts that are maintained out-of-tree. But for FW itself, no porting should be necessary. For users that just want to continue their work with minimal disruption the following should suffice: Install CMake 3.8.2+ Port any out-of-tree Makefiles to CMake. Learn the absolute minimum about the new command line interface: $ cd samples/hello_world $ mkdir build && cd build $ cmake -DBOARD=nrf52_pca10040 .. $ cd build $ make PR: zephyrproject-rtos#4692 docs: http://docs.zephyrproject.org/getting_started/getting_started.html Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
54 lines
2.0 KiB
CMake
54 lines
2.0 KiB
CMake
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.
|
|
zephyr_get_include_directories_as_string(includes)
|
|
zephyr_get_system_include_directories_as_string(system_includes)
|
|
zephyr_get_compile_definitions_as_string(definitions)
|
|
zephyr_get_compile_options_as_string(options)
|
|
|
|
set(external_project_cflags
|
|
${includes}${definitions}${options}${system_includes}
|
|
)
|
|
|
|
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.
|
|
set(mylib_dir ${CMAKE_CURRENT_SOURCE_DIR}/mylib)
|
|
ExternalProject_Add(
|
|
mylib_project # Name for custom target
|
|
PREFIX ${mylib_dir} # Root dir for entire project
|
|
SOURCE_DIR ${mylib_dir}
|
|
BINARY_DIR ${mylib_dir} # This particular build system is invoked from the root
|
|
CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf
|
|
BUILD_COMMAND
|
|
make
|
|
CC=${CMAKE_C_COMPILER}
|
|
CFLAGS=${external_project_cflags}
|
|
INSTALL_COMMAND "" # This particular build system has no install command
|
|
)
|
|
set(MYLIB_INCLUDE_DIR ${mylib_dir}/include)
|
|
set(MYLIB_LIB_DIR ${mylib_dir}/lib)
|
|
|
|
# Create a wrapper CMake library that our app can link with
|
|
add_library(mylib_lib STATIC IMPORTED)
|
|
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})
|
|
|
|
target_link_libraries(app mylib_lib)
|