Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.*
*~
bazel-*
/*build*
build*
bin/*
lib/*
var/*
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ message(STATUS "PROJECT_ROOT_DIR = ${PROJECT_ROOT_DIR}")

include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake)

include_directories(${PROJECT_ROOT_DIR}/src/include)
include_directories(${PROJECT_ROOT_DIR}/src)

option(BUILD_PYTHON_BINDINGS "Build Python bindings using pybind11" OFF)
Expand All @@ -33,7 +34,7 @@ cc_directories(tests)

if(BUILD_TOOLS)
cc_directories(tools)
endif ()
endif()

git_version(GIT_SRCS_VER ${PROJECT_ROOT_DIR})
set(CPACK_PACKAGE_VERSION ${GIT_SRCS_VER})
Expand Down
49 changes: 33 additions & 16 deletions cmake/bazel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## 1.3. Build a C/C++ static or shared library
## cc_library(
## NAME <name>
## [STATIC] [SHARED] [STRICT] [ALWAYS_LINK] [EXCLUDE] [PACKED]
## [STATIC] [SHARED] [STRICT] [ALWAYS_LINK] [EXCLUDE] [PACKED] [SRCS_NO_GLOB]
## SRCS <file1> [file2 ...]
## [INCS dir1 ...]
## [PUBINCS public_dir1 ...]
Expand Down Expand Up @@ -813,18 +813,35 @@ endfunction()
## Build a C/C++ static or shared library
function(cc_library)
cmake_parse_arguments(
CC_ARGS "STATIC;SHARED;EXCLUDE;PACKED" "NAME;VERSION"
CC_ARGS
"STATIC;SHARED;EXCLUDE;PACKED;SRCS_NO_GLOB"
"NAME;VERSION"
"SRCS;INCS;PUBINCS;DEFS;LIBS;CFLAGS;CXXFLAGS;LDFLAGS;DEPS;PACKED_EXCLUDES"
${ARGN}
)
)

if(NOT CC_ARGS_NAME)
message(FATAL_ERROR "No target name privated.")
message(FATAL_ERROR "No target name provided.")
endif()

file(GLOB CC_ARGS_SRCS ${CC_ARGS_SRCS})
if(NOT CC_ARGS_SRCS)
message(FATAL_ERROR "No source files found of ${CC_ARGS_NAME}.")
if(CC_ARGS_SRCS_NO_GLOB)
set(SOURCE_FILES ${CC_ARGS_SRCS})
if(NOT SOURCE_FILES)
message(FATAL_ERROR "No source files provided for ${CC_ARGS_NAME} (SRCS_NO_GLOB mode).")
endif()
else()
set(SOURCE_FILES "")
foreach(_src IN LISTS CC_ARGS_SRCS)
if(IS_ABSOLUTE "${_src}" OR NOT "${_src}" MATCHES "[*?]")
list(APPEND SOURCE_FILES "${_src}")
else()
file(GLOB _globbed_srcs ${_src})
list(APPEND SOURCE_FILES ${_globbed_srcs})
endif()
endforeach()
if(NOT SOURCE_FILES)
message(FATAL_ERROR "No source files found for ${CC_ARGS_NAME} after globbing.")
endif()
endif()

if(CC_ARGS_VERSION)
Expand All @@ -837,13 +854,13 @@ function(cc_library)
endif()

if(CC_ARGS_SHARED AND CC_ARGS_STATIC)
_add_library(${CC_ARGS_NAME} "${EXCLUDE_OPTION}" "${CC_ARGS_SRCS}")
_add_library(${CC_ARGS_NAME} "${EXCLUDE_OPTION}" ${SOURCE_FILES})
elseif(CC_ARGS_SHARED)
add_library(${CC_ARGS_NAME} SHARED ${EXCLUDE_OPTION} ${CC_ARGS_SRCS})
add_library(${CC_ARGS_NAME} SHARED ${EXCLUDE_OPTION} ${SOURCE_FILES})
elseif(CC_ARGS_STATIC)
add_library(${CC_ARGS_NAME} STATIC ${EXCLUDE_OPTION} ${CC_ARGS_SRCS})
add_library(${CC_ARGS_NAME} STATIC ${EXCLUDE_OPTION} ${SOURCE_FILES})
else()
add_library(${CC_ARGS_NAME} ${EXCLUDE_OPTION} ${CC_ARGS_SRCS})
add_library(${CC_ARGS_NAME} ${EXCLUDE_OPTION} ${SOURCE_FILES})
endif()

if(TARGET ${CC_ARGS_NAME}_objects)
Expand All @@ -857,7 +874,7 @@ function(cc_library)
LDFLAGS "${CC_ARGS_LDFLAGS}"
DEPS "${CC_ARGS_DEPS}"
"${CC_ARGS_UNPARSED_ARGUMENTS}"
)
)
endif()

if(TARGET ${CC_ARGS_NAME}_static)
Expand All @@ -872,7 +889,7 @@ function(cc_library)
LDFLAGS "${CC_ARGS_LDFLAGS}"
DEPS "${CC_ARGS_DEPS}"
"${CC_ARGS_UNPARSED_ARGUMENTS}"
)
)
if(CC_ARGS_PACKED)
install(
TARGETS ${CC_ARGS_NAME}_static
Expand All @@ -893,13 +910,13 @@ function(cc_library)
DEPS "${CC_ARGS_DEPS}"
VERSION "${CC_ARGS_VERSION}"
"${CC_ARGS_UNPARSED_ARGUMENTS}"
)
)
if(CC_ARGS_PACKED)
install(
TARGETS ${CC_ARGS_NAME}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
)
if(CC_ARGS_PUBINCS)
foreach(PACKED_EXCLUDE ${CC_ARGS_PACKED_EXCLUDES})
list(APPEND PATTERN_EXCLUDES "PATTERN;${PACKED_EXCLUDE};EXCLUDE")
Expand All @@ -908,7 +925,7 @@ function(cc_library)
DIRECTORY ${CC_ARGS_PUBINCS} DESTINATION ${CMAKE_INSTALL_INCDIR}
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.hxx"
${PATTERN_EXCLUDES}
)
)
endif()
endif()
endfunction()
Expand Down
107 changes: 107 additions & 0 deletions examples/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0077 NEW)
project(zvec-example-c++)
set(CMAKE_CXX_STANDARD 17)

# Enable compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# --- Paths to Zvec and dependencies ---
set(ZVEC_INCLUDE_DIR ${CMAKE_BINARY_DIR}/../../../src/include)
set(ZVEC_LIB_DIR ${CMAKE_BINARY_DIR}/../../../build/lib)
set(ZVEC_DEPENDENCY_LIB_DIR ${CMAKE_BINARY_DIR}/../../../build/external/usr/local/lib)

# Add include and library search paths
include_directories(${ZVEC_INCLUDE_DIR})
link_directories(${ZVEC_LIB_DIR} ${ZVEC_DEPENDENCY_LIB_DIR})

# --- Determine debug/release library names ---
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(GLOG_LIB glogd)
set(GFLAGS_LIB gflags_nothreads_debug)
set(PROTOBUF_LIB protobufd)
else()
set(GLOG_LIB glog)
set(GFLAGS_LIB gflags_nothreads)
set(PROTOBUF_LIB protobuf)
endif()

# --- Dependency groups ---
set(zvec_ailego_deps
arrow
parquet
arrow_bundled_dependencies
)

set(zvec_core_deps
# empty
)

set(zvec_db_deps
roaring
rocksdb
arrow
arrow_acero
arrow_bundled_dependencies
arrow_compute
arrow_dataset
parquet
antlr4-runtime
${GLOG_LIB}
${GFLAGS_LIB}
${PROTOBUF_LIB}
lz4
)

# --- Create INTERFACE targets for Zvec components ---

# zvec_ailego: links libzvec_ailego.a + its deps
add_library(zvec-ailego INTERFACE)
target_link_libraries(zvec-ailego INTERFACE
-lzvec_ailego
${zvec_ailego_deps}
)

# zvec_core: links libzvec_core.a via special flags (handled externally), but declare logical deps
add_library(zvec-core INTERFACE)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(zvec-core INTERFACE
"-Wl,--whole-archive,${ZVEC_LIB_DIR}/libzvec_core.a,-Wl,--no-whole-archive"
zvec-ailego
${zvec_core_deps}
)
elseif(APPLE)
target_link_libraries(zvec-core INTERFACE
"-Wl,-force_load,${ZVEC_LIB_DIR}/libzvec_core.a"
zvec-ailego
${zvec_core_deps}
)
else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()

# zvec_db: links libzvec_db.a + all deps
add_library(zvec-db INTERFACE)
target_link_libraries(zvec-db INTERFACE
zvec_db
zvec-core
zvec-ailego
${zvec_db_deps}
)


# --- Main executable ---
add_executable(db-example db/main.cc)
target_link_libraries(db-example PRIVATE
zvec-db
)

add_executable(core-example core/main.cc)
target_link_libraries(core-example PRIVATE
zvec-core
)

add_executable(ailego-example ailego/main.cc)
target_link_libraries(ailego-example PRIVATE
zvec-ailego
)
11 changes: 11 additions & 0 deletions examples/c++/ailego/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include <string>
#include <zvec/ailego/utility/string_helper.h>

using namespace zvec;

int main() {
std::string a{"hello world"};

std::cout << ailego::StringHelper::StartsWith(a, "hello") << std::endl;
}
3 changes: 3 additions & 0 deletions examples/c++/core/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}
Loading