Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from Follpvosten/cmake-find-library
Browse files Browse the repository at this point in the history
Use find_library and find_package for jansson and libcurl
  • Loading branch information
h4child committed May 17, 2018
2 parents d049784 + d0a59b6 commit d234c97
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 60 deletions.
24 changes: 13 additions & 11 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ include_directories (${PROJECT_SOURCE_DIR}/../include)

add_definitions("-g")

set(OS_FREEBSD CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
if(UNIX)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
# This is probably an unsupported BSD or OSX.
# Show an error, but try to proceed.
message(SEND_ERROR "Only Linux, FreeBSD and Windows are supported at this time.")
endif()

if(${OS_FREEBSD})
# Add /usr/local/lib so we can find the libs on FreeBSD
link_directories(/usr/local/lib /usr/lib /lib)
# Search for the required libraries, erroring out if they aren't found
find_library(JANSSON_LIB NAMES jansson)
find_package(CURL REQUIRED)
# Add the include directories for the libraries
include_directories(${CURL_INCLUDE_DIRS})
endif()

add_executable(echo echo.c)
target_link_libraries(echo jansson libcurl.so framebot)
target_link_libraries(echo ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)

add_executable(inline inline_bot.c)
target_link_libraries(inline jansson libcurl.so framebot)

if(${OS_FREEBSD})
target_compile_options(echo PUBLIC -I/usr/local/include)
target_compile_options(inline PUBLIC -I/usr/local/include)
endif()
target_link_libraries(inline ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
30 changes: 14 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@ include_directories (${PROJECT_SOURCE_DIR}/../include)

add_definitions("-g")

set(OS_LINUX CMAKE_SYSTEM_NAME STREQUAL Linux)
set(OS_FREEBSD CMAKE_SYSTEM_NAME STREQUAL FreeBSD)

if(${OS_LINUX} OR ${OS_FREEBSD})
if(${OS_FREEBSD})
# Add /usr/local/lib so we can find the libs on FreeBSD
link_directories(/usr/local/lib /usr/lib /lib)
if(UNIX)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
# This is probably an unsupported BSD or OSX.
# Show an error, but try to proceed.
message(SEND_ERROR "Only Linux, FreeBSD and Windows are supported at this time.")
endif()

# Search for the required libraries, erroring out if they aren't found
find_library(JANSSON_LIB NAMES jansson)
find_package(CURL REQUIRED)
# Add the include directories for the libraries
include_directories(${CURL_INCLUDE_DIRS})

add_library(framebot_ SHARED framebot.c memory.c objects.c json.c network.c format.c util.c)
target_link_libraries(framebot_ jansson libcurl.so)
target_link_libraries(framebot_ ${JANSSON_LIB} ${CURL_LIBRARIES})

add_library(framebot STATIC framebot.c memory.c objects.c json.c network.c format.c util.c)
target_link_libraries(framebot jansson libcurl.so)

if(${OS_FREEBSD})
# The default FreeBSD include path
target_compile_options(framebot_ PUBLIC -I/usr/local/include)
target_compile_options(framebot PUBLIC -I/usr/local/include)
endif()
target_link_libraries(framebot ${JANSSON_LIB} ${CURL_LIBRARIES})

install(TARGETS framebot_ LIBRARY DESTINATION lib)
install(TARGETS framebot ARCHIVE DESTINATION lib)

if(DEBUG EQUAL 1)
add_definitions("-g")
add_definitions("-Wall")
Expand Down
57 changes: 24 additions & 33 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ include_directories (${PROJECT_SOURCE_DIR}/../include)

add_definitions("-g")

set(OS_LINUX CMAKE_SYSTEM_NAME STREQUAL Linux)
set(OS_FREEBSD CMAKE_SYSTEM_NAME STREQUAL FreeBSD)

if(${OS_FREEBSD})
# Add /usr/local/lib so we can find the libs on FreeBSD
link_directories(/usr/local/lib /usr/lib /lib)
if(UNIX)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
# This is probably an unsupported BSD or OSX.
# Show an error, but try to proceed.
message(SEND_ERROR "Only Linux, FreeBSD and Windows are supported at this time.")
endif()

# Search for the required libraries, erroring out if they aren't found
find_library(JANSSON_LIB NAMES jansson)
find_package(CURL REQUIRED)
# Add the include directories for the libraries
include_directories(${CURL_INCLUDE_DIRS})
endif()

add_executable(methods_chat test_chat.c)
Expand All @@ -25,33 +31,18 @@ add_executable(sendvoice test_sendvoice.c)
add_executable(sendvideonote test_sendvideonote.c)
add_executable(sendmessage test_sendmessage.c)

if(${OS_FREEBSD})
# The default FreeBSD include path
target_compile_options(methods_chat PUBLIC -I/usr/local/include)
target_compile_options(update PUBLIC -I/usr/local/include)
target_compile_options(file PUBLIC -I/usr/local/include)
target_compile_options(userprofilephotos PUBLIC -I/usr/local/include)
target_compile_options(sendphotos PUBLIC -I/usr/local/include)
target_compile_options(sendaudio PUBLIC -I/usr/local/include)
target_compile_options(senddocument PUBLIC -I/usr/local/include)
target_compile_options(sendvideo PUBLIC -I/usr/local/include)
target_compile_options(sendvoice PUBLIC -I/usr/local/include)
target_compile_options(sendvideonote PUBLIC -I/usr/local/include)
target_compile_options(sendmessage PUBLIC -I/usr/local/include)
endif()

if (${OS_LINUX} OR ${OS_FREEBSD})
target_link_libraries(methods_chat jansson libcurl.so framebot)
target_link_libraries(update jansson libcurl.so framebot)
target_link_libraries(file jansson libcurl.so framebot)
target_link_libraries(userprofilephotos jansson libcurl.so framebot)
target_link_libraries(sendphotos jansson libcurl.so framebot)
target_link_libraries(sendaudio jansson libcurl.so framebot)
target_link_libraries(senddocument jansson libcurl.so framebot)
target_link_libraries(sendvideo jansson libcurl.so framebot)
target_link_libraries(sendvoice jansson libcurl.so framebot)
target_link_libraries(sendvideonote jansson libcurl.so framebot)
target_link_libraries(sendmessage jansson libcurl.so framebot)
if (UNIX)
target_link_libraries(methods_chat ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(update ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(file ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(userprofilephotos ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendphotos ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendaudio ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(senddocument ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendvideo ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendvoice ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendvideonote ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
target_link_libraries(sendmessage ${JANSSON_LIB} ${CURL_LIBRARIES} framebot)
endif ()

if (WIN32)
Expand Down

0 comments on commit d234c97

Please sign in to comment.