2 # - Find libsinsp and libscap
3 # Find libsinsp and libscap includes and libraries.
4 # Adapted from FindZSTD.cmake.
6 # This module will look for libsinsp and libscap using pkg-config. If that
7 # fails, it will search ${SINSP_INCLUDEDIR} and ${SINSP_HINTS}/include
8 # for the libsinsp and libscap include directory and ${SINSP_LIBDIR} and
9 # ${SINSP_HINTS}/lib for the libsinsp and libscap libraries.
11 # It will set the following variables:
13 # SINSP_FOUND - True if libsinsp found.
14 # SINSP_INCLUDE_DIRS - Where to find sinsp.h, scap.h, etc.
15 # SINSP_LINK_LIBRARIES - List of libraries when using libsinsp.
17 # You must manually set the following variables:
18 # FALCO_PLUGINS - Paths to plugins built from https://github.com/falcosecurity/plugins/.
21 # SINSP_DLL_DIR - (Windows) Path to the libsinsp and libscap DLLs
22 # SINSP_DLL - (Windows) Name of the libsinsp and libscap DLLs
24 include( FindWSWinLibs )
25 FindWSWinLibs( "falcosecurity-libs-.*" SINSP_HINTS )
27 include(CMakeDependentOption)
29 if( NOT USE_REPOSITORY)
30 find_package(PkgConfig)
31 pkg_check_modules(SINSP libsinsp)
34 # Include both legacy (#include <sinsp.h>) and current (#include <libsinsp/sinsp.h>) paths for now.
36 # We're likely building on Windows since libsinsp and libscap ship with .pc modules.
37 # We might want to dispense with this and use pkg_check_modules exclusively, but that
38 # would require adding pkg-config to the Windows build and ensuring that the .pc files
39 # we ship are discoverable and valid.
40 find_path(_sinsp_include_dirs NO_CACHE
41 NAMES libsinsp/sinsp.h
42 HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include"
43 PATH_SUFFIXES falcosecurity
47 if(_sinsp_include_dirs)
48 list(APPEND _sinsp_include_dirs ${_sinsp_include_dirs}/libsinsp)
51 find_path(_scap_include_dir NO_CACHE
53 HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include"
54 PATH_SUFFIXES falcosecurity/libscap
59 list(APPEND _sinsp_include_dirs ${_scap_include_dir})
61 unset(_scap_include_dir)
63 find_library(_sinsp_link_libs NO_CACHE
65 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib"
71 if (NOT SINSP_VERSION)
72 find_file(_sinsp_pkgconfig NO_CACHE
74 PATHS "${SINSP_LIBDIR}/pkgconfig" "${SINSP_HINTS}/lib/pkgconfig"
77 file(READ ${_sinsp_pkgconfig} _sinsp_pkgconfig_contents)
78 string(REGEX MATCH "Version: *([0-9.]+)" _ ${_sinsp_pkgconfig_contents})
79 set(SINSP_VERSION ${CMAKE_MATCH_1})
80 unset(_sinsp_pkgconfig_contents)
82 unset(_sinsp_pkgconfig)
90 scap_engine_source_plugin
91 scap_engine_test_input
97 foreach(_scap_lib ${_scap_libs})
98 find_library(_lib NO_CACHE
100 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib"
106 list(APPEND _sinsp_link_libs ${_lib})
113 find_path(_jsoncpp_include_dir NO_CACHE
115 HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include"
116 PATH_SUFFIXES falcosecurity jsoncpp
121 if (_jsoncpp_include_dir)
122 list(APPEND _sinsp_include_dirs ${_jsoncpp_include_dir})
123 unset(_jsoncpp_include_dir)
126 find_library(_jsoncpp_lib NO_CACHE
128 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" "${SINSP_HINTS}/lib/falcosecurity"
134 list(APPEND _sinsp_link_libs ${_jsoncpp_lib})
138 find_library(_re2_lib NO_CACHE
140 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" "${SINSP_HINTS}/lib/falcosecurity"
146 list(APPEND _sinsp_link_libs ${_re2_lib})
150 find_path(_tbb_include_dir NO_CACHE
152 HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include"
157 if (_tbb_include_dir)
158 list(APPEND _sinsp_include_dirs ${_tbb_include_dir})
159 unset(_tbb_include_dir)
162 find_library(_tbb_lib NO_CACHE
164 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" "${SINSP_HINTS}/lib/falcosecurity"
170 list(APPEND _sinsp_link_libs ${_tbb_lib})
174 # This is terrible, but libsinsp/libscap doesn't support dynamic linking on Windows (yet).
175 find_path(_zlib_include_dir NO_CACHE
177 HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include"
182 if (_zlib_include_dir)
183 list(APPEND _sinsp_include_dirs ${_zlib_include_dir})
184 unset(_zlib_include_dir)
187 find_library(_zlib_lib NO_CACHE
189 HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" "${SINSP_HINTS}/lib/falcosecurity"
195 list(APPEND _sinsp_link_libs ${_zlib_lib})
199 if(_sinsp_include_dirs AND _sinsp_link_libs)
200 list(REMOVE_DUPLICATES _sinsp_include_dirs)
201 set(SINSP_INCLUDE_DIRS ${_sinsp_include_dirs} CACHE PATH "Paths to libsinsp and libscap headers")
202 set(SINSP_LINK_LIBRARIES ${_sinsp_link_libs} CACHE PATH "Paths to libsinsp, libscap, etc.")
204 unset(_sinsp_include_dirs)
205 unset(_sinsp_link_libs)
210 # As https://cmake.org/cmake/help/latest/command/link_directories.html
211 # says, "Prefer to pass full absolute paths to libraries where possible,
212 # since this ensures the correct library will always be linked," so use
213 # SINSP_LINK_LIBRARIES instead of SINSP_LIBRARIES
214 # XXX SINSP_VERSION will require peeking for a #define or something similar.
215 include(FindPackageHandleStandardArgs)
216 find_package_handle_standard_args(Sinsp
220 VERSION_VAR SINSP_VERSION
224 if (SINSP_VERSION VERSION_EQUAL 0.0.0)
225 # https://github.com/falcosecurity/libs/blob/master/README.md#versioning
226 message(WARNING "libsinsp version is 0.0.0. If you built it outside of git, did you set FALCOSECURITY_LIBS_VERSION?")
229 string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${SINSP_VERSION})
230 # Should we cache these?
231 set(SINSP_VERSION_MAJOR ${CMAKE_MATCH_1})
232 set(SINSP_VERSION_MINOR ${CMAKE_MATCH_2})
233 set(SINSP_VERSION_MICRO ${CMAKE_MATCH_3})
235 # set ( SINSP_DLL_DIR "${SINSP_HINTS}/bin"
236 # CACHE PATH "Path to sinsp DLL"
238 # file( GLOB _SINSP_dll RELATIVE "${SINSP_DLL_DIR}"
239 # "${SINSP_DLL_DIR}/sinsp*.dll"
241 # set ( SINSP_DLL ${_SINSP_dll}
242 # # We're storing filenames only. Should we use STRING instead?
243 # CACHE FILEPATH "sinsp DLL file name"
245 # mark_as_advanced( SINSP_DLL_DIR SINSP_DLL )
248 set(SINSP_INCLUDE_DIRS)
249 set(SINSP_LINK_LIBRARIES)
251 set(SINSP_VERSION_MAJOR)
252 set(SINSP_VERSION_MINOR)
253 set(SINSP_VERSION_MICRO)
256 mark_as_advanced(SINSP_INCLUDE_DIRS SINSP_LINK_LIBRARIES)
261 if(WIN32 AND SINSP_FOUND AND NOT FALCO_PLUGINS)
262 FindWSWinLibs( "falcosecurity-plugins-.*" _falco_plugin_dir)
263 if(_falco_plugin_dir)
264 file( GLOB _falco_plugins LIST_DIRECTORIES false "${_falco_plugin_dir}/*.dll" )
265 unset(_falco_plugin_dir)
269 # XXX It looks like we can either autodiscover this value or provide an option but not both.
271 set(FALCO_PLUGINS ${_falco_plugins} CACHE FILEPATH "Paths to Falco plugins. Semicolon-separated")
272 unset(_falco_plugins)
274 cmake_dependent_option(FALCO_PLUGINS "Paths to Falco plugins. Semicolon-separated" "" "SINSP_FOUND" "")