Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: cmake related cleanups #5662

Closed
wants to merge 4 commits into from
Closed

Conversation

tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Aug 1, 2019

  • cmake: use the builtin FindBzip2.cmake from CMake
  • cmake: require CMake v3.5.1
  • cmake: add imported target for 3rd party libraries
  • cmake: extract ReadVersion.cmake out and refactor it

@maysamyabandeh
Copy link
Contributor

@hliu18 @burtonli Would appreciate it if you could verify the suggested changes.

@hliu18
Copy link
Contributor

hliu18 commented Aug 1, 2019

Looks fine to me.

CMakeLists.txt Outdated
enable_language(ASM)
cmake_minimum_required(VERSION 3.5.1)
project(rocksdb
VERSION 6.2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to get version from version.h?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to not duplicate in two places. Is "VERSION 6.2.0" needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. i extracted ReadVersion.cmake out, and use it instead.

# LZ4_INCLUDE_DIR - where to find lz4.h, etc.
# LZ4_LIBRARIES - List of libraries when using lz4.
# LZ4_FOUND - True if lz4 found.
# lz4_INCLUDE_DIR - where to find lz4.h, etc.
Copy link
Contributor

@burtonli burtonli Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lz4_INCLUDE_DIRS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. fixed.

CMakeLists.txt Outdated
add_definitions(-DBZIP2)
include_directories(${BZIP2_INCLUDE_DIR})
include_directories(${BZIP2_INCLUDE_DIRS})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also update Findbzip2.cmake accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findbzip2.cmake is removed in the same commit. please refer the commit message for more details.

FindBzip2.cmake has been shipped along with CMake since v2.6.0,
so let's just use it instead of the homebrew one.

please note, in CMake 3.5.1, FindBzip2.cmake exposed
`BZIP2_INCLUDE_DIR`, see
https://github.com/Kitware/CMake/blob/v3.5.1/Modules/FindBZip2.cmake.

while since CMake 3.12.1, FindBzip2.cmake exposes
both Bzip2::Bzip2 and `BZIP2_INCLUDE_DIRS`, see
https://github.com/Kitware/CMake/blob/v3.12.1/Modules/FindBZip2.cmake

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
* require 3.5.1
* use project(... LANGUAGES ..) to silence warnings
  regarding to CMP0048
* use imported target of ZLIB::ZLIB, as it's available since 3.5.1

cmake 3.5.1 is offered by ubuntu xenial, and cmake3.13 is offered by
EPEL7. so it should be safe to bump the required cmake version.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@tchaikov
Copy link
Contributor Author

tchaikov commented Aug 2, 2019

changelog

  • s/lz4_INCLUDE_DIR/lz4_INCLUDE_DIRS/
  • add imported target for more Find*.cmake. and use it for VERSION in project() command
  • extract ReadVersion.cmake out

* so it would be simpler to import these libraries
* lower case the {lz4,snappy,zstd}_* variables to follow the
  convention of CMake that Find<name>.cmake should expose
  names of <name>_*. instead of <NAME>_*.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
for couple reasons

* modularize the cmake file, to extract the subroutines into their
  own modules. this approach also avoid pollution the global
  namespace with the local variables.
* use `<PROJECT_NAME>_VERSION_*` instead of `ROCKSDB_VERSION_*` to
  follow CMake conventions. please note, the project name of rocksdb
  in this CMakefile script is "rocksdb" instead of "ROCKSDB".
* refactor the code to read the version number using a loop, let
  repeating this way.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@maysamyabandeh
Copy link
Contributor

@tchaikov could you please update the PR description with a summary of the changes.

@maysamyabandeh
Copy link
Contributor

@burtonli @yiwu-arbug Thanks for the review. In the PR good for landing?

@tchaikov
Copy link
Contributor Author

tchaikov commented Aug 5, 2019

@maysamyabandeh sure. updated.

@burtonli
Copy link
Contributor

burtonli commented Aug 5, 2019

LGTM

1 similar comment
@yiwu-arbug
Copy link
Contributor

LGTM

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@tchaikov tchaikov deleted the wip-cmake branch August 6, 2019 02:59
@facebook-github-bot
Copy link
Contributor

@maysamyabandeh merged this pull request in cc9fa7f.

tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 10, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Signed-off-by: Kefu Chai <kchai@redhat.com>
tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 11, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Signed-off-by: Kefu Chai <kchai@redhat.com>
tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 17, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Fixes: https://tracker.ceph.com/issues/41253
Signed-off-by: Kefu Chai <kchai@redhat.com>
tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 17, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Fixes: https://tracker.ceph.com/issues/41253
Signed-off-by: Kefu Chai <kchai@redhat.com>
tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 17, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Fixes: https://tracker.ceph.com/issues/41253
Signed-off-by: Kefu Chai <kchai@redhat.com>
tchaikov added a commit to tchaikov/ceph that referenced this pull request Aug 17, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Fixes: https://tracker.ceph.com/issues/41253
Signed-off-by: Kefu Chai <kchai@redhat.com>
smithfarm pushed a commit to smithfarm/ceph that referenced this pull request Aug 28, 2019
rocksdb needs CMake 3.5.1 since
facebook/rocksdb#5662

Fixes: https://tracker.ceph.com/issues/41253
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 52277bf)
ajkr added a commit to cockroachdb/rocksdb that referenced this pull request Nov 1, 2019
@@ -93,43 +93,38 @@ else()
if(WITH_SNAPPY)
find_package(snappy REQUIRED)
add_definitions(-DSNAPPY)
include_directories(${SNAPPY_INCLUDE_DIR})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaikov Why do you remove this line? Seems that cannot find it in include path. Errors like
/root/cs/suzanwen/repos/C++/storage/rocksdb_xxx/rocksdb/util/compression.h:31:20: fatal error: snappy.h: No such file or directory #include <snappy.h> ^ compilation terminated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because, IIUC, snappy::snappy should be able to populate the "INSTALL_INTERFACE" property to the library/executable linked against it, so cmake will determine the correct build property of consumer of snappy::snappy and library publicly linked against this library.

INTERFACE_INCLUDE_DIRECTORIES ${snappy_INCLUDE_DIRS})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right for the most targets, such as ROCKSDB_STATIC_LIB. But not for TESTUTILLIB. Plz have a glance at the following snippet.

add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})

snappy.h was included in db/db_test_util.cc(just as the source file in target TESTUTILLIB). Porbably we need make it works fine with target_link_libraries(${TESTUTILLIB} ${LIBS}).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaikov #6043 pr as it is, plz make a review.

merryChris pushed a commit to merryChris/rocksdb that referenced this pull request Nov 18, 2019
Summary:
- cmake: use the builtin FindBzip2.cmake from CMake
- cmake: require CMake v3.5.1
- cmake: add imported target for 3rd party libraries
- cmake: extract ReadVersion.cmake out and refactor it
Pull Request resolved: facebook#5662

Differential Revision: D16660974

Pulled By: maysamyabandeh

fbshipit-source-id: 681594910e74253251fe14ad0befc41a4d0f4fd4
# Read rocksdb version from version.h header file.

function(get_rocksdb_version version_var)
file(READ "${CMAKE_SOURCE_DIR}/include/rocksdb/version.h" version_header_file)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CMAKE_CURRENT_SOURCE_DIR, not CMAKE_SOURCE_DIR. This particular variable breaks a rockdb source build that's been vendor'ed via add_subdirectory(vendor/rocksdb) in a parent source tree, as it instead tries to get the include/rocksdb/version.h in the parent project.

@wbrown-lg
Copy link

As noted in an inline comment, this breaks the rocksdb build if we do a CMake add_subdirectory on rocksdb.

@tchaikov
Copy link
Contributor Author

@wbrown-lg thanks for pointing out this. Will fix it shortly.

@tchaikov
Copy link
Contributor Author

@wbrown-lg this was fixed by adcf920 . could you use a commit which includes that change instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants