Skip to content

Commit fc9ee68

Browse files
committed
Unirec output: improved detection of libtrap and libunirec (added version extraction)
1 parent 9b382a5 commit fc9ee68

File tree

5 files changed

+86
-45
lines changed

5 files changed

+86
-45
lines changed

extra_plugins/output/unirec/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
2121
# Find IPFIXcol and libnf
2222
find_package(IPFIXcol2 2.0.0 REQUIRED)
2323
find_package(LibTrap REQUIRED)
24-
find_package(Unirec REQUIRED)
24+
find_package(LibUnirec REQUIRED)
2525

2626
# Set default build type if not specified by user
2727
if (NOT CMAKE_BUILD_TYPE)
@@ -49,7 +49,7 @@ configure_file(
4949
include_directories(
5050
"${IPFIXCOL2_INCLUDE_DIRS}" # IPFIXcol2 header files
5151
"${LIBTRAP_INCLUDE_DIRS}" # libtrap header files
52-
"${UNIREC_INCLUDE_DIRS}" # unirec header files
52+
"${LIBUNIREC_INCLUDE_DIRS}" # unirec header files
5353
)
5454

5555
# Create a linkable module
@@ -67,7 +67,7 @@ add_library(unirec-output MODULE
6767

6868
target_link_libraries(unirec-output
6969
${LIBTRAP_LIBRARIES} # libtrap
70-
${UNIREC_LIBRARIES} # unirec
70+
${LIBUNIREC_LIBRARIES} # unirec
7171
m # standard math library
7272
)
7373

extra_plugins/output/unirec/CMakeModules/FindLibTrap.cmake

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,53 @@
55

66
# use pkg-config to get the directories and then use these values
77
# in the find_path() and find_library() calls
8-
find_package(PkgConfig)
9-
pkg_check_modules(PC_LIBTRAP QUIET LibTrap)
8+
find_package(PkgConfig QUIET)
9+
if (PKG_CONFIG_FOUND)
10+
pkg_check_modules(PC_LIBTRAP QUIET "libtrap")
11+
endif()
1012
set(LIBTRAP_DEFINITIONS ${PC_LIBTRAP_CFLAGS_OTHER})
1113

1214
find_path(
13-
LIBTRAP_INCLUDE_DIR trap.h
15+
LIBTRAP_INCLUDE_DIR libtrap/trap.h
1416
HINTS ${PC_LIBTRAP_INCLUDEDIR} ${PC_LIBTRAP_INCLUDE_DIRS}
15-
PATH_SUFFIXES include/libtrap
17+
PATH_SUFFIX include
1618
)
1719

1820
find_library(
19-
LIBTRAP_LIBRARY NAMES trap
21+
LIBTRAP_LIBRARY NAMES trap libtrap
2022
HINTS ${PC_LIBTRAP_LIBDIR} ${PC_LIBTRAP_LIBRARY_DIRS}
2123
PATH_SUFFIXES lib lib64
2224
)
2325

24-
# handle the QUIETLY and REQUIRED arguments and set LIBLIBTRAP_FOUND to TRUE
26+
if (PC_LIBTRAP_VERSION)
27+
# Version extracted from pkg-config
28+
set(LIBTRAP_VERSION_STRING ${PC_LIBTRAP_VERSION})
29+
elseif (LIBTRAP_INCLUDE_DIR AND LIBTRAP_LIBRARY)
30+
# Try to get the version of the installed library
31+
try_run(
32+
TRAP_RES_RUN TRAP_RES_COMP
33+
${CMAKE_CURRENT_BINARY_DIR}/try_run/trap_version_test/
34+
${PROJECT_SOURCE_DIR}/CMakeModules/try_run/trap_version.c
35+
CMAKE_FLAGS
36+
-DLINK_LIBRARIES=${LIBTRAP_LIBRARY}
37+
-DINCLUDE_DIRECTORIES=${LIBTRAP_INCLUDE_DIR}
38+
RUN_OUTPUT_VARIABLE LIBTRAP_VERSION_VAR
39+
)
40+
41+
if (TRAP_RES_COMP AND TRAP_RES_RUN EQUAL 0)
42+
# Successfully compiled and executed with return code 0
43+
set(LIBTRAP_VERSION_STRING ${LIBTRAP_VERSION_VAR})
44+
endif()
45+
endif()
46+
47+
# handle the QUIETLY and REQUIRED arguments and set LIBTRAP_FOUND to TRUE
2548
# if all listed variables are TRUE
2649
include(FindPackageHandleStandardArgs)
27-
find_package_handle_standard_args(libtrap
50+
find_package_handle_standard_args(LibTrap
2851
REQUIRED_VARS LIBTRAP_LIBRARY LIBTRAP_INCLUDE_DIR
2952
VERSION_VAR LIBTRAP_VERSION_STRING
3053
)
3154

3255
set(LIBTRAP_LIBRARIES ${LIBTRAP_LIBRARY})
3356
set(LIBTRAP_INCLUDE_DIRS ${LIBTRAP_INCLUDE_DIR})
34-
mark_as_advanced(LIBTRAP_INCLUDE_DIR LIBTRAP_LIBRARIES)
57+
mark_as_advanced(LIBTRAP_INCLUDE_DIR LIBTRAP_LIBRARY)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# LIBUNIREC_FOUND - System has libfds
2+
# LIBUNIREC_INCLUDE_DIRS - The libfds include directories
3+
# LIBUNIREC_LIBRARIES - The libraries needed to use libfds
4+
# LIBUNIREC_DEFINITIONS - Compiler switches required for using libfds
5+
6+
# use pkg-config to get the directories and then use these values
7+
# in the find_path() and find_library() calls
8+
find_package(PkgConfig QUIET)
9+
if (PKG_CONFIG_FOUND)
10+
pkg_check_modules(PC_UNIREC QUIET "unirec")
11+
endif()
12+
set(LIBUNIREC_DEFINITIONS ${PC_UNIREC_CFLAGS_OTHER})
13+
14+
find_path(
15+
UNIREC_INCLUDE_DIR unirec/unirec.h
16+
HINTS ${PC_UNIREC_INCLUDEDIR} ${PC_UNIREC_INCLUDE_DIRS}
17+
PATH_SUFFIXES include
18+
)
19+
20+
find_library(
21+
UNIREC_LIBRARY NAMES unirec libunirec
22+
HINTS ${PC_UNIREC_LIBDIR} ${PC_UNIREC_LIBRARY_DIRS}
23+
PATH_SUFFIXES lib lib64
24+
)
25+
26+
if (PC_UNIREC_VERSION)
27+
# Version extracted from pkg-config
28+
set(UNIREC_VERSION_STRING ${PC_UNIREC_VERSION})
29+
endif()
30+
31+
32+
# handle the QUIETLY and REQUIRED arguments and set LIBUNIREC_FOUND to TRUE
33+
# if all listed variables are TRUE
34+
include(FindPackageHandleStandardArgs)
35+
find_package_handle_standard_args(LibUnirec
36+
REQUIRED_VARS UNIREC_LIBRARY UNIREC_INCLUDE_DIR
37+
VERSION_VAR UNIREC_VERSION_STRING
38+
)
39+
40+
set(LIBUNIREC_LIBRARIES ${UNIREC_LIBRARY})
41+
set(LIBUNIREC_INCLUDE_DIRS ${UNIREC_INCLUDE_DIR})
42+
mark_as_advanced(UNIREC_INCLUDE_DIR UNIREC_LIBRARY)

extra_plugins/output/unirec/CMakeModules/FindUnirec.cmake

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <libtrap/trap.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
int
6+
main(int argc, char *argv[])
7+
{
8+
printf("%s", trap_version);
9+
return EXIT_SUCCESS;
10+
}

0 commit comments

Comments
 (0)