You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/05/10 11:36:49 UTC

[GitHub] [incubator-kvrocks] PragmaTwice commented on a diff in pull request #564: Use FetchContent instead of ExternalProject and git submodules in CMake

PragmaTwice commented on code in PR #564:
URL: https://github.com/apache/incubator-kvrocks/pull/564#discussion_r869130333


##########
cmake/rocksdb.cmake:
##########
@@ -15,67 +15,34 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if (NOT __ROCKSDB_INCLUDED)
-  set(__ROCKSDB_INCLUDED TRUE)
+include_guard()
 
-  find_package(Threads)
-  set(CMAKE_INSTALL_LIBDIR lib)
-  # build directory
-  set(rocksdb_PREFIX ${CMAKE_BUILD_DIRECTORY}/external/rocksdb-prefix)
-  # install directory
-  set(rocksdb_INSTALL ${CMAKE_BUILD_DIRECTORY}/external/rocksdb-install)
-  set(COMPILE_WITH_JEMALLOC ON)
+set(COMPILE_WITH_JEMALLOC ON)
 
-  if (UNIX)
-      set(ROCKSDB_EXTRA_COMPILER_FLAGS "-fPIC")
-  endif()
+if (DISABLE_JEMALLOC)
+  set(COMPILE_WITH_JEMALLOC OFF)
+endif()
 
-  set(ROCKSDB_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROCKSDB_EXTRA_COMPILER_FLAGS}")
-  set(ROCKSDB_C_FLAGS "${CMAKE_C_FLAGS} ${ROCKSDB_EXTRA_COMPILER_FLAGS}")
-  if (NOT DISABLE_JEMALLOC)
-    list(APPEND rocksdb_DEPENDS jemalloc)
-    list(APPEND rocksdb_DEPENDS snappy)
-    set(JEMALLOC_ROOT_DIR ${jemalloc_INSTALL})
-  else()
-    set(rocksdb_DEPENDS "snappy")
-    set(COMPILE_WITH_JEMALLOC OFF)
-  endif()
-  ExternalProject_Add(rocksdb
-      DEPENDS ${rocksdb_DEPENDS}
-      PREFIX ${rocksdb_PREFIX}
-      #GIT_REPOSITORY "https://github.com/facebook/rocksdb"
-      #GIT_TAG "v5.15.10"
-      SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/rocksdb
-      INSTALL_DIR ${rocksdb_INSTALL}
-      CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-		 -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-                 -DCMAKE_INSTALL_PREFIX=${rocksdb_INSTALL}
-                 -DBUILD_SHARED_LIBS=OFF
-                 -DBUILD_STATIC_LIBS=ON
-                 -DBUILD_PACKAGING=OFF
-                 -DBUILD_TESTING=OFF
-                 -DBUILD_NC_TESTS=OFF
-                 -DBUILD_CONFIG_TESTS=OFF
-                 -DINSTALL_HEADERS=ON
-                 -DCMAKE_C_FLAGS=${ROCKSDB_C_FLAGS}
-                 -DCMAKE_CXX_FLAGS=${ROCKSDB_CXX_FLAGS}
-                 -DCMAKE_PREFIX_PATH=${snappy_INSTALL}
-                 -DJEMALLOC_ROOT_DIR=${JEMALLOC_ROOT_DIR}
-                 -DFAIL_ON_WARNINGS=OFF
-                 -DWITH_TESTS=OFF
-                 -DWITH_SNAPPY=ON
-                 -DWITH_TOOLS=OFF
-                 -DWITH_GFLAGS=OFF
-                 -DUSE_RTTI=ON
-                 -DWITH_JEMALLOC=${COMPILE_WITH_JEMALLOC}
-      LOG_DOWNLOAD 1
-      LOG_CONFIGURE 1
-      LOG_INSTALL 1
-      )
+include(FetchContent)
 
-  include(GNUInstallDirs)
-  set(rocksdb_FOUND TRUE)
-  set(rocksdb_INCLUDE_DIRS ${rocksdb_INSTALL}/include)
-  set(rocksdb_LIBRARIES ${rocksdb_INSTALL}/${CMAKE_INSTALL_LIBDIR}/librocksdb.a)
-endif()
+FetchContent_Declare(rocksdb
+  GIT_REPOSITORY https://github.com/facebook/rocksdb
+  GIT_TAG v6.29.5
+)
+
+include(cmake/utils.cmake)
+
+FetchContent_MakeAvailableWithArgs(rocksdb

Review Comment:
   `FetchContent` commands will be executed on configuration stage, not the build stage, so there is no `DEPENDS` parameter (and the FetchContent declared names are not cmake targets actually, so no `add_dependencies`). The execution order plays the role of `DEPENDS`, you can check [here](https://cmake.org/cmake/help/latest/module/FetchContent.html#id5) to find details.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org