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

Add Windows and CMake support #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
222 changes: 222 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
cmake_minimum_required(VERSION 3.23.0)
project(libserdes)

option(SERDES_ENABLE_AVRO_C "Include avro C facilities" OFF)
option(SERDES_ENABLE_AVRO_CPP "Include avro C++ facilities" ON)
option(SERDES_ENABLE_WITH_EXAMPLE "Build examples" OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(SERDES_ENABLE_AVRO_CPP)
find_package(libavrocpp REQUIRED)
endif()
find_package(jansson REQUIRED)
find_package(CURL REQUIRED)

# Serdes common base library
# --------------------------
set(SERDES_COMMON_PUBLIC_HEADERS
src/serdes.h
src/serdes-common.h
)

set(SERDES_COMMON_SRC
src/framing.c
src/rest.c
src/rest.h
src/schema-cache.c
src/serdes.c
src/serdes_int.h
src/tinycthread.h
)

# Serdes C thread library
# -----------------------
add_library(serdes_c_thread STATIC
src/tinycthread.c
src/tinycthread.h
)

target_compile_features(serdes_c_thread PUBLIC c_std_99)
# C_STANDARD required for macOS
set_target_properties(serdes_c_thread PROPERTIES
C_STANDARD 99
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
LINKER_LANGUAGE C
FOLDER "Serdes"
)

# Serdes C library
# ----------------
add_library(serdes STATIC)

target_compile_features(serdes PUBLIC c_std_99)
# C_STANDARD required for macOS
set_target_properties(serdes PROPERTIES
C_STANDARD 99
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
LINKER_LANGUAGE C
FOLDER "Serdes"
)

target_compile_definitions(serdes PRIVATE HAVE_NO_CONFIG)

target_include_directories(serdes
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/windows/include>
)

IF (WIN32)
target_include_directories(serdes
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/windows/include>
)
ENDIF()

target_sources(serdes
PUBLIC
FILE_SET serdes_api
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src
FILES
${SERDES_COMMON_PUBLIC_HEADERS}
src/serdes.h
PRIVATE
${SERDES_COMMON_SRC}
)

target_link_libraries(serdes
PRIVATE
CURL::libcurl
jansson::jansson
)

if(SERDES_ENABLE_AVRO_C)
target_compile_definitions(serdes PUBLIC ENABLE_AVRO_C)

target_sources(serdes
PUBLIC
FILE_SET serdes_api
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src
FILES
src/serdes-avro.h
PRIVATE
src/deserialize-avro.c
src/schema-avro.c
src/serialize-avro.c
)

target_link_libraries(serdes
PUBLIC
avro-static
)
endif()

# Serdes C++ thread library
# -----------------------
add_library(serdes_cxx_thread STATIC
src/tinycthread.c
src/tinycthread.h
)

target_compile_features(serdes_cxx_thread PUBLIC cxx_std_11)
# CXX_STANDARD required for macOS
set_target_properties(serdes_cxx_thread PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
FOLDER "Serdes"
)

# Serdes C++ library
# ------------------
add_library(serdes++ STATIC)

target_compile_features(serdes++ PUBLIC cxx_std_11)
# CXX_STANDARD required for macOS
set_target_properties(serdes++ PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
FOLDER "Serdes"
)

target_compile_definitions(serdes++ PRIVATE HAVE_NO_CONFIG)

target_include_directories(serdes++
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src-cpp>
$<INSTALL_INTERFACE:include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)

IF (WIN32)
target_include_directories(serdes++
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/windows/include>
)
ENDIF()

target_sources(serdes++
PUBLIC
FILE_SET serdes_api
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src
FILES
${SERDES_COMMON_PUBLIC_HEADERS}
PUBLIC
FILE_SET serdes_api
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src-cpp
FILES
src-cpp/serdescpp.h
PRIVATE
${SERDES_COMMON_SRC}
src-cpp/Serdes.cpp
src-cpp/serdescpp_int.h
)

target_link_libraries(serdes++
PRIVATE
CURL::libcurl
jansson::jansson
)

if(SERDES_ENABLE_AVRO_CPP)
target_sources(serdes++
PUBLIC
FILE_SET serdes_api
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src-cpp
FILES
src-cpp/serdescpp-avro.h
PRIVATE
src-cpp/serdescpp-avro_int.h
src-cpp/serdes-avro.cpp
)

target_link_libraries(serdes++
PUBLIC
libavrocpp::libavrocpp
)
endif()

# TODO install directory: include/libserdes
include(GNUInstallDirs)
install(TARGETS
serdes serdes_c_thread
serdes++ serdes_cxx_thread
FILE_SET serdes_api
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libserdes
)

if(SERDES_ENABLE_WITH_EXAMPLE)
add_subdirectory(examples)
endif()
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# libserdes

Copyright(C) 2015-2022 Confluent Inc.
Copyright(C) 2015-2023 Confluent Inc.

* This software is licensed under the Apache 2.0 license.
---------------------------------------------------------------------------
Expand Down Expand Up @@ -49,17 +49,36 @@ On Debian/Ubuntu based systems:
**NOTE: The avro libraries needs to be installed manually or through [Confluent's APT and YUM repositories](http://docs.confluent.io/current/installation.html)**

## Build
### Configure script (Linux)

./configure
make
sudo make install

### CMake - Conan

### Documentation
mkdir build
cd build
conan install -pr:b win_x86_64_release -pr:h win_x86_64_release ../conan/conanfile.txt
cmake .. --toolchain=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake -P cmake_install.cmake

profile `win_x86_64_release` is provided as example in `conan` directory.

Build options:

| Option | Description | Default |
| :-------------------------------- | :-------------------------- | :-----: |
| SERDES_ENABLE_AVRO_C | Include avro C facilities | OFF |
| SERDES_ENABLE_AVRO_CPP | Include avro C++ facilities | ON |
| SERDES_ENABLE_WITH_EXAMPLE | Build examples | OFF |
| SERDES_ENABLE_EXAMPLES_LIBRDKAFKA | Include examples with kafka | OFF |

## Documentation

Full API documentation is available in [serdes.h](src/serdes.h) and [serdescpp.h](src-cpp/serdescpp.h)

### Configuration
## Configuration

libserdes typically only needs to be configured with a list of URLs
to the schema registries, all other configuration is optional.
Expand Down
15 changes: 15 additions & 0 deletions conan/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[requires]
libavrocpp/1.11.1
libcurl/7.88.1
jansson/2.14
openssl/1.1.1t

librdkafka/1.9.2

[generators]
CMakeToolchain
CMakeDeps

[options]
libcurl:with_ssl=openssl
openssl:shared=True
9 changes: 9 additions & 0 deletions conan/win_x86_64_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[settings]
os=Windows
arch=x86_64
compiler=Visual Studio
compiler.version=17
build_type=Release
[options]
[build_requires]
[env]
Loading