Improve docs and CMake configure_file

This commit is contained in:
Tilen Majerle 2023-12-08 16:03:46 +01:00
parent 195ba53036
commit 275a7de240
3 changed files with 17 additions and 4 deletions

View File

@ -40,6 +40,7 @@ else()
)
# Add subdir with lwmem and link to the project
set(LWMEM_OPTS_DIR ${CMAKE_CURRENT_LIST_DIR}/dev)
add_subdirectory(lwmem)
target_link_libraries(${PROJECT_NAME} lwmem)
target_link_libraries(${PROJECT_NAME} lwmem_cpp)

View File

@ -66,6 +66,10 @@ Next step is to add the library to the project, by means of source files to comp
* Copy ``lwmem/src/include/lwmem/lwmem_opts_template.h`` to project folder and rename it to ``lwmem_opts.h``
* Build the project
.. tip::
If you are using *CMake* build system, you can add the library to the project by adding the *library's folder*
directory with ``add_directory()`` CMake command, followed by linking the target with ``target_link_libraries()``
Configuration file
^^^^^^^^^^^^^^^^^^
@ -78,7 +82,11 @@ and it should be copied (or simply renamed in-place) and named ``lwmem_opts.h``
File must be renamed to ``lwmem_opts.h`` first and then copied to the project directory where compiler
include paths have access to it by using ``#include "lwmem_opts.h"``.
List of configuration options are available in the :ref:`api_lwmem_opt` section.
.. tip::
If you are using *CMake* build system, define the variable ``LWMEM_OPTS_DIR`` before adding library's directory to the *CMake* project.
Variable must set the output directory path. CMake will copy the template file there, and name it as required.
Configuration options list is available available in the :ref:`api_lwmem_opt` section.
If any option is about to be modified, it should be done in configuration file
.. literalinclude:: ../../lwmem/src/include/lwmem/lwmem_opts_template.h

View File

@ -5,8 +5,9 @@ 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)
if (DEFINED LWMEM_SYS_PORT)
target_sources(lwmem PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c)
# 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
@ -14,4 +15,7 @@ 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)
# Register other modules
# 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()