You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KED/ked/CMakeLists.txt

73 lines
1.8 KiB

cmake_minimum_required(VERSION 3.10)
project(ked_flexible_build C)
set(CMAKE_C_STANDARD 11)
# User must provide:
# -DMAIN_FILE: the main .c file to compile
# User must provide:
# -DMAIN_FILE: the main .c file to compile
if(NOT DEFINED MAIN_FILE)
message(FATAL_ERROR "MAIN_FILE must be specified.")
endif()
# Automatically infer PROJECT_ROOT as one level above this directory
get_filename_component(PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
message(STATUS "KED > CMAKE Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "KED > Project Root Dir: ${PROJECT_ROOT}")
# Interface headers to resolve against
set(KED_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/peripherals/gpio/gpio.h
)
set(KED_IMPL_SOURCES "")
foreach(header ${KED_HEADERS})
message(STATUS "KED > Project Headers: ${KED_HEADERS}")
file(RELATIVE_PATH rel_path ${CMAKE_CURRENT_SOURCE_DIR} ${header})
string(REPLACE ".h" ".c" impl_rel_path ${rel_path})
set(impl_path "${PROJECT_ROOT}/${impl_rel_path}")
if(EXISTS ${impl_path})
message(STATUS "KED > Project Sources: ${impl_path}")
list(APPEND KED_IMPL_SOURCES ${impl_path})
else()
message(FATAL_ERROR "KED > Missing implementation for ${rel_path}: ${impl_path}")
endif()
endforeach()
set(KED_MAIN ${PROJECT_ROOT}/${MAIN_FILE})
message(STATUS "KED > MAIN File: ${KED_MAIN}")
# Create the executable
add_executable(ked_executable
${KED_MAIN}
${KED_IMPL_SOURCES}
)
# Use libgpiod if available
find_package(PkgConfig)
pkg_check_modules(GPIOD libgpiod)
if(GPIOD_FOUND)
message(STATUS "KED > libgpiod found — defining KED_USES_LINUX")
target_compile_definitions(ked_executable PRIVATE KED_USES_LINUX)
endif()
target_include_directories(ked_executable PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_ROOT}
${GPIOD_INCLUDE_DIRS}
)
target_link_libraries(ked_executable
${GPIOD_LIBRARIES}
)