Skip to content

Commit

Permalink
feat(cmake): pass-through the custom C++ namespace from CMake (#15)
Browse files Browse the repository at this point in the history
Via defining the LB_STD_VERSION_NS macro using the
target_compile_definitions().
Its name a bit inconsistent though, but looks better (in my opinion) in
C++, but doesn't look OK in a bunch of CMake configure parameters as it
conflicts with another flags (`LBSTD_VERSION_xxx` vs `LB_STD_VERSION_xxx`).
  • Loading branch information
leha-bot committed Sep 23, 2023
1 parent 2f10056 commit c2d9fa9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
cmake_minimum_required(VERSION 3.20)
project(lbstd_version VERSION 0.0.1 LANGUAGES CXX)

option(LBSTD_VERSION_NS_NAME "The enclosing namespace for all classes of std_version" "lbstd")
set(LBSTD_VERSION_NS "lbstd" CACHE STRING "The enclosing namespace for all classes of std_version")
option(LBSTD_VERSION_ENABLE_FMTLIB "Enable fmtlib formatters integration" ON)
option(LBSTD_VERSION_ENABLE_STDFORMAT "Enable std::format integration")
option(LBSTD_VERSION_ENABLE_TESTS "Enable tests" ON)

if (LBSTD_VERSION_NS STREQUAL "")
message(FATAL_ERROR "The enclosing namespace name in variable LBSTD_VERSION_NS must be a non-empty string!")
endif()

if (LBSTD_VERSION_ENABLE_FMTLIB)
find_package(fmt REQUIRED)
endif()

add_library(lbstd_version INTERFACE)
target_include_directories(lbstd_version INTERFACE "${CMAKE_SOURCE_DIR}/include")
target_compile_definitions(lbstd_version INTERFACE "LB_STD_VERSION_NS=${LBSTD_VERSION_NS}")
target_compile_features(lbstd_version INTERFACE cxx_std_20)

if (LBSTD_VERSION_ENABLE_TESTS)
Expand Down

0 comments on commit c2d9fa9

Please sign in to comment.