Files
libmetal/cmake/options.cmake
Tanmay Shah 90d19dc759 libmetal: cmake: support machine less build
libmetal can be build without any machine support. It is possible that
vendors implement machine specific interfaces outside of libmetal and
link it with demos during build time. Hence, remove requirement to have
MACHINE and PROJECT_MACHINE variables from the build system. If vendor
prefer to choose 'template' machine, they can pass such option during
cmake configuration.

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
2026-02-04 11:32:12 +01:00

84 lines
2.7 KiB
CMake

file(READ ${LIBMETAL_ROOT_DIR}/VERSION ver)
string(REGEX MATCH "VERSION_MAJOR = ([0-9]*)" _ ${ver})
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_MINOR = ([0-9]*)" _ ${ver})
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_PATCH = ([0-9]*)" _ ${ver})
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_1})
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
message(STATUS "libmetal version: ${PROJECT_VERSION} (${CMAKE_SOURCE_DIR})")
if (NOT DEFINED CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Debug)
endif (NOT DEFINED CMAKE_BUILD_TYPE)
message ("-- Build type: ${CMAKE_BUILD_TYPE}")
if (NOT CMAKE_INSTALL_LIBDIR)
set (CMAKE_INSTALL_LIBDIR "lib")
endif (NOT CMAKE_INSTALL_LIBDIR)
if (NOT CMAKE_INSTALL_BINDIR)
set (CMAKE_INSTALL_BINDIR "bin")
endif (NOT CMAKE_INSTALL_BINDIR)
set (_host "${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR}")
message ("-- Host: ${_host}")
set (_target "${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
message ("-- Target: ${_target}")
if (NOT DEFINED PROJECT_SYSTEM)
string (TOLOWER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM)
string (TOUPPER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM_UPPER)
endif (NOT DEFINED PROJECT_SYSTEM)
string (TOLOWER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR)
if("${PROJECT_PROCESSOR}" STREQUAL "arm64")
set (PROJECT_PROCESSOR "aarch64")
endif()
string (TOUPPER ${PROJECT_PROCESSOR} PROJECT_PROCESSOR_UPPER)
if (DEFINED MACHINE)
# handle if '-' in machine name
string (REPLACE "-" "_" MACHINE ${MACHINE})
message ("-- Machine: ${MACHINE}")
string (TOLOWER ${MACHINE} PROJECT_MACHINE)
string (TOUPPER ${MACHINE} PROJECT_MACHINE_UPPER)
endif (DEFINED MACHINE)
option (WITH_STATIC_LIB "Build with a static library" ON)
if ("${PROJECT_SYSTEM}" STREQUAL "linux")
option (WITH_SHARED_LIB "Build with a shared library" ON)
option (WITH_TESTS "Install test applications" ON)
endif ("${PROJECT_SYSTEM}" STREQUAL "linux")
if (WITH_TESTS AND (${_host} STREQUAL ${_target}))
option (WITH_TESTS_EXEC "Run test applications during build" ON)
endif (WITH_TESTS AND (${_host} STREQUAL ${_target}))
if (WITH_ZEPHYR)
option (WITH_ZEPHYR_LIB "Build libmetal as a zephyr library" OFF)
endif (WITH_ZEPHYR)
option (WITH_DEFAULT_LOGGER "Build with default logger" ON)
option (WITH_FUNC_LINE_LOG "Log with function name, line number prefix" OFF)
option (WITH_DOC "Build with documentation" ON)
set_property (GLOBAL PROPERTY "PROJECT_EC_FLAGS" -Wall -Werror -Wextra)
if (NOT DEFINED PROJECT_VENDOR)
set (PROJECT_VENDOR "none")
endif (NOT DEFINED PROJECT_VENDOR)
message ("-- Vendor: ${PROJECT_VENDOR}")
if (${PROJECT_VENDOR} STREQUAL xlnx)
add_definitions( -DXLNX_PLATFORM )
endif()