Skip to content

Commit ec3a29f

Browse files
committed
CMake - Introduce FindPackage script for unirec++ library
TG-35
1 parent 3b2375c commit ec3a29f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

cmake/dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ find_package(Python3 REQUIRED COMPONENTS Development NumPy)
44

55
if(BUILD_WITH_UNIREC)
66
find_package(UNIREC 3.0.0 REQUIRED)
7+
find_package(UNIREC++ 3.2.0 REQUIRED)
78
endif()
89

910
# Set define for none depricated API for NUMPY

cmake/modules/FindUNIREC++.cmake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Find the Unirec++ includes and library
2+
#
3+
# This module defines the following IMPORTED targets:
4+
#
5+
# unirec::unirec++ - The "unirec++" library, if found.
6+
#
7+
# This module will set the following variables in your project:
8+
#
9+
# UNIREC++_INCLUDE_DIRS - where to find <unirec++/unirec++.hpp>, etc.
10+
# UNIREC++_LIBRARIES - List of libraries when using unirec++.
11+
# UNIREC++_FOUND - True if the unirec++ library has been found.
12+
13+
# Use pkg-config (if available) to get the library directories and then use
14+
# these values as hints for find_path() and find_library() functions.
15+
find_package(PkgConfig QUIET)
16+
if (PKG_CONFIG_FOUND)
17+
pkg_check_modules(PC_UNIREC++ QUIET unirec++)
18+
endif()
19+
20+
find_path(
21+
UNIREC++_INCLUDE_DIR unirec++
22+
HINTS ${PC_UNIREC++_INCLUDEDIR} ${PC_UNIREC++_INCLUDE_DIRS}
23+
PATH_SUFFIXES include
24+
)
25+
26+
find_library(
27+
UNIREC++_LIBRARY NAMES unirec++
28+
HINTS ${PC_UNIREC++_LIBDIR} ${PC_UNIREC++_LIBRARY_DIRS}
29+
PATH_SUFFIXES lib lib64
30+
)
31+
32+
if (PC_UNIREC++_VERSION)
33+
# Version extracted from pkg-config
34+
set(UNIREC++_VERSION_STRING ${PC_UNIREC++_VERSION})
35+
endif()
36+
37+
# Handle find_package() arguments (i.e. QUIETLY and REQUIRED) and set
38+
# UNIREC++_FOUND to TRUE if all listed variables are filled.
39+
include(FindPackageHandleStandardArgs)
40+
find_package_handle_standard_args(
41+
UNIREC++
42+
REQUIRED_VARS UNIREC++_LIBRARY UNIREC++_INCLUDE_DIR
43+
VERSION_VAR UNIREC++_VERSION_STRING
44+
)
45+
46+
set(UNIREC++_INCLUDE_DIRS ${UNIREC++_INCLUDE_DIR})
47+
set(UNIREC++_LIBRARIES ${UNIREC++_LIBRARY})
48+
mark_as_advanced(UNIREC++_INCLUDE_DIR UNIREC++_LIBRARY)
49+
50+
if (UNIREC++_FOUND)
51+
# Create imported library with all dependencies
52+
if (NOT TARGET unirec::unirec++ AND EXISTS "${UNIREC++_LIBRARIES}")
53+
add_library(unirec::unirec++ UNKNOWN IMPORTED)
54+
set_target_properties(unirec::unirec++ PROPERTIES
55+
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
56+
IMPORTED_LOCATION "${UNIREC++_LIBRARIES}"
57+
INTERFACE_INCLUDE_DIRECTORIES "${UNIREC++_INCLUDE_DIRS}")
58+
endif()
59+
endif()

0 commit comments

Comments
 (0)