mdbx-cmake: provide MDBX_BUILD_SHARED_LIBRARY option for dist-cmake.

Change-Id: Ic8ef72ff70c24f844c9275788f9ba847ffef36eb
This commit is contained in:
Leonid Yuriev 2019-09-19 03:31:33 +03:00
parent ab456bf376
commit 90a3ed992e

View File

@ -61,6 +61,8 @@ else()
project(libmdbx C CXX) project(libmdbx C CXX)
endif() endif()
find_package(Threads REQUIRED)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
@ -123,22 +125,29 @@ list(REMOVE_DUPLICATES MDBX_BUILD_FLAGS)
string(REPLACE ";" "" MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}") string(REPLACE ";" "" MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
add_definitions(-DMDBX_BUILD_FLAGS="${MDBX_BUILD_FLAGS}") add_definitions(-DMDBX_BUILD_FLAGS="${MDBX_BUILD_FLAGS}")
# add targets both for shared and static libraries # shared library
# static library used for tools, to avoid rpath/dll-path troubles if(DEFINED BUILD_SHARED_LIBS)
add_library(mdbx SHARED mdbx.c mdbx.h) option(MDBX_BUILD_SHARED_LIBRARY "Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS})
add_library(mdbx-static STATIC EXCLUDE_FROM_ALL mdbx.c mdbx.h) else()
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS) option(MDBX_BUILD_SHARED_LIBRARY "Build libmdbx as shared library (DLL)" ON)
endif()
if(MDBX_BUILD_SHARED_LIBRARY)
add_library(mdbx SHARED mdbx.c mdbx.h)
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
target_link_libraries(mdbx PRIVATE ${CMAKE_THREAD_LIBS_INIT})
if(WIN32)
target_link_libraries(mdbx PRIVATE ntdll.lib)
endif()
endif()
# link libraries # static library used for tools, to avoid rpath/dll-path troubles
find_package(Threads REQUIRED) add_library(mdbx-static STATIC EXCLUDE_FROM_ALL mdbx.c mdbx.h)
target_link_libraries(mdbx PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(mdbx-static INTERFACE ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(mdbx-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
if(WIN32) if(WIN32)
target_link_libraries(mdbx PRIVATE ntdll.lib)
target_link_libraries(mdbx-static INTERFACE ntdll.lib) target_link_libraries(mdbx-static INTERFACE ntdll.lib)
endif() endif()
# add target for 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)
target_link_libraries(${TOOL} mdbx-static) target_link_libraries(${TOOL} mdbx-static)