From 275a7de240a032ec2585c7ea8772b7f0616003f2 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 8 Dec 2023 16:03:46 +0100 Subject: [PATCH] Improve docs and CMake configure_file --- CMakeLists.txt | 1 + docs/get-started/index.rst | 10 +++++++++- lwmem/CMakeLists.txt | 10 +++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89ba41f..3bef347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index f4ba963..e000848 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -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 diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index d6601c9..4b7b6cd 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -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()