From 957403663fc4e7a7a51e1b940a46d77c11acff75 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 21 Feb 2023 13:34:30 +0800 Subject: [PATCH] build: cmake: build release.cc as a library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so we can attach compiling definitions in a simpler way. this change is based on Botond Dénes's change which gives an overhaul to the existing CMake building system. Signed-off-by: Kefu Chai --- CMakeLists.txt | 23 ++++------------------- cmake/add_version_library.cmake | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 cmake/add_version_library.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2de21da6c1..c0ef9f6b93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,7 +229,6 @@ set(scylla_sources redis/command_factory.cc redis/commands.cc redis/lolwut.cc - release.cc repair/repair.cc repair/row_level.cc replica/database.cc @@ -322,7 +321,9 @@ add_subdirectory(sstables) add_subdirectory(test) add_subdirectory(types) add_subdirectory(utils) - +include(add_version_library) +add_version_library(scylla_version + release.cc) add_executable(scylla ${scylla_sources} ${scylla_gen_sources}) @@ -334,6 +335,7 @@ target_link_libraries(scylla PRIVATE cql3 idl schema + scylla_version sstables test-perf types @@ -397,23 +399,6 @@ target_include_directories(scylla PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${scylla_gen_build_dir}") -### -### Generate version file and supply appropriate compile definitions for release.cc -### -execute_process(COMMAND ${CMAKE_SOURCE_DIR}/SCYLLA-VERSION-GEN --output-dir "${CMAKE_BINARY_DIR}/gen" RESULT_VARIABLE scylla_version_gen_res) -if(scylla_version_gen_res) - message(SEND_ERROR "Version file generation failed. Return code: ${scylla_version_gen_res}") -endif() - -file(READ "${CMAKE_BINARY_DIR}/gen/SCYLLA-VERSION-FILE" scylla_version) -string(STRIP "${scylla_version}" scylla_version) - -file(READ "${CMAKE_BINARY_DIR}/gen/SCYLLA-RELEASE-FILE" scylla_release) -string(STRIP "${scylla_release}" scylla_release) - -get_property(release_cdefs SOURCE "${CMAKE_SOURCE_DIR}/release.cc" PROPERTY COMPILE_DEFINITIONS) -list(APPEND release_cdefs "SCYLLA_VERSION=\"${scylla_version}\"" "SCYLLA_RELEASE=\"${scylla_release}\"") -set_source_files_properties("${CMAKE_SOURCE_DIR}/release.cc" PROPERTIES COMPILE_DEFINITIONS "${release_cdefs}") # TODO: create cmake/ directory and move utilities (generate functions etc) there # TODO: Build tests if BUILD_TESTING=on (using CTest module) diff --git a/cmake/add_version_library.cmake b/cmake/add_version_library.cmake new file mode 100644 index 0000000000..1d88090681 --- /dev/null +++ b/cmake/add_version_library.cmake @@ -0,0 +1,21 @@ +### +### Generate version file and supply appropriate compile definitions for release.cc +### +function(add_version_library name source) + set(version_file ${CMAKE_CURRENT_BINARY_DIR}/SCYLLA-VERSION-FILE) + set(release_file ${CMAKE_CURRENT_BINARY_DIR}/SCYLLA-RELEASE-FILE) + execute_process( + COMMAND ${CMAKE_SOURCE_DIR}/SCYLLA-VERSION-GEN --output-dir "${CMAKE_CURRENT_BINARY_DIR}" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + file(STRINGS ${version_file} scylla_version) + file(STRINGS ${release_file} scylla_release) + + add_library(${name} OBJECT ${source}) + target_compile_definitions(${name} + PRIVATE + SCYLLA_VERSION=\"${scylla_version}\" + SCYLLA_RELEASE=\"${scylla_release}\") + target_link_libraries(${name} + PRIVATE + Seastar::seastar) +endfunction(add_version_library)