diff --git a/CMakeLists.txt b/CMakeLists.txt index c132ea4..362892b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ else() ) # Add subdir with lwbtn and link to project - set(LWBTN_OPTS_DIR ${CMAKE_CURRENT_LIST_DIR}/dev) + set(LWBTN_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwbtn_opts.h) add_subdirectory(lwbtn) target_link_libraries(${PROJECT_NAME} lwbtn) endif() diff --git a/docs/get-started/index.rst b/docs/get-started/index.rst index 3296840..1ddee62 100644 --- a/docs/get-started/index.rst +++ b/docs/get-started/index.rst @@ -89,8 +89,8 @@ and it should be copied (or simply renamed in-place) and named ``lwbtn_opts.h`` include paths have access to it by using ``#include "lwbtn_opts.h"``. .. tip:: - If you are using *CMake* build system, define the variable ``LWBTN_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. + If you are using *CMake* build system, define the variable ``LWBTN_OPTS_FILE`` before adding library's directory to the *CMake* project. + Variable must contain the path to the user options file. If not provided, one will be generated in the build directory. Configuration options list is available available in the :ref:`api_lwbtn_opt` section. If any option is about to be modified, it should be done in configuration file diff --git a/lwbtn/library.cmake b/lwbtn/library.cmake index 5ac4626..ad152cc 100644 --- a/lwbtn/library.cmake +++ b/lwbtn/library.cmake @@ -1,14 +1,19 @@ # +# LIB_PREFIX: LWBTN +# # This file provides set of variables for end user # and also generates one (or more) libraries, that can be added to the project using target_link_libraries(...) # # Before this file is included to the root CMakeLists file (using include() function), user can set some variables: # -# LWBTN_OPTS_DIR: If defined, it should set the folder path where options file shall be generated. +# LWBTN_OPTS_FILE: If defined, it is the path to the user options file. If not defined, one will be generated for you automatically # LWBTN_COMPILE_OPTIONS: If defined, it provide compiler options for generated library. # LWBTN_COMPILE_DEFINITIONS: If defined, it provides "-D" definitions to the library build # +# Custom include directory +set(LWBTN_CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib_inc) + # Library core sources set(lwbtn_core_SRCS ${CMAKE_CURRENT_LIST_DIR}/src/lwbtn/lwbtn.c @@ -17,6 +22,7 @@ set(lwbtn_core_SRCS # Setup include directories set(lwbtn_include_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/include + ${LWBTN_CUSTOM_INC_DIR} ) # Register library to the system @@ -26,7 +32,11 @@ target_include_directories(lwbtn INTERFACE ${lwbtn_include_DIRS}) target_compile_options(lwbtn PRIVATE ${LWBTN_COMPILE_OPTIONS}) target_compile_definitions(lwbtn PRIVATE ${LWBTN_COMPILE_DEFINITIONS}) -# Create config file -if(DEFINED LWBTN_OPTS_DIR AND NOT EXISTS ${LWBTN_OPTS_DIR}/lwbtn_opts.h) - configure_file(${CMAKE_CURRENT_LIST_DIR}/src/include/lwbtn/lwbtn_opts_template.h ${LWBTN_OPTS_DIR}/lwbtn_opts.h COPYONLY) -endif() \ No newline at end of file +# Create config file if user didn't provide one info himself +if(NOT LWBTN_OPTS_FILE) + message(STATUS "Using default lwbtn_opts.h file") + set(LWBTN_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/src/include/lwbtn/lwbtn_opts_template.h) +else() + message(STATUS "Using custom lwbtn_opts.h file from ${LWBTN_OPTS_FILE}") +endif() +configure_file(${LWBTN_OPTS_FILE} ${LWBTN_CUSTOM_INC_DIR}/lwbtn_opts.h COPYONLY) \ No newline at end of file