Create .cmake file to allow higher flexibility of end user

This commit is contained in:
Tilen Majerle 2023-12-09 11:10:19 +01:00
parent 275a7de240
commit 181c2c7dd9
2 changed files with 41 additions and 19 deletions

View File

@ -1,21 +1,3 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
# Register core library include(${CMAKE_CURRENT_LIST_DIR}/library.cmake)
add_library(lwmem INTERFACE)
target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c)
target_include_directories(lwmem INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include)
# Add system port
if(DEFINED LWMEM_SYS_PORT)
target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c)
endif()
# Register core library with C++ extensions
add_library(lwmem_cpp INTERFACE)
target_sources(lwmem_cpp PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp)
target_include_directories(lwmem_cpp INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include)
# Create config file
if(DEFINED LWMEM_OPTS_DIR AND NOT EXISTS ${LWMEM_OPTS_DIR}/lwmem_opts.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwmem/lwmem_opts_template.h ${LWMEM_OPTS_DIR}/lwmem_opts.h COPYONLY)
endif()

40
lwmem/library.cmake Normal file
View File

@ -0,0 +1,40 @@
# Library core sources
set(lwmem_core_SRCS
${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c
)
# C++ extension
set(lwmem_core_cpp_SRCS
${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp
)
# Setup include directories
set(lwmem_include_DIRS
${CMAKE_CURRENT_LIST_DIR}/src/include
)
# Add system port
if(DEFINED LWMEM_SYS_PORT)
set(lwmem_core_SRCS ${lwmem_core_SRCS}
${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c
)
endif()
# Register core library
add_library(lwmem INTERFACE)
target_sources(lwmem PUBLIC ${lwmem_core_SRCS})
target_include_directories(lwmem INTERFACE ${lwmem_include_DIRS})
target_compile_options(lwmem PRIVATE ${LWMEM_COMPILE_OPTIONS})
target_compile_definitions(lwmem PRIVATE ${LWMEM_COMPILE_DEFINITIONS})
# Register core library with C++ extensions
add_library(lwmem_cpp INTERFACE)
target_sources(lwmem_cpp PUBLIC ${lwmem_core_SRCS})
target_include_directories(lwmem_cpp INTERFACE ${lwmem_include_DIRS})
target_compile_options(lwmem_cpp PRIVATE ${LWMEM_COMPILE_OPTIONS})
target_compile_definitions(lwmem_cpp PRIVATE ${LWMEM_COMPILE_DEFINITIONS})
# Create config file
if(DEFINED LWMEM_OPTS_DIR AND NOT EXISTS ${LWMEM_OPTS_DIR}/lwmem_opts.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwmem/lwmem_opts_template.h ${LWMEM_OPTS_DIR}/lwmem_opts.h COPYONLY)
endif()