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

Migrate TgTypeParser to template and jsoncpp #315

Closed
wants to merge 19 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
!samples
!src
!test
!CMakeLists.txt
!CMakeLists.txt
!CMake
27 changes: 27 additions & 0 deletions CMake/FindJsonCppCustom.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# FindJsonCpp.cmake

# Try to locate the jsoncpp package using pkg-config
find_package(PkgConfig QUIET)

if (PKG_CONFIG_FOUND)
pkg_check_modules(JSONCPP_PKG jsoncpp)

if (JSONCPP_PKG_FOUND)
# Create the jsoncpp imported target
if (NOT TARGET JsonCpp::JsonCpp)
add_library(JsonCpp::JsonCpp SHARED IMPORTED)
set_target_properties(JsonCpp::JsonCpp PROPERTIES
IMPORTED_LOCATION "${JSONCPP_PKG_LIBRARY_DIRS}/libjsoncpp.so"
INTERFACE_INCLUDE_DIRECTORIES "${JSONCPP_PKG_INCLUDE_DIRS}"
)

# Optionally, set any additional properties, such as dependencies or version
message(STATUS "Found JsonCpp: ${JSONCPP_PKG_LIBRARY_DIRS}/libjsoncpp.so")
endif()

else()
message(FATAL_ERROR "Pkg-config found, but JsonCpp not found via pkg-config.")
endif()
else()
message(FATAL_ERROR "Pkg-config not found, cannot locate JsonCpp.")
endif()
32 changes: 20 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@ set(SRC_LIST
src/net/Url.cpp
src/tools/FileTools.cpp
src/tools/StringTools.cpp
src/types/BotCommandScope.cpp
src/types/ChatBoostSource.cpp
src/types/ChatMember.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
src/types/InputMedia.cpp
src/types/InputMessageContent.cpp
src/types/MenuButton.cpp
src/types/MessageOrigin.cpp
src/types/PassportElementError.cpp
src/types/ReactionType.cpp)
src/types/InputFile.cpp)

# libs
## threads
Expand All @@ -67,6 +57,22 @@ if (CURL_FOUND)
add_definitions(-DHAVE_CURL)
endif()

## jsoncpp
if (NOT TARGET JsonCpp::JsonCpp)
find_package(jsoncpp)
if (NOT TARGET JsonCpp::JsonCpp)
message(STATUS "Using alternative findjsoncpp")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
find_package(JsonCppCustom)
if (NOT TARGET JsonCpp::JsonCpp)
message(FATAL_ERROR "Jsoncpp is not available")
endif()
endif()
endif()
install(FILES CMake/FindJsonCppCustom.cmake
DESTINATION lib/cmake/tgbot-cpp
)

## boost
set(Boost_USE_MULTITHREADED ON)
if (ENABLE_TESTS)
Expand All @@ -86,10 +92,11 @@ set(LIB_LIST
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${Boost_LIBRARIES}
JsonCpp::JsonCpp
)

if (CURL_FOUND)
set(LIB_LIST ${LIB_LIST} ${CURL_LIBRARIES})
set(LIB_LIST ${LIB_LIST} CURL::libcurl)
endif()

if (WIN32)
Expand All @@ -101,6 +108,7 @@ add_library(${PROJECT_NAME} ${SRC_LIST})
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_include_directories(${PROJECT_NAME} PUBLIC ${jsoncpp_INCLUDE_DIRS} ${JSONCPP_PKG_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${LIB_LIST})
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ FROM debian:latest
MAINTAINER Oleg Morozenkov <[email protected]>

RUN apt-get -qq update && \
apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev zlib1g-dev && \
apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev zlib1g-dev libjsoncpp-dev && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/tgbot-cpp
COPY include include
COPY src src
COPY CMakeLists.txt ./
COPY CMake CMake

RUN cmake . && \
make -j$(nproc) && \
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile_test
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ RUN apt-get -qq update && \
make \
python2.7-dev \
wget \
zlib1g-dev && \
zlib1g-dev \
libjsoncpp-dev \
pkg-config && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/tgbot-cpp
COPY include include
COPY src src
COPY test test
COPY CMakeLists.txt ./
COPY CMake CMake

RUN cmake -DENABLE_TESTS=ON . && \
make -j$(nproc) && \
Expand Down
Loading
Loading