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 cmake and ci #23

Open
wants to merge 1 commit 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
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
branches:
- master

jobs:
build-macOS:
name: build (macOS)
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: |
brew install libev
cmake --debug-output -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
build-linux:
name: build (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
sudo apt-get install libev-dev
cmake --debug-output -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.15)

project(jsonrcp-c
LANGUAGES C
)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

set(CMAKE_C_STANDARD 11)
set(SRCS src/jsonrpc-c.c src/cJSON.c)
set(HDRS include/jsonrpc-c.h include/cJSON.h)

find_package(Libev REQUIRED)

add_library(
jsonrpc-c
STATIC ${HDRS} ${SRCS}
)
target_include_directories(
jsonrpc-c
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${LIBEV_INCLUDE_DIRS}
)
target_link_libraries(
jsonrpc-c
PUBLIC
${LIBEV_LIBRARIES}
)

add_library(
jsonrpc-c-shared
SHARED ${HDRS} ${SRCS}
)
target_include_directories(
jsonrpc-c-shared
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${LIBEV_INCLUDE_DIRS}
)
target_link_libraries(
jsonrpc-c-shared
PUBLIC
${LIBEV_LIBRARIES}
)
40 changes: 40 additions & 0 deletions cmake/FindLibev.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://github.com/nghttp2/nghttp2/blob/master/cmake/FindLibev.cmake

# - Try to find libev
# Once done this will define
# LIBEV_FOUND - System has libev
# LIBEV_INCLUDE_DIRS - The libev include directories
# LIBEV_LIBRARIES - The libraries needed to use libev

find_path(LIBEV_INCLUDE_DIR
NAMES ev.h
)
find_library(LIBEV_LIBRARY
NAMES ev
)

if(LIBEV_INCLUDE_DIR)
file(STRINGS "${LIBEV_INCLUDE_DIR}/ev.h"
LIBEV_VERSION_MAJOR REGEX "^#define[ \t]+EV_VERSION_MAJOR[ \t]+[0-9]+")
file(STRINGS "${LIBEV_INCLUDE_DIR}/ev.h"
LIBEV_VERSION_MINOR REGEX "^#define[ \t]+EV_VERSION_MINOR[ \t]+[0-9]+")
string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MAJOR "${LIBEV_VERSION_MAJOR}")
string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MINOR "${LIBEV_VERSION_MINOR}")
set(LIBEV_VERSION "${LIBEV_VERSION_MAJOR}.${LIBEV_VERSION_MINOR}")
unset(LIBEV_VERSION_MINOR)
unset(LIBEV_VERSION_MAJOR)
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBEV_FOUND to TRUE
# if all listed variables are TRUE and the requested version matches.
find_package_handle_standard_args(Libev REQUIRED_VARS
LIBEV_LIBRARY LIBEV_INCLUDE_DIR
VERSION_VAR LIBEV_VERSION)

if(LIBEV_FOUND)
set(LIBEV_LIBRARIES ${LIBEV_LIBRARY})
set(LIBEV_INCLUDE_DIRS ${LIBEV_INCLUDE_DIR})
endif()

mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARY)