Skip to content

Commit 7d805ae

Browse files
committed
CMake: build libmetal for Zephyr
Enable buildling libmetal for Zephyr Here is the step to build libmetal for Zephyr: % export ZEPHRY_GCC_VARIANT=zephyr % export ZEPHRY_SDK_INSTALL_DIR=<where Zephyr SDK is installed> % source <git_clone_zephyr_project_source_root>/zephyr-env.sh % cmake <libmetal_source_root> -DWITH_ZEPHYR=on -DBOARD=qemu_cortex_m3 % make VERBOSE=1 all libmetal will be generated in "<BUILD_DIR>/lib/libmetal.a" Signed-off-by: Wendy Liang <jliang@xilinx.com>
1 parent acd920c commit 7d805ae

File tree

4 files changed

+50
-30
lines changed

4 files changed

+50
-30
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ list (APPEND CMAKE_MODULE_PATH
55
"${CMAKE_SOURCE_DIR}/cmake/modules"
66
"${CMAKE_SOURCE_DIR}/cmake/platforms")
77

8+
include (syscheck)
89
project (metal C)
910

1011
include (CheckIncludeFiles)
@@ -20,6 +21,7 @@ endforeach()
2021
enable_testing ()
2122

2223
add_subdirectory (lib)
24+
2325
if (WITH_TESTS)
2426
add_subdirectory (test)
2527
endif (WITH_TESTS)

cmake/depends.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
2424

2525
else ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
2626

27-
# TODO: fix for find_path() to detect stdatomic.h
27+
# TODO: fix for find_path() to detect stdatomic.h
2828
# find_path (HAVE_STDATOMIC_H stdatomic.h)
2929
set (_saved_cmake_required_flags ${CMAKE_REQUIRED_FLAGS})
3030
set (CMAKE_REQUIRED_FLAGS "-c" CACHE STRING "")

cmake/syscheck.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# use "Generic" as CMAKE_SYSTEM_NAME
2+
3+
if (WITH_ZEPHYR)
4+
set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "")
5+
string (TOLOWER "Zephyr" PROJECT_SYSTEM)
6+
string (TOUPPER "Zephyr" PROJECT_SYSTEM_UPPER)
7+
set(IS_TEST 1)
8+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
9+
if (CONFIG_CPU_CORTEX_M)
10+
set (MACHINE "cortexm" CACHE STRING "")
11+
endif (CONFIG_CPU_CORTEX_M)
12+
endif (WITH_ZEPHYR)

lib/CMakeLists.txt

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,41 @@ if (WITH_DEFAULT_LOGGER)
5959
add_definitions (-DDEFAULT_LOGGER_ON)
6060
endif (WITH_DEFAULT_LOGGER)
6161

62-
# Build a shared library if so configured.
63-
if (WITH_SHARED_LIB)
64-
set (_lib ${PROJECT_NAME}-shared)
65-
add_library (${_lib} SHARED ${_sources})
66-
target_link_libraries (${_lib} ${_deps})
67-
install (TARGETS ${_lib} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
68-
if (PROJECT_EC_FLAGS)
69-
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
70-
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
71-
endif (PROJECT_EC_FLAGS)
72-
set_target_properties (${_lib} PROPERTIES
73-
OUTPUT_NAME "${PROJECT_NAME}"
74-
VERSION "${PROJECT_VER}"
75-
SOVERSION "${PROJECT_VER_MAJOR}"
76-
)
77-
endif (WITH_SHARED_LIB)
62+
if (WITH_ZEPHYR)
63+
zephyr_library_named(metal)
64+
add_dependencies(metal offsets_h)
65+
target_sources (metal PRIVATE ${_sources})
66+
else (WITH_ZEPHYR)
67+
# Build a shared library if so configured.
68+
if (WITH_SHARED_LIB)
69+
set (_lib ${PROJECT_NAME}-shared)
70+
add_library (${_lib} SHARED ${_sources})
71+
target_link_libraries (${_lib} ${_deps})
72+
install (TARGETS ${_lib} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
73+
if (PROJECT_EC_FLAGS)
74+
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
75+
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
76+
endif (PROJECT_EC_FLAGS)
77+
set_target_properties (${_lib} PROPERTIES
78+
OUTPUT_NAME "${PROJECT_NAME}"
79+
VERSION "${PROJECT_VER}"
80+
SOVERSION "${PROJECT_VER_MAJOR}"
81+
)
82+
endif (WITH_SHARED_LIB)
7883

79-
# Build a static library if so configured.
80-
if (WITH_STATIC_LIB)
81-
set (_lib ${PROJECT_NAME}-static)
82-
add_library (${_lib} STATIC ${_sources})
83-
install (TARGETS ${_lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
84-
if (PROJECT_EC_FLAGS)
85-
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
86-
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
87-
endif (PROJECT_EC_FLAGS)
88-
set_target_properties (${_lib} PROPERTIES
89-
OUTPUT_NAME "${PROJECT_NAME}"
90-
)
91-
endif (WITH_STATIC_LIB)
84+
# Build a static library if so configured.
85+
if (WITH_STATIC_LIB)
86+
set (_lib ${PROJECT_NAME}-static)
87+
add_library (${_lib} STATIC ${_sources})
88+
install (TARGETS ${_lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
89+
if (PROJECT_EC_FLAGS)
90+
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
91+
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
92+
endif (PROJECT_EC_FLAGS)
93+
set_target_properties (${_lib} PROPERTIES
94+
OUTPUT_NAME "${PROJECT_NAME}"
95+
)
96+
endif (WITH_STATIC_LIB)
97+
endif (WITH_ZEPHYR)
9298

9399
# vim: expandtab:ts=2:sw=2:smartindent

0 commit comments

Comments
 (0)