Skip to content

Commit

Permalink
Improve docs and CMake configure_file
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Dec 8, 2023
1 parent 24a425b commit 056ea90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ else()
)

# Add subdir with lwprintf and link to the project
set(LWPRINTF_OPTS_DIR ${CMAKE_CURRENT_LIST_DIR}/dev)
add_subdirectory(lwprintf)
target_link_libraries(${PROJECT_NAME} lwprintf)
endif()
10 changes: 9 additions & 1 deletion docs/get-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Next step is to add the library to the project, by means of source files to comp
* Copy ``lwprintf/src/include/lwprintf/lwprintf_opts_template.h`` to project folder and rename it to ``lwprintf_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
^^^^^^^^^^^^^^^^^^

Expand All @@ -78,7 +82,11 @@ and it should be copied (or simply renamed in-place) and named ``lwprintf_opts.h
File must be renamed to ``lwprintf_opts.h`` first and then copied to the project directory where compiler
include paths have access to it by using ``#include "lwprintf_opts.h"``.

List of configuration options are available in the :ref:`api_lwprintf_opt` section.
.. tip::
If you are using *CMake* build system, define the variable ``LWPRINTF_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_lwprintf_opt` section.
If any option is about to be modified, it should be done in configuration file

.. literalinclude:: ../../lwprintf/src/include/lwprintf/lwprintf_opts_template.h
Expand Down
12 changes: 9 additions & 3 deletions lwprintf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ add_library(lwprintf INTERFACE)
target_sources(lwprintf PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwprintf/lwprintf.c)
target_include_directories(lwprintf INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include)

if (DEFINED LWPRINTF_SYS_PORT)
target_sources(lwprintf PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c)
# Add system port
if(DEFINED LWPRINTF_SYS_PORT)
target_sources(lwprintf PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/system/lwprintf_sys_${LWPRINTF_SYS_PORT}.c)
endif()

# Create config file
if(DEFINED LWPRINTF_OPTS_DIR AND NOT EXISTS ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwprintf/lwprintf_opts_template.h ${LWPRINTF_OPTS_DIR}/lwprintf_opts.h COPYONLY)
endif()

0 comments on commit 056ea90

Please sign in to comment.