Skip to content

Commit

Permalink
Merge pull request #1502 from rschwebel/rsc/introduce-pkg-config
Browse files Browse the repository at this point in the history
Use pkg-config to find libraries and include files
  • Loading branch information
kzangeli authored Apr 3, 2024
2 parents aee2253 + e9cc365 commit afeff9c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 136 deletions.
34 changes: 14 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
PROJECT(orionld)
cmake_minimum_required(VERSION 3.5)

find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread filesystem system regex)
pkg_check_modules(LIBMONGOC REQUIRED libmongoc-1.0)
pkg_check_modules(LIBBSON REQUIRED libbson-1.0)
pkg_check_modules(LIBMICROHTTPD REQUIRED libmicrohttpd)
pkg_check_modules(GNUTLS REQUIRED gnutls)

#
# DEBUG or RELEASE build ?
#
Expand Down Expand Up @@ -252,23 +259,8 @@ SET (ORION_LIBS
pa
)

SET (BOOST
boost_thread
boost_filesystem
boost_system
boost_regex
)

SET (BOOST_MT
boost_thread-mt
boost_filesystem-mt
boost_system-mt
boost_regex-mt
)

# Static libs common to orionld and unitTest binaries
SET (COMMON_STATIC_LIBS
microhttpd.a
mongoclient.a
kjson.a
khash.a
Expand All @@ -280,7 +272,7 @@ SET (DYNAMIC_LIBS
prom
promhttp
curl
gnutls
${GNUTLS_LIBRARIES}
pthread
gcrypt
ssl
Expand All @@ -294,8 +286,8 @@ SET (DYNAMIC_LIBS
resolv
paho-mqtt3c
pq # for TRoE & Postgres
libmongoc-1.0.so
libbson-1.0.so
${LIBMONGOC_LIBRARIES}
${LIBBSON_LIBRARIES}
)

#
Expand All @@ -314,8 +306,8 @@ endif (UNIT_TEST)
# Common include
#
include_directories("/usr/include")
include_directories("/usr/local/include/libbson-1.0")
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("${LIBBSON_INCLUDE_DIRS}")
include_directories("${LIBMONGOC_INCLUDE_DIRS}")
include_directories("${PROJECT_SOURCE_DIR}/..")
include_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/prom/include")
include_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/promhttp/include")
Expand All @@ -337,6 +329,8 @@ link_directories("${PROJECT_SOURCE_DIR}/../kbase")
link_directories("${PROJECT_SOURCE_DIR}/../khash")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/prom/build")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/promhttp/build")
link_directories("${LIBMONGOC_LIBRARY_DIRS}")
link_directories("${GNUTLS_LIBRARY_DIRS}")

#
# Enabling test harness
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-ubi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WORKDIR ${PATH_TO_SRC}
RUN pwd
RUN ls -l ../

RUN make release install
RUN PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH make release install

RUN strip /usr/bin/orionld

Expand Down
1 change: 1 addition & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set -e

export ROOT='/opt'
export BROKER='orionld'
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH
REV_DEFAULT='develop'
REPOSITORY_DEFAULT='https://github.com/fiware/context.Orion-LD'
STAGE_DEFAULT='release'
Expand Down
44 changes: 9 additions & 35 deletions src/app/contextBroker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,21 @@ include_directories("${PROJECT_SOURCE_DIR}/src/lib")
link_directories("/usr/local/lib/")
link_directories("/usr/lib64/")
link_directories("/usr/lib/x86_64-linux-gnu")

link_directories("${Boost_LIBRARY_DIRS}")
link_directories("${LIBMICROHTTPD_LIBRARY_DIRS}")


# Executable declaration
# ------------------------------------------------------------

ADD_EXECUTABLE(contextBroker ${SOURCES} ${HEADERS})

MESSAGE("contextBroker distro: '${DISTRO}'")

# The following ones are distros that we have checked are built correctly

IF(${DISTRO} MATCHES "CentOS_6.*")
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "CentOS_7.*")
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "Debian_.*")
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})

# The following ones are distros that haven't been checked since the refactoring in
# PR #2062. They should be "promoted" as soon as we have positive feedback about
# them or fixed (maybe based in the version of this file previous to
# the aforementioned PR)

ELSEIF ((${DISTRO} STREQUAL "Ubuntu_13.04") OR (${DISTRO} STREQUAL "Ubuntu_12.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_12.04.2_LTS"))
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF((${DISTRO} STREQUAL "Ubuntu_13.10") OR (${DISTRO} STREQUAL "Ubuntu_14.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.10"))
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF((${DISTRO} STREQUAL "Ubuntu_14.04.2_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.3_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.4_LTS") OR (${DISTRO} MATCHES "Linux_Mint_.*"))
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "openSUSE_13.1")
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Fedora_20")
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})

# Finally this is a "best effort" option to try to build on distros that don't have a
# specify switch

ELSE()
TARGET_LINK_LIBRARIES(contextBroker ${STATIC_LIBS} -lmongoclient ${BOOST} ${DYNAMIC_LIBS})
ENDIF()
TARGET_LINK_LIBRARIES(contextBroker
${STATIC_LIBS}
${DYNAMIC_LIBS}
-lmongoclient
${Boost_LIBRARIES}
${LIBMICROHTTPD_LIBRARIES}
)

IF (${DISTRO} MATCHES "Ubuntu.*")
MESSAGE("contextBroker: INSTALL Ubuntu DISTRO: '${DISTRO}'")
Expand Down
48 changes: 9 additions & 39 deletions src/app/orionld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,19 @@ include_directories("${PROJECT_SOURCE_DIR}/src/lib")
link_directories("/usr/local/lib/")
link_directories("/usr/lib64/")
link_directories("/usr/lib/x86_64-linux-gnu")


link_directories("${Boost_LIBRARY_DIRS}")
link_directories("${LIBMICROHTTPD_LIBRARY_DIRS}")

# Executable declaration
# ------------------------------------------------------------

ADD_EXECUTABLE(orionld ${SOURCES} ${HEADERS})

MESSAGE("orionld distro: '${DISTRO}'")

# The following ones are distros that we have checked are built correctly

IF(${DISTRO} MATCHES "CentOS_6.*")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "CentOS_7.*")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "Debian_.*")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})

# The following ones are distros that haven't been checked since the refactoring in
# PR #2062. They should be "promoted" as soon as we have positive feedback about
# them or fixed (maybe based in the version of this file previous to
# the aforementioned PR)

ELSEIF ((${DISTRO} STREQUAL "Ubuntu_13.04") OR (${DISTRO} STREQUAL "Ubuntu_12.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_12.04.2_LTS"))
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF((${DISTRO} STREQUAL "Ubuntu_13.10") OR (${DISTRO} STREQUAL "Ubuntu_14.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.10"))
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF((${DISTRO} STREQUAL "Ubuntu_14.04.2_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.3_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.4_LTS") OR (${DISTRO} MATCHES "Linux_Mint_.*"))
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "openSUSE_13.1")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Fedora_20")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Ubuntu_22.04.2_LTS")
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})

# Finally this is a "best effort" option to try to build on distros that don't have a
# specify switch

ELSE()
TARGET_LINK_LIBRARIES(orionld ${STATIC_LIBS} -lmongoclient ${BOOST} ${DYNAMIC_LIBS})
ENDIF()
TARGET_LINK_LIBRARIES(orionld
${STATIC_LIBS}
${DYNAMIC_LIBS}
-lmongoclient
${Boost_LIBRARIES}
${LIBMICROHTTPD_LIBRARIES}
)

IF (${DISTRO} MATCHES "Ubuntu.*")
MESSAGE("orionld: INSTALL Ubuntu DISTRO: '${DISTRO}'")
Expand Down
54 changes: 13 additions & 41 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ SET (STATIC_LIBS
# Include directories
# ------------------------------------------------------------
include_directories("/usr/include")
include_directories("/usr/local/include/libbson-1.0")
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("${LIBBSON_INCLUDE_DIRS}")
include_directories("${LIBMONGOC_INCLUDE_DIRS}")
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/src/lib")
include_directories("${PROJECT_SOURCE_DIR}/src/app")
Expand All @@ -177,13 +177,16 @@ include_directories("${PROJECT_SOURCE_DIR}/..")
link_directories("/usr/local/lib/")
link_directories("/usr/lib64/")
link_directories("/usr/lib/x86_64-linux-gnu")
link_directories("${Boost_LIBRARY_DIRS}")
link_directories("${LIBMONGOC_LIBRARY_DIRS}")
link_directories("${PROJECT_SOURCE_DIR}/../kjson")
link_directories("${PROJECT_SOURCE_DIR}/../kalloc")
link_directories("${PROJECT_SOURCE_DIR}/../kbase")
link_directories("${PROJECT_SOURCE_DIR}/../khash")
link_directories("${PROJECT_SOURCE_DIR}/../klog")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/prom/build")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/promhttp/build")
link_directories("${LIBMICROHTTPD_LIBRARY_DIRS}")



Expand All @@ -197,46 +200,15 @@ add_definitions(-DUNIT_TEST)
# ------------------------------------------------------------

ADD_EXECUTABLE(unitTest ${SOURCES})
TARGET_LINK_LIBRARIES(unitTest
${STATIC_LIBS}
${Boost_LIBRARIES}
${LIBMICROHTTPD_LIBRARIES}
${DYNAMIC_LIBS}
)

MESSAGE("unitTest distro: '${DISTRO}'")

# The following ones are distros that we have checked are built correctly

IF(${DISTRO} MATCHES "CentOS_6.*")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "Debian_8.*")
# It seems that Debian 8.x doesn't like -mt libraries for unit tests... not sure about other Debian versions
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "Debian_9.*")
# Debian9 just like Debian8 doesn't like -mt libraries for unit tests
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} MATCHES "Debian_.*")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})

# The following ones are distros that haven't been checked since the refactoring in
# PR #2062. They should be "promoted" as soon as we have positive feedback about
# them or fixed (maybe based in the version of this file previous to
# the aforementioned PR)

ELSEIF ((${DISTRO} STREQUAL "Ubuntu_13.04") OR (${DISTRO} STREQUAL "Ubuntu_12.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_12.04.2_LTS"))
IF ((${DISTRO} STREQUAL "Ubuntu_13.04") OR (${DISTRO} STREQUAL "Ubuntu_12.04.1_LTS") OR (${DISTRO} STREQUAL "Ubuntu_12.04.2_LTS"))
# Pending to check after the refactor
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion-null")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Ubuntu_13.10")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Ubuntu_14.04.1_LTS")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF((${DISTRO} STREQUAL "Ubuntu_14.04.2_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.3_LTS") OR (${DISTRO} STREQUAL "Ubuntu_14.04.4_LTS"))
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "Ubuntu_14.10")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ELSEIF(${DISTRO} STREQUAL "openSUSE_12.3")
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST_MT} ${DYNAMIC_LIBS})

# Finally this is a "best effort" option to try to build on distros that don't have a
# specify switch

ELSE()
# Pending to check after the refactor
TARGET_LINK_LIBRARIES(unitTest ${STATIC_LIBS} ${BOOST} ${DYNAMIC_LIBS})
ENDIF()

0 comments on commit afeff9c

Please sign in to comment.