2019-09-09 13:40:24 +03:00
|
|
|
##
|
2019-08-31 17:13:02 +03:00
|
|
|
## Copyright 2019 Leonid Yuriev <leo@yuriev.ru>
|
|
|
|
## and other libmdbx authors: please see AUTHORS file.
|
|
|
|
## All rights reserved.
|
|
|
|
##
|
|
|
|
## Redistribution and use in source and binary forms, with or without
|
|
|
|
## modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
## Public License.
|
|
|
|
##
|
|
|
|
## A copy of this license is available in the file LICENSE in the
|
|
|
|
## top-level directory of the distribution or, alternatively, at
|
|
|
|
## <http://www.OpenLDAP.org/license.html>.
|
|
|
|
##
|
|
|
|
|
|
|
|
# Get version
|
2019-09-05 11:57:52 +03:00
|
|
|
fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}/../VERSION")
|
|
|
|
message(STATUS "libmdbx version is ${MDBX_VERSION}")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2019-09-01 17:40:00 +03:00
|
|
|
if(MDBX_ALLOY_MODE)
|
|
|
|
set(LIBMDBX_SOURCES alloy.c)
|
|
|
|
else()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
|
|
set(LIBMDBX_OSAL windows)
|
|
|
|
else()
|
|
|
|
set(LIBMDBX_OSAL posix)
|
|
|
|
endif()
|
|
|
|
set(LIBMDBX_SOURCES
|
|
|
|
elements/defs.h elements/internals.h elements/osal.h
|
|
|
|
elements/core.c elements/osal.c elements/lck-${LIBMDBX_OSAL}.c)
|
|
|
|
endif()
|
2019-09-03 02:24:19 +03:00
|
|
|
list(APPEND LIBMDBX_SOURCES ../mdbx.h
|
2019-09-05 11:57:52 +03:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h")
|
2019-09-01 17:40:00 +03:00
|
|
|
|
2019-09-05 11:57:52 +03:00
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
2019-09-03 02:24:19 +03:00
|
|
|
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
|
|
|
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()
|
2019-09-03 19:15:22 +03:00
|
|
|
set(MDBX_LIBDEP_MODE PRIVATE)
|
2019-09-03 02:24:19 +03:00
|
|
|
else()
|
|
|
|
add_library(mdbx STATIC ${LIBMDBX_SOURCES})
|
2019-09-03 19:15:22 +03:00
|
|
|
set(MDBX_LIBDEP_MODE PUBLIC)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
|
|
if(MSVC)
|
|
|
|
if(NOT MSVC_LIB_EXE)
|
|
|
|
# Find lib.exe
|
2019-09-05 11:57:52 +03:00
|
|
|
get_filename_component(CL_NAME ${CMAKE_C_COMPILER} NAME)
|
|
|
|
string(REPLACE cl.exe lib.exe MSVC_LIB_EXE ${CL_NAME})
|
2019-09-03 19:15:22 +03:00
|
|
|
find_program(MSVC_LIB_EXE ${MSVC_LIB_EXE})
|
|
|
|
endif()
|
|
|
|
if(MSVC_LIB_EXE)
|
2019-09-05 11:57:52 +03:00
|
|
|
message(STATUS "Found MSVC's lib tool: ${MSVC_LIB_EXE}")
|
2019-09-03 19:15:22 +03:00
|
|
|
set(MDBX_NTDLL_EXTRA_IMPLIB ${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib)
|
|
|
|
add_custom_command(OUTPUT ${MDBX_NTDLL_EXTRA_IMPLIB}
|
|
|
|
COMMENT "Create extra-import-library for ntdll.dll"
|
|
|
|
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def"
|
|
|
|
COMMAND ${MSVC_LIB_EXE} /def:"${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def" /out:"${MDBX_NTDLL_EXTRA_IMPLIB}" ${INITIAL_CMAKE_STATIC_LINKER_FLAGS})
|
|
|
|
else()
|
2019-09-05 11:57:52 +03:00
|
|
|
message(SEND_ERROR "MSVC's lib tool not found")
|
2019-09-03 19:15:22 +03:00
|
|
|
endif()
|
|
|
|
elseif(MINGW OR MINGW64)
|
|
|
|
if(NOT DLLTOOL)
|
|
|
|
# Find dlltool
|
2019-09-05 11:57:52 +03:00
|
|
|
get_filename_component(GCC_NAME ${CMAKE_C_COMPILER} NAME)
|
|
|
|
string(REPLACE gcc dlltool DLLTOOL_NAME ${GCC_NAME})
|
|
|
|
find_program(DLLTOOL NAMES ${DLLTOOL_NAME})
|
2019-09-03 19:15:22 +03:00
|
|
|
endif()
|
|
|
|
if(DLLTOOL)
|
2019-09-05 11:57:52 +03:00
|
|
|
message(STATUS "Found dlltool: ${DLLTOOL}")
|
2019-09-03 19:15:22 +03:00
|
|
|
set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
|
|
|
|
add_custom_command(OUTPUT ${MDBX_NTDLL_EXTRA_IMPLIB}
|
|
|
|
COMMENT "Create extra-import-library for ntdll.dll"
|
|
|
|
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def"
|
|
|
|
COMMAND ${DLLTOOL} -d "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def" -l "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
|
|
|
else()
|
2019-09-05 11:57:52 +03:00
|
|
|
message(SEND_ERROR "dlltool not found")
|
2019-09-03 19:15:22 +03:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|
|
|
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ntdll.lib)
|
|
|
|
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
|
|
|
# LY: Sometimes Cmake requires a nightmarish magic for simple things.
|
|
|
|
# 1) create a target out of the library compilation result
|
|
|
|
add_custom_target(ntdll_extra_target DEPENDS ${MDBX_NTDLL_EXTRA_IMPLIB})
|
|
|
|
# 2) create an library target out of the library compilation result
|
|
|
|
add_library(ntdll_extra STATIC IMPORTED GLOBAL)
|
|
|
|
add_dependencies(ntdll_extra ntdll_extra_target)
|
|
|
|
# 3) specify where the library is (and where to find the headers)
|
|
|
|
set_target_properties(ntdll_extra
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_LOCATION ${MDBX_NTDLL_EXTRA_IMPLIB})
|
|
|
|
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ntdll_extra)
|
|
|
|
endif()
|
2019-09-03 02:24:19 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set_target_properties(mdbx PROPERTIES
|
2019-08-31 17:13:02 +03:00
|
|
|
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
|
|
|
C_STANDARD 11
|
|
|
|
C_STANDARD_REQUIRED OFF
|
2019-09-03 02:24:19 +03:00
|
|
|
PUBLIC_HEADER "../mdbx.h")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
|
|
if(CC_HAS_FASTMATH)
|
2019-09-03 02:24:19 +03:00
|
|
|
target_compile_options(mdbx PRIVATE "-ffast-math")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
if(BUILD_FOR_NATIVE_CPU AND CC_HAS_ARCH_NATIVE)
|
2019-09-03 02:24:19 +03:00
|
|
|
target_compile_options(mdbx PUBLIC "-march=native")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
if(CC_HAS_VISIBILITY)
|
2019-09-03 02:24:19 +03:00
|
|
|
target_compile_options(mdbx PRIVATE "-fvisibility=hidden")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
install(TARGETS mdbx
|
|
|
|
LIBRARY DESTINATION lib COMPONENT runtime
|
|
|
|
RUNTIME DESTINATION bin COMPONENT runtime
|
|
|
|
ARCHIVE DESTINATION lib/static COMPONENT devel
|
2019-09-10 20:00:54 +03:00
|
|
|
PUBLIC_HEADER DESTINATION include
|
2019-09-03 02:24:19 +03:00
|
|
|
INCLUDES DESTINATION include COMPONENT devel)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# library build info (used in library version output)
|
|
|
|
#
|
|
|
|
|
|
|
|
# get definitions as a string of "-Dxyz=124 ..."
|
2019-09-03 02:24:19 +03:00
|
|
|
get_target_property(MDBX_DEFINITIONS mdbx COMPILE_DEFINITIONS)
|
2019-08-31 17:13:02 +03:00
|
|
|
if(NOT MDBX_DEFINITIONS)
|
|
|
|
set(MDBX_DEFINITIONS "")
|
|
|
|
endif()
|
|
|
|
list(REMOVE_DUPLICATES MDBX_DEFINITIONS)
|
|
|
|
string(REGEX REPLACE "([^;]+)" " -D\\1" MDBX_DEFINITIONS "${MDBX_DEFINITIONS}")
|
|
|
|
string(STRIP MDBX_DEFINITIONS "${MDBX_DEFINITIONS}")
|
|
|
|
|
|
|
|
# get target compile options as a list
|
2019-09-03 02:24:19 +03:00
|
|
|
get_target_property(mdbx_compile_options mdbx COMPILE_OPTIONS)
|
2019-08-31 17:13:02 +03:00
|
|
|
if(NOT mdbx_compile_options)
|
|
|
|
set(mdbx_compile_options "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# append cmake's common cxx flags and defines
|
|
|
|
string(REPLACE " " ";" cmake_cxx_options "${CMAKE_C_FLAGS}" "${CMAKE_C_DEFINES}")
|
|
|
|
list(INSERT mdbx_compile_options 0 "${cmake_c_options}")
|
|
|
|
unset(cmake_c_options)
|
|
|
|
|
|
|
|
# append cmake's build-type flags and defines
|
|
|
|
if(NOT CMAKE_CONFIGURATION_TYPES)
|
2019-09-03 02:24:19 +03:00
|
|
|
string(REPLACE " " ";" cmake_cxx_options
|
|
|
|
"${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}"
|
|
|
|
"${CMAKE_C_DEFINES_${CMAKE_BUILD_TYPE_UPPERCASE}}")
|
2019-08-31 17:13:02 +03:00
|
|
|
list(APPEND mdbx_compile_options "${cmake_c_options}")
|
|
|
|
unset(cmake_c_options)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# append linker dll's options
|
|
|
|
if(LIBMDBX_TYPE STREQUAL "SHARED")
|
|
|
|
string(REPLACE " " ";" cmake_shared_linker_options "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
|
|
list(APPEND mdbx_compile_options ${cmake_shared_linker_options})
|
|
|
|
unset(cmake_shared_linker_options)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# drop duplicates in the option list
|
|
|
|
list(REMOVE_DUPLICATES mdbx_compile_options)
|
|
|
|
|
|
|
|
# make string of space separated flags
|
2019-09-05 11:57:52 +03:00
|
|
|
string(REPLACE ";" " " MDBX_BUILD_FLAGS "${mdbx_compile_options}")
|
2019-08-31 17:13:02 +03:00
|
|
|
unset(mdbx_compile_options)
|
2019-09-05 11:57:52 +03:00
|
|
|
string(STRIP "${MDBX_BUILD_FLAGS}${MDBX_DEFINITIONS}" MDBX_BUILD_FLAGS)
|
2019-08-31 17:13:02 +03:00
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
# add dynamic part via per-configuration define
|
2019-09-05 11:57:52 +03:00
|
|
|
message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS} <AND CONFIGURATION DEPENDENT>")
|
|
|
|
set(MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
|
2019-08-31 17:13:02 +03:00
|
|
|
add_definitions(
|
|
|
|
-DMDBX_COMPILE_FLAGS="$<$<CONFIG:Debug>:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$<CONFIG:Release>:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$<CONFIG:RelWithDebInfo>:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$<CONFIG:MinSizeRel>:${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_DEFINES_MINSIZEREL}>"
|
|
|
|
)
|
|
|
|
else()
|
2019-09-05 11:57:52 +03:00
|
|
|
message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS}")
|
|
|
|
set(MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
|
2019-09-03 02:24:19 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# get compiler info
|
|
|
|
execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1"
|
|
|
|
OUTPUT_VARIABLE MDBX_BUILD_COMPILER
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET
|
|
|
|
RESULT_VARIABLE rc)
|
|
|
|
if(rc OR NOT MDBX_BUILD_COMPILER)
|
2019-09-05 11:57:52 +03:00
|
|
|
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" MDBX_BUILD_COMPILER)
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# make a build-target triplet
|
2019-09-03 19:13:26 +03:00
|
|
|
if(CMAKE_C_COMPILER_TARGET)
|
|
|
|
set(MDBX_BUILD_TARGET "${CMAKE_C_COMPILER_TARGET}")
|
|
|
|
elseif(CMAKE_C_PLATFORM_ID AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
|
|
|
string(STRIP "${CMAKE_C_PLATFORM_ID}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_LIBRARY_ARCHITECTURE)
|
|
|
|
string(STRIP "${CMAKE_LIBRARY_ARCHITECTURE}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
|
|
|
string(STRIP "${CMAKE_GENERATOR_PLATFORM}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_SYSTEM_ARCH)
|
|
|
|
string(STRIP "${CMAKE_SYSTEM_ARCH}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
|
|
|
else()
|
|
|
|
string(STRIP "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
2019-09-03 19:13:26 +03:00
|
|
|
add_definitions(-DMDBX_BUILD_CONFIG="$<CONFIG>")
|
2019-08-31 17:13:02 +03:00
|
|
|
else()
|
2019-09-03 19:13:26 +03:00
|
|
|
add_definitions(-DMDBX_BUILD_CONFIG="${CMAKE_BUILD_TYPE}")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
2019-09-03 02:24:19 +03:00
|
|
|
# options
|
2019-08-31 17:13:02 +03:00
|
|
|
string(TIMESTAMP MDBX_BUILD_TIMESTAMP UTC)
|
2019-09-05 11:57:52 +03:00
|
|
|
set(MDBX_BUILD_OPTIONS_STRING -DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
|
2019-09-03 02:24:19 +03:00
|
|
|
foreach(item IN LISTS MDBX_BUILD_OPTIONS)
|
|
|
|
if(DEFINED ${item} AND NOT "${${item}}" STREQUAL "AUTO")
|
2019-09-05 11:57:52 +03:00
|
|
|
string(APPEND MDBX_BUILD_OPTIONS_STRING " -D${item}=${${item}}")
|
2019-09-03 02:24:19 +03:00
|
|
|
message(STATUS "${item}: ${${item}}")
|
|
|
|
else()
|
|
|
|
unset(${item} CACHE)
|
|
|
|
set(${item}_AUTO ON)
|
2019-09-05 11:57:52 +03:00
|
|
|
string(APPEND MDBX_BUILD_OPTIONS_STRING " -D${item}=AUTO")
|
2019-09-03 02:24:19 +03:00
|
|
|
message(STATUS "${item}: AUTO")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(options VERSION C_COMPILER CXX_COMPILER DEFINITIONS)
|
|
|
|
foreach(item IN LISTS options)
|
|
|
|
if(DEFINED ${item})
|
|
|
|
set(value "${${item}}")
|
|
|
|
elseif(DEFINED MDBX_${item})
|
|
|
|
set(item MDBX_${item})
|
|
|
|
set(value "${${item}}")
|
|
|
|
elseif(DEFINED CMAKE_${item})
|
|
|
|
set(item CMAKE_${item})
|
|
|
|
set(value "${${item}}")
|
2019-08-31 17:13:02 +03:00
|
|
|
else()
|
2019-09-03 02:24:19 +03:00
|
|
|
set(value "undefined")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
2019-09-03 02:24:19 +03:00
|
|
|
message(STATUS "${item}: ${value}")
|
|
|
|
endforeach(item)
|
|
|
|
|
2019-09-05 11:57:52 +03:00
|
|
|
# generate version and config files
|
2019-09-03 02:24:19 +03:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c.in"
|
2019-09-05 11:57:52 +03:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c" ESCAPE_QUOTES)
|
|
|
|
|
|
|
|
file(SHA256 "${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c" MDBX_SOURCERY_DIGEST)
|
|
|
|
string(MAKE_C_IDENTIFIER "${MDBX_GIT_DESCRIBE}" MDBX_SOURCERY_SUFFIX)
|
|
|
|
set(MDBX_BUILD_SOURCERY "${MDBX_SOURCERY_DIGEST}_${MDBX_SOURCERY_SUFFIX}")
|
2019-09-03 02:24:19 +03:00
|
|
|
|
2019-09-05 11:57:52 +03:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h.in"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h" ESCAPE_QUOTES)
|
2019-09-10 14:32:17 +03:00
|
|
|
add_definitions(-DMDBX_CONFIG_H="config.h")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
|
|
add_subdirectory(tools)
|