mirror of
https://github.com/isar/libmdbx.git
synced 2025-04-04 04:02:57 +08:00
mdbx-cmake: require C99 or use C11 when available.
Change-Id: I241e8c38232750efb537a0b581f822540f207cdc
This commit is contained in:
parent
83a0c31b35
commit
70350bad81
@ -75,6 +75,14 @@ if(NOT CMAKE_BUILD_TYPE)
|
|||||||
FORCE)
|
FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
|
||||||
|
if(NOT HAS_C11 LESS 0)
|
||||||
|
set(MDBX_C_STANDARD 11)
|
||||||
|
else()
|
||||||
|
set(MDBX_C_STANDARD 99)
|
||||||
|
endif()
|
||||||
|
message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx")
|
||||||
|
|
||||||
# not supported by this (minimal) script
|
# not supported by this (minimal) script
|
||||||
add_definitions(-DMDBX_AVOID_CRT=0)
|
add_definitions(-DMDBX_AVOID_CRT=0)
|
||||||
|
|
||||||
@ -141,9 +149,13 @@ if(NOT DEFINED MDBX_BUILD_SHARED_LIBRARY)
|
|||||||
endif()
|
endif()
|
||||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||||
add_library(mdbx SHARED mdbx.c mdbx.h)
|
add_library(mdbx SHARED mdbx.c mdbx.h)
|
||||||
|
set_target_properties(mdbx PROPERTIES
|
||||||
|
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||||
|
PUBLIC_HEADER mdbx.h)
|
||||||
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
||||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||||
set_target_properties(mdbx PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
set_target_properties(mdbx PROPERTIES
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(mdbx PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(mdbx PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
@ -153,9 +165,13 @@ endif()
|
|||||||
|
|
||||||
# static library used for tools, to avoid rpath/dll-path troubles
|
# static library used for tools, to avoid rpath/dll-path troubles
|
||||||
add_library(mdbx-static STATIC EXCLUDE_FROM_ALL mdbx.c mdbx.h)
|
add_library(mdbx-static STATIC EXCLUDE_FROM_ALL mdbx.c mdbx.h)
|
||||||
|
set_target_properties(mdbx-static PROPERTIES
|
||||||
|
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||||
|
PUBLIC_HEADER mdbx.h)
|
||||||
target_link_libraries(mdbx-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(mdbx-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
||||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||||
set_target_properties(mdbx-static PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
set_target_properties(mdbx-static PROPERTIES
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||||
endif()
|
endif()
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(mdbx-static INTERFACE ntdll.lib)
|
target_link_libraries(mdbx-static INTERFACE ntdll.lib)
|
||||||
@ -164,8 +180,11 @@ endif()
|
|||||||
# mdbx-tools
|
# mdbx-tools
|
||||||
foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load)
|
foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load)
|
||||||
add_executable(${TOOL} ${TOOL}.c)
|
add_executable(${TOOL} ${TOOL}.c)
|
||||||
|
set_target_properties(${TOOL} PROPERTIES
|
||||||
|
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||||
set_target_properties(${TOOL} PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
set_target_properties(${TOOL} PROPERTIES
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(${TOOL} mdbx-static)
|
target_link_libraries(${TOOL} mdbx-static)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -272,7 +272,13 @@ else()
|
|||||||
setup_compile_flags()
|
setup_compile_flags()
|
||||||
endif(SUBPROJECT)
|
endif(SUBPROJECT)
|
||||||
|
|
||||||
option(MDBX_ENABLE_TESTS "Build MDBX tests." ${BUILD_TESTING})
|
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
|
||||||
|
if(NOT HAS_C11 LESS 0)
|
||||||
|
set(MDBX_C_STANDARD 11)
|
||||||
|
else()
|
||||||
|
set(MDBX_C_STANDARD 99)
|
||||||
|
endif()
|
||||||
|
message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@ -312,6 +318,7 @@ else()
|
|||||||
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
||||||
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
||||||
endif()
|
endif()
|
||||||
|
option(MDBX_ENABLE_TESTS "Build MDBX tests." ${BUILD_TESTING})
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -35,15 +35,16 @@ list(APPEND LIBMDBX_SOURCES ../mdbx.h
|
|||||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||||
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
||||||
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
||||||
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
|
|
||||||
set_target_properties(mdbx PROPERTIES LINK_FLAGS "-fvisibility=hidden")
|
|
||||||
endif()
|
|
||||||
set(MDBX_LIBDEP_MODE PRIVATE)
|
set(MDBX_LIBDEP_MODE PRIVATE)
|
||||||
else()
|
else()
|
||||||
add_library(mdbx STATIC ${LIBMDBX_SOURCES})
|
add_library(mdbx STATIC ${LIBMDBX_SOURCES})
|
||||||
set(MDBX_LIBDEP_MODE PUBLIC)
|
set(MDBX_LIBDEP_MODE PUBLIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
|
||||||
|
set_target_properties(mdbx PROPERTIES LINK_FLAGS "-fvisibility=hidden")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(NOT MSVC_LIB_EXE)
|
if(NOT MSVC_LIB_EXE)
|
||||||
@ -102,8 +103,7 @@ endif()
|
|||||||
|
|
||||||
set_target_properties(mdbx PROPERTIES
|
set_target_properties(mdbx PROPERTIES
|
||||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
||||||
C_STANDARD 11
|
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||||
C_STANDARD_REQUIRED OFF
|
|
||||||
PUBLIC_HEADER "../mdbx.h")
|
PUBLIC_HEADER "../mdbx.h")
|
||||||
|
|
||||||
if(CC_HAS_FASTMATH)
|
if(CC_HAS_FASTMATH)
|
||||||
|
@ -29,6 +29,7 @@ foreach(TOOL ${MDBX_TOOLS})
|
|||||||
|
|
||||||
target_link_libraries(${TOOL} mdbx ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(${TOOL} mdbx ${CMAKE_THREAD_LIBS_INIT})
|
||||||
set_target_properties(${TOOL} PROPERTIES
|
set_target_properties(${TOOL} PROPERTIES
|
||||||
|
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||||
|
|
||||||
install(TARGETS ${TOOL} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
|
install(TARGETS ${TOOL} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx)
|
||||||
|
@ -34,9 +34,7 @@ add_executable(mdbx_test
|
|||||||
|
|
||||||
set_target_properties(mdbx_test PROPERTIES
|
set_target_properties(mdbx_test PROPERTIES
|
||||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
||||||
CXX_STANDARD 17
|
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||||
CXX_STANDARD_REQUIRED ON
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CC_HAS_FASTMATH)
|
if(CC_HAS_FASTMATH)
|
||||||
target_compile_options(mdbx_test PRIVATE "-ffast-math")
|
target_compile_options(mdbx_test PRIVATE "-ffast-math")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user