Skip to content

Commit

Permalink
Make USE_LATEST_STD cmake option.-
Browse files Browse the repository at this point in the history
Determine minimum cxx standard for library.
  • Loading branch information
gabyx committed Jan 27, 2019
1 parent d5e15bc commit d4f31cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ option(BUILD_PACKAGE "Enable this to build the installer" ON)
option(USE_PCH "Use precompiled header files for compilation" ON)
option(CUSTOM_DOXYGEN_STYLE "Enable this option to use a custom doxygen style for HTML documentation; Otherwise the default will be used" ON)
option(BUILD_WEBSITE_DOCU "Enable this option to create the special docu for the website" OFF)
option(USE_LATEST_STD "Build the library using the latest std-library fetures and making it probably not backward compatible." OFF)

# one precompiled headers cannot be used for multiple ninja targets
# thats why we have to disable this option, when BUILD_STATIC or
Expand Down
24 changes: 19 additions & 5 deletions src/rttr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,38 @@ if (USE_PCH)
activate_precompiled_headers("detail/base/pch.h" SRC_FILES)
endif()

# Determine the minium required standard.
if (USE_LATEST_STD)
if (MAX_CXX_STANDARD GREATER_EQUAL 17)
list(APPEND COMPILE_DEFS "RTTR_USE_STD_STRING_VIEW")
set(MIN_CXX_STANDARD cxx_std_17)
endif ()
else ()
set(MIN_CXX_STANDARD cxx_std_11) # at least c++11 is needed to compile RTTR
endif ()

if (${BUILD_RTTR_DYNAMIC})
add_library(rttr_core SHARED ${UnityBuild} ${SRC_FILES} ${HPP_FILES})
add_library(RTTR::Core ALIAS rttr_core)

target_compile_definitions(rttr_core PRIVATE RTTR_DLL_EXPORTS)
target_compile_definitions(rttr_core PUBLIC RTTR_DLL)



set_target_properties(rttr_core PROPERTIES
VERSION ${RTTR_VERSION} SOVERSION ${RTTR_VERSION}
EXPORT_NAME Core
DEBUG_POSTFIX ${RTTR_DEBUG_POSTFIX}
CXX_STANDARD ${MAX_CXX_STANDARD}
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1)


target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS})

target_link_libraries(rttr_core PRIVATE ${CMAKE_DL_LIBS})


if(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
target_compile_features(rttr_core PUBLIC cxx_std_11) # at least c++11 is needed to compile RTTR
target_compile_features(rttr_core PUBLIC ${MIN_CXX_STANDARD})
endif()

target_include_directories(rttr_core PUBLIC
Expand Down Expand Up @@ -94,7 +104,9 @@ if (BUILD_STATIC)
EXPORT_NAME Core_Lib
CXX_STANDARD ${MAX_CXX_STANDARD}
DEBUG_POSTFIX ${RTTR_DEBUG_POSTFIX})


target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS})

target_link_libraries(rttr_core_lib PRIVATE ${CMAKE_DL_LIBS})

if (MSVC)
Expand Down Expand Up @@ -139,6 +151,8 @@ if (BUILD_WITH_STATIC_RUNTIME_LIBS)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
$<INSTALL_INTERFACE:include>)

target_compile_definitions(rttr_core PUBLIC ${COMPILE_DEFS})

target_link_libraries(rttr_core_s PRIVATE ${CMAKE_DL_LIBS})

set_target_properties(rttr_core_s PROPERTIES
Expand Down
8 changes: 6 additions & 2 deletions src/rttr/detail/base/core_prerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,12 @@ namespace rttr
/////////////////////////////////////////////////////////////////////////////////////////
// Enable some C++17 Features
/////////////////////////////////////////////////////////////////////////////////////////
#if __cplusplus >= 201703L
#define RTTR_ENABLE_STD_STRING_VIEW
#ifdef RTTR_USE_STD_STRING_VIEW
#if __cplusplus >= 201703L
#define RTTR_ENABLE_STD_STRING_VIEW
#else
#error "Linking with this library needs C++17, as std::string_view is required."
#endif
#endif

} // end namespace rttr
Expand Down

0 comments on commit d4f31cd

Please sign in to comment.