From 764da90c123066629d900eb55c89a25b6eefd70b Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Fri, 17 Oct 2025 22:25:46 +0200 Subject: [PATCH 1/6] create options for cmake project --- CMakeLists.txt | 145 ++++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a89a170ae..5744bbde1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.21) project(keyvi) #### Build Type @@ -6,14 +6,25 @@ if (CMAKE_BUILD_TYPE) string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) endif() +#### Options + +option(KEYVI_C_BINDINGS "Keyvi: Build C binding" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_PYTHON_BINDINGS "Keyvi: Build Python module" OFF) +option(KEYVI_TESTS "Keyvi: Build unit tests" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_BINARIES "Keyvi: Build Python module" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_DOCS "Keyvi: Build docs" ${PROJECT_IS_TOP_LEVEL}) + #### Linting -find_program(CLANGTIDY clang-tidy) -if(CLANGTIDY) - message ("-- Found clang-tidy") - set(CMAKE_CXX_CLANG_TIDY clang-tidy; --extra-arg-before=-std=c++17) -else() - message ("-- clang-tidy not found") -endif() +if(KEYVI_CLANG_TIDY) + find_program(CLANGTIDY clang-tidy) + if(CLANGTIDY) + message ("-- Found clang-tidy") + set(CMAKE_CXX_CLANG_TIDY clang-tidy; --extra-arg-before=-std=c++17) + else() + message ("-- clang-tidy not found") + endif() +endif(KEYVI_CLANG_TIDY) #### Cmake modules set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/") @@ -174,67 +185,73 @@ string(REPLACE " " ";" _KEYVI_COMPILE_DEFINITIONS_LIST "${_KEYVI_COMPILE_DEFINIT #### Targets #### -# keyvicompiler -add_executable(keyvicompiler keyvi/bin/keyvicompiler/keyvicompiler.cpp) -target_link_libraries(keyvicompiler ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -target_compile_options(keyvicompiler PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) -target_compile_definitions(keyvicompiler PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) -target_include_directories(keyvicompiler PRIVATE "$") +if(KEYVI_BINARIES) + # keyvicompiler + add_executable(keyvicompiler keyvi/bin/keyvicompiler/keyvicompiler.cpp) + target_link_libraries(keyvicompiler ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) + target_compile_options(keyvicompiler PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) + target_compile_definitions(keyvicompiler PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) + target_include_directories(keyvicompiler PRIVATE "$") -install (TARGETS keyvicompiler DESTINATION bin COMPONENT applications OPTIONAL) + install (TARGETS keyvicompiler DESTINATION bin COMPONENT applications OPTIONAL) -# keyviinspector -add_executable(keyviinspector keyvi/bin/keyviinspector/keyviinspector.cpp) -target_link_libraries(keyviinspector ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -target_compile_options(keyviinspector PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) -target_compile_definitions(keyviinspector PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) -target_include_directories(keyviinspector PRIVATE "$") + # keyviinspector + add_executable(keyviinspector keyvi/bin/keyviinspector/keyviinspector.cpp) + target_link_libraries(keyviinspector ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) + target_compile_options(keyviinspector PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) + target_compile_definitions(keyviinspector PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) + target_include_directories(keyviinspector PRIVATE "$") -install (TARGETS keyviinspector DESTINATION bin COMPONENT applications OPTIONAL) + install (TARGETS keyviinspector DESTINATION bin COMPONENT applications OPTIONAL) -# keyvimerger -add_executable(keyvimerger keyvi/bin/keyvimerger/keyvimerger.cpp) -target_link_libraries(keyvimerger ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -target_compile_options(keyvimerger PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) -target_compile_definitions(keyvimerger PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) -target_include_directories(keyvimerger PRIVATE "$") + # keyvimerger + add_executable(keyvimerger keyvi/bin/keyvimerger/keyvimerger.cpp) + target_link_libraries(keyvimerger ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) + target_compile_options(keyvimerger PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) + target_compile_definitions(keyvimerger PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) + target_include_directories(keyvimerger PRIVATE "$") -install (TARGETS keyvimerger DESTINATION bin COMPONENT applications) + install (TARGETS keyvimerger DESTINATION bin COMPONENT applications) +endif(KEYVI_BINARIES) # keyvi_c -add_library(keyvi_c SHARED keyvi/bin/keyvi_c/c_api.cpp) -target_link_libraries(keyvi_c ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -target_compile_options(keyvi_c PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) -target_compile_definitions(keyvi_c PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) -target_include_directories(keyvi_c PRIVATE "$") +if(KEYVI_C_BINDINGS) + add_library(keyvi_c SHARED keyvi/bin/keyvi_c/c_api.cpp) + target_link_libraries(keyvi_c ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) + target_compile_options(keyvi_c PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) + target_compile_definitions(keyvi_c PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) + target_include_directories(keyvi_c PRIVATE "$") +endif(KEYVI_C_BINDINGS) # unit tests -FILE(GLOB_RECURSE UNIT_TEST_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} keyvi/tests/keyvi/*.cpp) -add_executable(unit_test_all ${UNIT_TEST_SOURCES}) -target_link_libraries(unit_test_all ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -target_compile_options(unit_test_all PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) -target_compile_definitions(unit_test_all PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) -target_include_directories(unit_test_all PRIVATE "$") -add_dependencies(unit_test_all keyvimerger) - -if (WIN32) - message(STATUS "zlib: ${ZLIB_LIBRARY_RELEASE}") - # copies the dlls required to run to the build folder - foreach(LIB ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE} ${Boost_FILESYSTEM_LIBRARY_RELEASE} ${ZLIB_LIBRARY_RELEASE}) - get_filename_component(UTF_BASE_NAME ${LIB} NAME_WE) - get_filename_component(UTF_PATH ${LIB} PATH) - if(EXISTS "${UTF_PATH}/${UTF_BASE_NAME}.dll") - add_custom_command(TARGET unit_test_all POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "${UTF_PATH}/${UTF_BASE_NAME}.dll" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) - # zlib might be stored in a different folder - elseif(EXISTS "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll") - add_custom_command(TARGET unit_test_all POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) - endif() - endforeach() -endif (WIN32) +if(KEYVI_TESTS) + FILE(GLOB_RECURSE UNIT_TEST_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} keyvi/tests/keyvi/*.cpp) + add_executable(unit_test_all ${UNIT_TEST_SOURCES}) + target_link_libraries(unit_test_all ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) + target_compile_options(unit_test_all PRIVATE ${_KEYVI_CXX_FLAGS_LIST}) + target_compile_definitions(unit_test_all PRIVATE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) + target_include_directories(unit_test_all PRIVATE "$") + add_dependencies(unit_test_all keyvimerger) + + if (WIN32) + message(STATUS "zlib: ${ZLIB_LIBRARY_RELEASE}") + # copies the dlls required to run to the build folder + foreach(LIB ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE} ${Boost_FILESYSTEM_LIBRARY_RELEASE} ${ZLIB_LIBRARY_RELEASE}) + get_filename_component(UTF_BASE_NAME ${LIB} NAME_WE) + get_filename_component(UTF_PATH ${LIB} PATH) + if(EXISTS "${UTF_PATH}/${UTF_BASE_NAME}.dll") + add_custom_command(TARGET unit_test_all POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${UTF_PATH}/${UTF_BASE_NAME}.dll" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ) + # zlib might be stored in a different folder + elseif(EXISTS "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll") + add_custom_command(TARGET unit_test_all POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + ) + endif() + endforeach() + endif (WIN32) +endif(KEYVI_TESTS) # bindings add_custom_target(bindings @@ -259,10 +276,14 @@ target_include_directories(keyvi INTERFACE "$ target_compile_definitions(keyvi INTERFACE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) target_link_libraries(keyvi INTERFACE ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) +if (KEYVI_PYTHON_BINDINGS) + add_subdirectory(python-pybind) +endif () + ### docs # don't run it as part of a non-toplevel build, e.g. python -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/sphinx-docs) +if(KEYVI_DOCS) find_package(Doxygen) find_package(Sphinx COMPONENTS breathe) @@ -288,4 +309,4 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/sphinx-docs) else() message ("-- Skip doc target, doxygen/sphinx not found") endif() -endif() +endif(KEYVI_DOCS) From f647df8adaba21c84e83938e0f6edfd3a844d2aa Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Fri, 17 Oct 2025 22:28:37 +0200 Subject: [PATCH 2/6] pre-commit on cmake files --- CMakeLists.txt | 4 ++-- cmake_modules/FindSnappy.cmake | 2 +- cmake_modules/FindSphinx.cmake | 1 - keyvi/flags.cmake | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5744bbde1..bb46435d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,7 +114,7 @@ if (WIN32) add_definitions( -DBOOST_ALL_NO_LIB ) add_definitions( -DBOOST_ALL_DYN_LINK ) link_directories (${Boost_LIBRARY_DIRS}) - + # required for endian specific functions list(APPEND _OS_LIBRARIES "ws2_32") endif (WIN32) @@ -247,7 +247,7 @@ if(KEYVI_TESTS) elseif(EXISTS "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll") add_custom_command(TARGET unit_test_all POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${UTF_PATH}/../bin/${UTF_BASE_NAME}.dll" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - ) + ) endif() endforeach() endif (WIN32) diff --git a/cmake_modules/FindSnappy.cmake b/cmake_modules/FindSnappy.cmake index d9537b2b8..f7460d3fd 100644 --- a/cmake_modules/FindSnappy.cmake +++ b/cmake_modules/FindSnappy.cmake @@ -15,4 +15,4 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS( Snappy_LIBRARY Snappy_INCLUDE_DIR ) -mark_as_advanced(Snappy_INCLUDE_DIR Snappy_LIBRARY) \ No newline at end of file +mark_as_advanced(Snappy_INCLUDE_DIR Snappy_LIBRARY) diff --git a/cmake_modules/FindSphinx.cmake b/cmake_modules/FindSphinx.cmake index 09fbb141a..d801c76e4 100644 --- a/cmake_modules/FindSphinx.cmake +++ b/cmake_modules/FindSphinx.cmake @@ -337,4 +337,3 @@ function(sphinx_add_docs _target) "${_outputdir}" DEPENDS ${_depends}) endfunction() - diff --git a/keyvi/flags.cmake b/keyvi/flags.cmake index 6bd9e7c6c..49aff4459 100644 --- a/keyvi/flags.cmake +++ b/keyvi/flags.cmake @@ -8,4 +8,4 @@ KEYVI_LINK_LIBRARIES_ALL=@_KEYVI_LINK_LIBRARIES_DYNAMIC@ @_KEYVI_LINK_LIBRARIES_ KEYVI_LINK_LIBRARIES_DYNAMIC=@_KEYVI_LINK_LIBRARIES_DYNAMIC@ KEYVI_LINK_LIBRARIES_STATIC=@_KEYVI_LINK_LIBRARIES_STATIC@ KEYVI_LINK_FLAGS=@_KEYVI_LINK_FLAGS@ -KEYVI_INCLUDES=@_KEYVI_INCLUDES@ \ No newline at end of file +KEYVI_INCLUDES=@_KEYVI_INCLUDES@ From 931c227d1f3e3f97c77ad5d7eb2edf798d651160 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Tue, 21 Oct 2025 05:37:54 +0200 Subject: [PATCH 3/6] turn off clang-tidy as default --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb46435d5..a16ab7c35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(KEYVI_C_BINDINGS "Keyvi: Build C binding" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_PYTHON_BINDINGS "Keyvi: Build Python module" OFF) option(KEYVI_TESTS "Keyvi: Build unit tests" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_BINARIES "Keyvi: Build Python module" ${PROJECT_IS_TOP_LEVEL}) -option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" ${PROJECT_IS_TOP_LEVEL} OFF) option(KEYVI_DOCS "Keyvi: Build docs" ${PROJECT_IS_TOP_LEVEL}) #### Linting @@ -22,7 +22,7 @@ if(KEYVI_CLANG_TIDY) message ("-- Found clang-tidy") set(CMAKE_CXX_CLANG_TIDY clang-tidy; --extra-arg-before=-std=c++17) else() - message ("-- clang-tidy not found") + message(FATAL_ERROR "clang-tidy requested but not found") endif() endif(KEYVI_CLANG_TIDY) From 76bef1c0b41d7a70dcc73c81ae0b9203b568185d Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Tue, 21 Oct 2025 06:10:24 +0200 Subject: [PATCH 4/6] fix syntax --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a16ab7c35..8c99946f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(KEYVI_C_BINDINGS "Keyvi: Build C binding" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_PYTHON_BINDINGS "Keyvi: Build Python module" OFF) option(KEYVI_TESTS "Keyvi: Build unit tests" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_BINARIES "Keyvi: Build Python module" ${PROJECT_IS_TOP_LEVEL}) -option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" ${PROJECT_IS_TOP_LEVEL} OFF) +option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" OFF) option(KEYVI_DOCS "Keyvi: Build docs" ${PROJECT_IS_TOP_LEVEL}) #### Linting From dbc001cf70bd34b11cca95b84c1bed7d5f26ac12 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Tue, 21 Oct 2025 14:28:31 +0200 Subject: [PATCH 5/6] Update CMakeLists.txt remove python bindings from this PR --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c99946f8..979ada4a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ endif() #### Options option(KEYVI_C_BINDINGS "Keyvi: Build C binding" ${PROJECT_IS_TOP_LEVEL}) -option(KEYVI_PYTHON_BINDINGS "Keyvi: Build Python module" OFF) option(KEYVI_TESTS "Keyvi: Build unit tests" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_BINARIES "Keyvi: Build Python module" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" OFF) @@ -276,10 +275,6 @@ target_include_directories(keyvi INTERFACE "$ target_compile_definitions(keyvi INTERFACE ${_KEYVI_COMPILE_DEFINITIONS_LIST}) target_link_libraries(keyvi INTERFACE ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${Snappy_LIBRARY} ${ZSTD_LIBRARIES} ${_OS_LIBRARIES}) -if (KEYVI_PYTHON_BINDINGS) - add_subdirectory(python-pybind) -endif () - ### docs # don't run it as part of a non-toplevel build, e.g. python From 4aac62e33c2354b1d1d1bf9ac95ad3117f59b033 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Tue, 21 Oct 2025 14:32:49 +0200 Subject: [PATCH 6/6] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 979ada4a3..52f073adf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ endif() option(KEYVI_C_BINDINGS "Keyvi: Build C binding" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_TESTS "Keyvi: Build unit tests" ${PROJECT_IS_TOP_LEVEL}) -option(KEYVI_BINARIES "Keyvi: Build Python module" ${PROJECT_IS_TOP_LEVEL}) +option(KEYVI_BINARIES "Keyvi: Build keyvi binaries" ${PROJECT_IS_TOP_LEVEL}) option(KEYVI_CLANG_TIDY "Keyvi: Build with clang tidy" OFF) option(KEYVI_DOCS "Keyvi: Build docs" ${PROJECT_IS_TOP_LEVEL})