Add an option to the CMake build to disable building shared libraries (#6122)

Summary:
Add an option to explicitly disable building shared versions of the
RocksDB libraries.  The shared libraries cannot be built in cases where
some dependencies are only available as static libraries.  This allows
still building RocksDB in these situations.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6122

Differential Revision: D18920740

fbshipit-source-id: d24f66d93c68a1e65635e6e0b663bae62c903bca
main
Adam Simpkins 5 years ago committed by Facebook Github Bot
parent 2b060c1498
commit 2bb5fc1280
  1. 67
      CMakeLists.txt
  2. 2
      db_stress_tool/CMakeLists.txt
  3. 4
      java/CMakeLists.txt
  4. 2
      tools/CMakeLists.txt

@ -766,7 +766,8 @@ endif()
set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX}) set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX})
set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX}) set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX})
set(ROCKSDB_IMPORT_LIB ${ROCKSDB_SHARED_LIB})
option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" ON)
option(WITH_LIBRADOS "Build with librados" OFF) option(WITH_LIBRADOS "Build with librados" OFF)
if(WITH_LIBRADOS) if(WITH_LIBRADOS)
@ -777,38 +778,42 @@ endif()
if(WIN32) if(WIN32)
set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib) set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib)
set(LIBS ${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
else() else()
set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
target_link_libraries(${ROCKSDB_SHARED_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
LINKER_LANGUAGE CXX
VERSION ${rocksdb_VERSION}
SOVERSION ${rocksdb_VERSION_MAJOR}
CXX_STANDARD 11
OUTPUT_NAME "rocksdb")
endif() endif()
add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES}) add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES})
target_link_libraries(${ROCKSDB_STATIC_LIB} target_link_libraries(${ROCKSDB_STATIC_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
if(WIN32) if(ROCKSDB_BUILD_SHARED)
add_library(${ROCKSDB_IMPORT_LIB} SHARED ${SOURCES}) add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
target_link_libraries(${ROCKSDB_IMPORT_LIB} target_link_libraries(${ROCKSDB_SHARED_LIB}
${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
if(WIN32)
set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS") COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS")
if(MSVC) if(MSVC)
set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES
COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb") COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb")
set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb") COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_SHARED_LIB}.pdb")
endif() endif()
else()
set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
LINKER_LANGUAGE CXX
VERSION ${rocksdb_VERSION}
SOVERSION ${rocksdb_VERSION_MAJOR}
CXX_STANDARD 11
OUTPUT_NAME "rocksdb")
endif()
endif()
if(ROCKSDB_BUILD_SHARED AND NOT WIN32)
set(ROCKSDB_LIB ${ROCKSDB_SHARED_LIB})
else()
set(ROCKSDB_LIB ${ROCKSDB_STATIC_LIB})
endif() endif()
option(WITH_JNI "build with JNI" OFF) option(WITH_JNI "build with JNI" OFF)
@ -857,6 +862,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
) )
if(ROCKSDB_BUILD_SHARED)
install( install(
TARGETS ${ROCKSDB_SHARED_LIB} TARGETS ${ROCKSDB_SHARED_LIB}
EXPORT RocksDBTargets EXPORT RocksDBTargets
@ -866,6 +872,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
) )
endif()
install( install(
EXPORT RocksDBTargets EXPORT RocksDBTargets
@ -1052,7 +1059,7 @@ if(WITH_TESTS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX}) set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX})
add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE}) add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})
target_link_libraries(${TESTUTILLIB} ${LIBS}) target_link_libraries(${TESTUTILLIB} ${ROCKSDB_LIB})
if(MSVC) if(MSVC)
set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb") set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb")
endif() endif()
@ -1073,14 +1080,25 @@ if(WITH_TESTS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1 EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
OUTPUT_NAME ${exename}${ARTIFACT_SUFFIX} OUTPUT_NAME ${exename}${ARTIFACT_SUFFIX}
) )
target_link_libraries(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} gtest ${LIBS}) target_link_libraries(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} gtest ${ROCKSDB_LIB})
if(NOT "${exename}" MATCHES "db_sanity_test") if(NOT "${exename}" MATCHES "db_sanity_test")
add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX}) add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
add_dependencies(check ${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX}) add_dependencies(check ${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX})
endif() endif()
endforeach(sourcefile ${TEST_EXES}) endforeach(sourcefile ${TEST_EXES})
if(WIN32)
# C executables must link to a shared object # C executables must link to a shared object
if(ROCKSDB_BUILD_SHARED)
set(ROCKSDB_LIB_FOR_C ${ROCKSDB_SHARED_LIB})
else()
set(ROCKSDB_LIB_FOR_C OFF)
endif()
else()
set(ROCKSDB_LIB_FOR_C ${ROCKSDB_LIB})
endif()
if(ROCKSDB_LIB_FOR_C)
set(C_TESTS db/c_test.c) set(C_TESTS db/c_test.c)
set(C_TEST_EXES ${C_TESTS}) set(C_TEST_EXES ${C_TESTS})
@ -1093,11 +1111,12 @@ if(WITH_TESTS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1 EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1 EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
) )
target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${ROCKSDB_IMPORT_LIB} testutillib${ARTIFACT_SUFFIX}) target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${ROCKSDB_LIB_FOR_C} testutillib${ARTIFACT_SUFFIX})
add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX}) add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
add_dependencies(check ${exename}${ARTIFACT_SUFFIX}) add_dependencies(check ${exename}${ARTIFACT_SUFFIX})
endforeach(sourcefile ${C_TEST_EXES}) endforeach(sourcefile ${C_TEST_EXES})
endif() endif()
endif()
option(WITH_BENCHMARK_TOOLS "build with benchmarks" ON) option(WITH_BENCHMARK_TOOLS "build with benchmarks" ON)
if(WITH_BENCHMARK_TOOLS) if(WITH_BENCHMARK_TOOLS)
@ -1117,14 +1136,14 @@ if(WITH_BENCHMARK_TOOLS)
get_filename_component(exename ${sourcefile} NAME_WE) get_filename_component(exename ${sourcefile} NAME_WE)
add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile} add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}
$<TARGET_OBJECTS:testharness>) $<TARGET_OBJECTS:testharness>)
target_link_libraries(${exename}${ARTIFACT_SUFFIX} gtest ${LIBS}) target_link_libraries(${exename}${ARTIFACT_SUFFIX} gtest ${ROCKSDB_LIB})
endforeach(sourcefile ${BENCHMARKS}) endforeach(sourcefile ${BENCHMARKS})
add_executable(db_bench${ARTIFACT_SUFFIX} add_executable(db_bench${ARTIFACT_SUFFIX}
tools/db_bench.cc tools/db_bench.cc
tools/db_bench_tool.cc tools/db_bench_tool.cc
$<TARGET_OBJECTS:testharness>) $<TARGET_OBJECTS:testharness>)
target_link_libraries(db_bench${ARTIFACT_SUFFIX} gtest ${LIBS}) target_link_libraries(db_bench${ARTIFACT_SUFFIX} gtest ${ROCKSDB_LIB})
endif() endif()
option(WITH_TOOLS "build with tools" ON) option(WITH_TOOLS "build with tools" ON)

@ -10,5 +10,5 @@ add_executable(db_stress${ARTIFACT_SUFFIX}
db_stress_gflags.cc db_stress_gflags.cc
db_stress_tool.cc db_stress_tool.cc
no_batched_ops_stress.cc) no_batched_ops_stress.cc)
target_link_libraries(db_stress${ARTIFACT_SUFFIX} ${LIBS}) target_link_libraries(db_stress${ARTIFACT_SUFFIX} ${ROCKSDB_LIB})
list(APPEND tool_deps db_stress) list(APPEND tool_deps db_stress)

@ -484,13 +484,13 @@ endif()
set(ROCKSDBJNI_STATIC_LIB rocksdbjni${ARTIFACT_SUFFIX}) set(ROCKSDBJNI_STATIC_LIB rocksdbjni${ARTIFACT_SUFFIX})
add_library(${ROCKSDBJNI_STATIC_LIB} ${JNI_NATIVE_SOURCES}) add_library(${ROCKSDBJNI_STATIC_LIB} ${JNI_NATIVE_SOURCES})
add_dependencies(${ROCKSDBJNI_STATIC_LIB} rocksdbjni_headers) add_dependencies(${ROCKSDBJNI_STATIC_LIB} rocksdbjni_headers)
target_link_libraries(${ROCKSDBJNI_STATIC_LIB} ${ROCKSDB_STATIC_LIB} ${LIBS}) target_link_libraries(${ROCKSDBJNI_STATIC_LIB} ${ROCKSDB_STATIC_LIB} ${ROCKSDB_LIB})
if(NOT MINGW) if(NOT MINGW)
set(ROCKSDBJNI_SHARED_LIB rocksdbjni-shared${ARTIFACT_SUFFIX}) set(ROCKSDBJNI_SHARED_LIB rocksdbjni-shared${ARTIFACT_SUFFIX})
add_library(${ROCKSDBJNI_SHARED_LIB} SHARED ${JNI_NATIVE_SOURCES}) add_library(${ROCKSDBJNI_SHARED_LIB} SHARED ${JNI_NATIVE_SOURCES})
add_dependencies(${ROCKSDBJNI_SHARED_LIB} rocksdbjni_headers) add_dependencies(${ROCKSDBJNI_SHARED_LIB} rocksdbjni_headers)
target_link_libraries(${ROCKSDBJNI_SHARED_LIB} ${ROCKSDB_STATIC_LIB} ${LIBS}) target_link_libraries(${ROCKSDBJNI_SHARED_LIB} ${ROCKSDB_STATIC_LIB} ${ROCKSDB_LIB})
set_target_properties( set_target_properties(
${ROCKSDBJNI_SHARED_LIB} ${ROCKSDBJNI_SHARED_LIB}

@ -10,7 +10,7 @@ foreach(src ${TOOLS})
get_filename_component(exename ${src} NAME_WE) get_filename_component(exename ${src} NAME_WE)
add_executable(${exename}${ARTIFACT_SUFFIX} add_executable(${exename}${ARTIFACT_SUFFIX}
${src}) ${src})
target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${LIBS}) target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${ROCKSDB_LIB})
list(APPEND tool_deps ${exename}) list(APPEND tool_deps ${exename})
endforeach() endforeach()

Loading…
Cancel
Save