From 95f4c2bcb52514d5fb858f797af5c1e0ba92cf40 Mon Sep 17 00:00:00 2001 From: Alexander Zinoviev Date: Tue, 7 Jul 2015 16:49:47 -0700 Subject: [PATCH] Conditional use of 3rd-party libraries --- CMakeLists.txt | 40 +++++++++++----------------------------- thirdparty.inc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fbf1cef1..679ac1372 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # This cmake build is for Windows only. # # Prerequisites: -# You must have Visual Studio 2013 installed. Start the Developer Command Prompt window that is a part of Visual Studio installation. +# You must have Visual Studio 2013 Update 4 installed. Start the Developer Command Prompt window that is a part of Visual Studio installation. # Run the build commands from within the Developer Command Prompt window to have paths to the compiler and runtime libraries set. # # To build Rocksdb for Windows is as easy as 1-2-3-4-5: @@ -43,10 +43,6 @@ add_custom_command(OUTPUT ${BUILD_VERSION_CC} add_custom_target(GenerateBuildVersion DEPENDS ${BUILD_VERSION_CC}) -add_definitions(${GFLAGS_CXX_FLAGS} ${SNAPPY_CXX_FLAGS}) -include_directories(${GFLAGS_INCLUDE} ${SNAPPY_INCLUDE} ${JEMALLOC_INCLUDE}) -set (THIRDPARTY_LIBS ${GFLAGS_LIBS} ${SNAPPY_LIBS} ${JEMALLOC_LIBS}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /W3 /WX /EHsc /GS /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /errorReport:queue") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /wd4018 /wd4100 /wd4101 /wd4127 /wd4189 /wd4200 /wd4244 /wd4267 /wd4296 /wd4305 /wd4307 /wd4309 /wd4512 /wd4701 /wd4702 /wd4800 /wd4804 /wd4996") @@ -62,13 +58,11 @@ include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_SOURCE_DIR}/port) include_directories(${PROJECT_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src) -set(ROCKSDB_LIBS rocksdblib) -set(ROCKSDB_LIBS_JE rocksdblib_je) +set(ROCKSDB_LIBS rocksdblib${ARTIFACT_SUFFIX}) set(THIRDPARTY_LIBS ${THIRDPARTY_LIBS} gtest) set(SYSTEM_LIBS Shlwapi.lib Rpcrt4.lib) set(LIBS ${ROCKSDB_LIBS} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) -set(LIBS_JE ${ROCKSDB_LIBS_JE} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) add_subdirectory(third-party/gtest-1.7.0/fused-src/gtest) @@ -225,23 +219,14 @@ set(SOURCES utilities/write_batch_with_index/write_batch_with_index_internal.cc ) -add_library(rocksdblib ${SOURCES}) -set_target_properties(rocksdblib PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/rocksdblib.pdb") -add_dependencies(rocksdblib GenerateBuildVersion) - -add_library(rocksdblib_je ${SOURCES}) -set_target_properties(rocksdblib_je PROPERTIES COMPILE_FLAGS "${JEMALLOC_CXX_FLAGS} /Fd${CMAKE_CFG_INTDIR}/rocksdblib_je.pdb") -add_dependencies(rocksdblib_je GenerateBuildVersion) - -add_library(rocksdb SHARED ${SOURCES}) -set_target_properties(rocksdb PROPERTIES COMPILE_FLAGS "-DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/rocksdb.pdb") -add_dependencies(rocksdb GenerateBuildVersion) -target_link_libraries(rocksdb ${LIBS}) +add_library(rocksdblib${ARTIFACT_SUFFIX} ${SOURCES}) +set_target_properties(rocksdblib${ARTIFACT_SUFFIX} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/rocksdblib${ARTIFACT_SUFFIX}.pdb") +add_dependencies(rocksdblib${ARTIFACT_SUFFIX} GenerateBuildVersion) -add_library(rocksdb_je SHARED ${SOURCES}) -set_target_properties(rocksdb_je PROPERTIES COMPILE_FLAGS "${JEMALLOC_CXX_FLAGS} -DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/rocksdb_je.pdb") -add_dependencies(rocksdb_je GenerateBuildVersion) -target_link_libraries(rocksdb_je ${LIBS_JE}) +add_library(rocksdb${ARTIFACT_SUFFIX} SHARED ${SOURCES}) +set_target_properties(rocksdb${ARTIFACT_SUFFIX} PROPERTIES COMPILE_FLAGS "-DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/rocksdb${ARTIFACT_SUFFIX}.pdb") +add_dependencies(rocksdb${ARTIFACT_SUFFIX} GenerateBuildVersion) +target_link_libraries(rocksdb${ARTIFACT_SUFFIX} ${LIBS}) set(APPS db/db_bench.cc @@ -339,9 +324,6 @@ foreach(sourcefile ${EXES}) string(REPLACE ".cc" "" exename ${sourcefile}) string(REPLACE ".c" "" exename ${exename}) string(REGEX REPLACE "^((.+)/)+" "" exename ${exename}) - add_executable(${exename} ${sourcefile}) - target_link_libraries(${exename} ${LIBS}) - add_executable(${exename}_je ${sourcefile}) - set_target_properties(${exename}_je PROPERTIES COMPILE_FLAGS ${JEMALLOC_CXX_FLAGS}) - target_link_libraries(${exename}_je ${LIBS_JE}) + add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}) + target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${LIBS}) endforeach(sourcefile ${EXES}) diff --git a/thirdparty.inc b/thirdparty.inc index 73a4c2643..dd43e0c5f 100644 --- a/thirdparty.inc +++ b/thirdparty.inc @@ -3,6 +3,11 @@ # This example assumes all the libraries locate in the same directory tree under THIRDPARTY_HOME environment variable # Set environment variable THIRDPARTY_HOME to point to your third party libraries home (Unix style dir separators) +# Edit these lines to enable/disable external libraries use +set(USE_GFLAGS 1) +set(USE_SNAPPY 1) +set(USE_JEMALLOC 1) + # # Edit these 4 lines to define paths to GFLAGS # @@ -38,3 +43,28 @@ set(JEMALLOC_LIB_RELEASE ${JEMALLOC_HOME}/bin/retail/amd64/jemalloc.lib) # Don't touch these lines set(JEMALLOC_CXX_FLAGS -DJEMALLOC) set(JEMALLOC_LIBS debug ${JEMALLOC_LIB_DEBUG} optimized ${JEMALLOC_LIB_RELEASE}) + + +# Aggregate all third-party dependencies + +set (THIRDPARTY_LIBS "") +set (ARTIFACT_SUFFIX "") + +if (${USE_GFLAGS} EQUAL 1) +set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} ${GFLAGS_LIBS}) +add_definitions(${GFLAGS_CXX_FLAGS}) +include_directories(${GFLAGS_INCLUDE}) +endif (${USE_GFLAGS} EQUAL 1) + +if (${USE_SNAPPY} EQUAL 1) +set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} ${SNAPPY_LIBS}) +add_definitions(${SNAPPY_CXX_FLAGS}) +include_directories(${SNAPPY_INCLUDE}) +endif (${USE_SNAPPY} EQUAL 1) + +if (${USE_JEMALLOC} EQUAL 1) +set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} ${JEMALLOC_LIBS}) +add_definitions(${JEMALLOC_CXX_FLAGS}) +include_directories(${JEMALLOC_INCLUDE}) +set (ARTIFACT_SUFFIX "_je") +endif (${USE_JEMALLOC} EQUAL 1) -- GitLab