From e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 22:34:10 +0200 Subject: Adding upstream version 4.2.2. Signed-off-by: Daniel Baumann --- cmake/modules/.editorconfig | 15 ++ cmake/modules/COPYING-CMAKE-SCRIPTS | 25 +++ cmake/modules/CheckCLinkerFlag.cmake | 57 +++++ cmake/modules/FindAIRPCAP.cmake | 61 ++++++ cmake/modules/FindAMRNB.cmake | 57 +++++ cmake/modules/FindAsciidoctor.cmake | 312 +++++++++++++++++++++++++++ cmake/modules/FindBCG729.cmake | 57 +++++ cmake/modules/FindBROTLI.cmake | 50 +++++ cmake/modules/FindCAP.cmake | 40 ++++ cmake/modules/FindCARES.cmake | 81 +++++++ cmake/modules/FindChocolatey.cmake | 22 ++ cmake/modules/FindDOXYGEN.cmake | 47 +++++ cmake/modules/FindFseeko.cmake | 85 ++++++++ cmake/modules/FindGCRYPT.cmake | 89 ++++++++ cmake/modules/FindGLIB2.cmake | 205 ++++++++++++++++++ cmake/modules/FindGMODULE2.cmake | 48 +++++ cmake/modules/FindGNUTLS.cmake | 92 ++++++++ cmake/modules/FindGTHREAD2.cmake | 48 +++++ cmake/modules/FindILBC.cmake | 77 +++++++ cmake/modules/FindKERBEROS.cmake | 126 +++++++++++ cmake/modules/FindLEX.cmake | 46 ++++ cmake/modules/FindLFS.cmake | 153 ++++++++++++++ cmake/modules/FindLIBSSH.cmake | 109 ++++++++++ cmake/modules/FindLZ4.cmake | 74 +++++++ cmake/modules/FindLibXml2.cmake | 124 +++++++++++ cmake/modules/FindLua.cmake | 243 +++++++++++++++++++++ cmake/modules/FindM.cmake | 52 +++++ cmake/modules/FindMSVC_REDIST.cmake | 23 ++ cmake/modules/FindMaxMindDB.cmake | 75 +++++++ cmake/modules/FindMinizip.cmake | 81 +++++++ cmake/modules/FindNGHTTP2.cmake | 62 ++++++ cmake/modules/FindNGHTTP3.cmake | 62 ++++++ cmake/modules/FindNL.cmake | 144 +++++++++++++ cmake/modules/FindNSIS.cmake | 13 ++ cmake/modules/FindOPUS.cmake | 57 +++++ cmake/modules/FindPCAP.cmake | 329 +++++++++++++++++++++++++++++ cmake/modules/FindPCRE2.cmake | 102 +++++++++ cmake/modules/FindPortableApps.cmake | 26 +++ cmake/modules/FindPowerShell.cmake | 32 +++ cmake/modules/FindSBC.cmake | 51 +++++ cmake/modules/FindSETCAP.cmake | 19 ++ cmake/modules/FindSMI.cmake | 72 +++++++ cmake/modules/FindSNAPPY.cmake | 58 +++++ cmake/modules/FindSPANDSP.cmake | 66 ++++++ cmake/modules/FindSinsp.cmake | 176 +++++++++++++++ cmake/modules/FindSparkle.cmake | 51 +++++ cmake/modules/FindSpeexDSP.cmake | 58 +++++ cmake/modules/FindSystemd.cmake | 37 ++++ cmake/modules/FindVLD.cmake | 62 ++++++ cmake/modules/FindWSLibrary.cmake | 37 ++++ cmake/modules/FindWSWinLibs.cmake | 101 +++++++++ cmake/modules/FindWiX.cmake | 44 ++++ cmake/modules/FindWinSparkle.cmake | 56 +++++ cmake/modules/FindXSLTPROC.cmake | 152 +++++++++++++ cmake/modules/FindZLIB.cmake | 150 +++++++++++++ cmake/modules/FindZSTD.cmake | 73 +++++++ cmake/modules/LICENSE.txt | 57 +++++ cmake/modules/UseAsn2Wrs.cmake | 89 ++++++++ cmake/modules/UseCheckAPI.cmake | 41 ++++ cmake/modules/UseCustomIncludes.cmake | 18 ++ cmake/modules/UseExecutableResources.cmake | 26 +++ cmake/modules/UseLemon.cmake | 65 ++++++ cmake/modules/UseMakePluginReg.cmake | 17 ++ cmake/modules/UseMakeTaps.cmake | 15 ++ cmake/modules/WiresharkPlugin.cmake | 75 +++++++ cmake/modules/readme.txt | 3 + 66 files changed, 5070 insertions(+) create mode 100644 cmake/modules/.editorconfig create mode 100644 cmake/modules/COPYING-CMAKE-SCRIPTS create mode 100644 cmake/modules/CheckCLinkerFlag.cmake create mode 100644 cmake/modules/FindAIRPCAP.cmake create mode 100644 cmake/modules/FindAMRNB.cmake create mode 100644 cmake/modules/FindAsciidoctor.cmake create mode 100644 cmake/modules/FindBCG729.cmake create mode 100644 cmake/modules/FindBROTLI.cmake create mode 100644 cmake/modules/FindCAP.cmake create mode 100644 cmake/modules/FindCARES.cmake create mode 100644 cmake/modules/FindChocolatey.cmake create mode 100644 cmake/modules/FindDOXYGEN.cmake create mode 100644 cmake/modules/FindFseeko.cmake create mode 100644 cmake/modules/FindGCRYPT.cmake create mode 100644 cmake/modules/FindGLIB2.cmake create mode 100644 cmake/modules/FindGMODULE2.cmake create mode 100644 cmake/modules/FindGNUTLS.cmake create mode 100644 cmake/modules/FindGTHREAD2.cmake create mode 100644 cmake/modules/FindILBC.cmake create mode 100644 cmake/modules/FindKERBEROS.cmake create mode 100644 cmake/modules/FindLEX.cmake create mode 100644 cmake/modules/FindLFS.cmake create mode 100644 cmake/modules/FindLIBSSH.cmake create mode 100644 cmake/modules/FindLZ4.cmake create mode 100644 cmake/modules/FindLibXml2.cmake create mode 100644 cmake/modules/FindLua.cmake create mode 100644 cmake/modules/FindM.cmake create mode 100644 cmake/modules/FindMSVC_REDIST.cmake create mode 100644 cmake/modules/FindMaxMindDB.cmake create mode 100644 cmake/modules/FindMinizip.cmake create mode 100644 cmake/modules/FindNGHTTP2.cmake create mode 100644 cmake/modules/FindNGHTTP3.cmake create mode 100644 cmake/modules/FindNL.cmake create mode 100644 cmake/modules/FindNSIS.cmake create mode 100644 cmake/modules/FindOPUS.cmake create mode 100644 cmake/modules/FindPCAP.cmake create mode 100644 cmake/modules/FindPCRE2.cmake create mode 100644 cmake/modules/FindPortableApps.cmake create mode 100644 cmake/modules/FindPowerShell.cmake create mode 100644 cmake/modules/FindSBC.cmake create mode 100644 cmake/modules/FindSETCAP.cmake create mode 100644 cmake/modules/FindSMI.cmake create mode 100644 cmake/modules/FindSNAPPY.cmake create mode 100644 cmake/modules/FindSPANDSP.cmake create mode 100644 cmake/modules/FindSinsp.cmake create mode 100644 cmake/modules/FindSparkle.cmake create mode 100644 cmake/modules/FindSpeexDSP.cmake create mode 100644 cmake/modules/FindSystemd.cmake create mode 100644 cmake/modules/FindVLD.cmake create mode 100644 cmake/modules/FindWSLibrary.cmake create mode 100644 cmake/modules/FindWSWinLibs.cmake create mode 100644 cmake/modules/FindWiX.cmake create mode 100644 cmake/modules/FindWinSparkle.cmake create mode 100644 cmake/modules/FindXSLTPROC.cmake create mode 100644 cmake/modules/FindZLIB.cmake create mode 100644 cmake/modules/FindZSTD.cmake create mode 100644 cmake/modules/LICENSE.txt create mode 100644 cmake/modules/UseAsn2Wrs.cmake create mode 100644 cmake/modules/UseCheckAPI.cmake create mode 100644 cmake/modules/UseCustomIncludes.cmake create mode 100644 cmake/modules/UseExecutableResources.cmake create mode 100644 cmake/modules/UseLemon.cmake create mode 100644 cmake/modules/UseMakePluginReg.cmake create mode 100644 cmake/modules/UseMakeTaps.cmake create mode 100644 cmake/modules/WiresharkPlugin.cmake create mode 100644 cmake/modules/readme.txt (limited to 'cmake/modules') diff --git a/cmake/modules/.editorconfig b/cmake/modules/.editorconfig new file mode 100644 index 0000000..993ca32 --- /dev/null +++ b/cmake/modules/.editorconfig @@ -0,0 +1,15 @@ +[FindAsciidoctor.cmake] +indent_style = space +indent_size = 4 + +[FindSinsp.cmake] +indent_style = space +indent_size = 2 + +[FindSMI.cmake] +indent_style = space +indent_size = 2 + +[FindSPANDSP.cmake] +indent_style = space +indent_size = 2 diff --git a/cmake/modules/COPYING-CMAKE-SCRIPTS b/cmake/modules/COPYING-CMAKE-SCRIPTS new file mode 100644 index 0000000..45f01f8 --- /dev/null +++ b/cmake/modules/COPYING-CMAKE-SCRIPTS @@ -0,0 +1,25 @@ +Copyright notice for the files copied from +https://web.archive.org/web/20080613235159/http://www.opensync.org/browser/branches/3rd-party-cmake-modules/modules + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake/modules/CheckCLinkerFlag.cmake b/cmake/modules/CheckCLinkerFlag.cmake new file mode 100644 index 0000000..f21d573 --- /dev/null +++ b/cmake/modules/CheckCLinkerFlag.cmake @@ -0,0 +1,57 @@ +# - Check whether the C linker supports a given flag. +# CHECK_C_LINKER_FLAG(FLAG VARIABLE) +# +# FLAG - the compiler flag +# VARIABLE - variable to store the result +# +# This actually calls the check_c_source_compiles macro. +# See help for CheckCSourceCompiles for a listing of variables +# that can modify the build. + +# Copyright (c) 2010, Joerg Mayer (see AUTHORS file) +# +# Redistribution and use is allowed according to the terms of the BSD license. + +INCLUDE(CheckCSourceRuns) + +MACRO (CHECK_C_LINKER_FLAG _FLAG _RESULT) + # + # This is ugly. + # + # See CMake bug 0015934: + # + # https://cmake.org/Bug/view.php?id=15934 + # + # So we add the flags to CMAKE_REQUIRED_LIBRARIES, to sneak it into + # the linker flags. + # + # This may or may not work with versions earlier than 2.8.11, although + # 2.8.10's Xcode generator doesn't appear to work at all - it fails + # with an internal CMake error. + # + # With 3.2 and later, we could also set policy CMP0056 to NEW and + # set CMAKE_EXE_LINKER_FLAGS. + # + set(save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_LIBRARIES "${_FLAG}") + if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + # + # This means the linker is presumably the Microsoft linker; + # we need to pass /WX in order to have the linker fail, + # rather than just complaining and driving on, if it's + # passed a flag it doesn't handle. + # + set(CMAKE_REQUIRED_LIBRARIES "/WX ${CMAKE_REQUIRED_LIBRARIES}") + elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") + # + # We'll be running the linker through the compiler driver, so + # we may need to pass -Werror=unused-command-line-argument to have it + # fail, rather than just complaining and driving on, if it's + # passed a flag it doesn't handle. + set(CMAKE_REQUIRED_LIBRARIES + "-Werror=unused-command-line-argument ${CMAKE_REQUIRED_LIBRARIES}") + endif() + check_c_source_compiles("int main(void) { return 0;}" ${_RESULT}) + set(CMAKE_REQUIRED_LIBRARIES "${save_CMAKE_REQUIRED_LIBRARIES}") +ENDMACRO (CHECK_C_LINKER_FLAG) + diff --git a/cmake/modules/FindAIRPCAP.cmake b/cmake/modules/FindAIRPCAP.cmake new file mode 100644 index 0000000..a606f96 --- /dev/null +++ b/cmake/modules/FindAIRPCAP.cmake @@ -0,0 +1,61 @@ +# +# - Find airpcap +# Find the native AIRPCAP includes and library +# +# AIRPCAP_INCLUDE_DIRS - where to find pcap.h, etc. +# AIRPCAP_LIBRARIES - List of libraries when using pcap. +# AIRPCAP_FOUND - True if pcap found. +# AIRPCAP_DLL_DIR - (Windows) Path to the AirPcap DLL. +# AIRPCAP_DLL - (Windows) Name of the AirPcap DLL. + +include( FindWSWinLibs ) +FindWSWinLibs( "AirPcap" AIRPCAP_TMP_HINTS ) +#message( STATUS "AIRPCAP TMP HINTS: ${AIRPCAP_TMP_HINTS}" ) +FindWSWinLibs( "Airpcap_" AIRPCAP_HINTS "${AIRPCAP_TMP_HINTS}" ) +#message( STATUS "AIRPCAP HINTS: ${AIRPCAP_HINTS}" ) + +find_path( AIRPCAP_INCLUDE_DIR + NAMES + airpcap.h + pcap.h + HINTS + "${AIRPCAP_HINTS}/include" +) + +find_library( AIRPCAP_LIBRARY + NAMES + airpcap + HINTS + "${AIRPCAP_HINTS}/lib" +) + + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( AIRPCAP DEFAULT_MSG AIRPCAP_LIBRARY AIRPCAP_INCLUDE_DIR ) + +if( AIRPCAP_FOUND ) + set( AIRPCAP_INCLUDE_DIRS ${AIRPCAP_INCLUDE_DIR} ) + set( AIRPCAP_LIBRARIES ${AIRPCAP_LIBRARY} ) + if(WIN32) + set ( _platform_subdir "x86" ) + if( WIN32 AND "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64" ) + set ( _platform_subdir "x64" ) + endif() + + set ( AIRPCAP_DLL_DIR "${AIRPCAP_HINTS}/bin/${_platform_subdir}" + CACHE PATH "Path to AirPcap DLL" + ) + set ( AIRPCAP_DLL airpcap.dll + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "AirPcap DLL file name" + ) + mark_as_advanced( AIRPCAP_DLL_DIR AIRPCAP_DLL ) + endif() +else() + set( AIRPCAP_INCLUDE_DIRS ) + set( AIRPCAP_LIBRARIES ) + set( AIRPCAP_DLL_DIR ) + set( AIRPCAP_DLLS ) +endif() + +mark_as_advanced( AIRPCAP_LIBRARIES AIRPCAP_INCLUDE_DIRS ) diff --git a/cmake/modules/FindAMRNB.cmake b/cmake/modules/FindAMRNB.cmake new file mode 100644 index 0000000..f8928ca --- /dev/null +++ b/cmake/modules/FindAMRNB.cmake @@ -0,0 +1,57 @@ +# Find the system's opencore-amrnb includes and library +# +# AMRNB_INCLUDE_DIRS - where to find amrnb/decoder.h +# AMRNB_LIBRARIES - List of libraries when using amrnb +# AMRNB_FOUND - True if amrnb found +# AMRNB_DLL_DIR - (Windows) Path to the amrnb DLL +# AMRNB_DLL - (Windows) Name of the amrnb DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "opencore-amrnb-.*" "AMRNB_HINTS" ) + +if (NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(PC_AMRNB opencore-amrnb) +endif() + +find_path( AMRNB_INCLUDE_DIR + NAMES opencore-amrnb/interf_dec.h + HINTS + "${PC_AMRNB_INCLUDE_DIRS}" + "${AMRNB_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library( AMRNB_LIBRARY + NAMES opencore-amrnb + HINTS + "${PC_AMRNB_LIBDIRS}" + "${AMRNB_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( AMRNB DEFAULT_MSG AMRNB_LIBRARY AMRNB_INCLUDE_DIR) + +if( AMRNB_FOUND ) + set( AMRNB_INCLUDE_DIRS ${AMRNB_INCLUDE_DIR} ) + set( AMRNB_LIBRARIES ${AMRNB_LIBRARY} ) + if (WIN32) + set ( AMRNB_DLL_DIR "${AMRNB_HINTS}/bin" + CACHE PATH "Path to amrnb DLL" + ) + file( GLOB _amrnb_dll RELATIVE "${AMRNB_DLL_DIR}" + "${AMRNB_DLL_DIR}/libamrnb.dll" + ) + set ( AMRNB_DLL ${_amrnb_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "amrnb DLL file name" + ) + mark_as_advanced( AMRNB_DLL_DIR AMRNB_DLL ) + endif() +else() + set( AMRNB_INCLUDE_DIRS ) + set( AMRNB_LIBRARIES ) +endif() + +mark_as_advanced( AMRNB_LIBRARIES AMRNB_INCLUDE_DIRS ) diff --git a/cmake/modules/FindAsciidoctor.cmake b/cmake/modules/FindAsciidoctor.cmake new file mode 100644 index 0000000..b317117 --- /dev/null +++ b/cmake/modules/FindAsciidoctor.cmake @@ -0,0 +1,312 @@ +# +# - Find Asciidoctor +# Sets: +# ASCIIDOCTOR_EXECUTABLE +# + +INCLUDE(FindChocolatey) + +FIND_PROGRAM(ASCIIDOCTOR_EXECUTABLE + NAMES + asciidoctorj.cmd + asciidoctorj.bat + asciidoctorj + asciidoctor.cmd + asciidoctor.bat + asciidoctor + asciidoctor.ruby2.1 + # XXX Add Asciidoctor.js releases (asciidoctor-linux, + # asciidoctor-macos, asciidoctor-win) if that ever becomes an option. + PATHS + /bin + /usr/bin + /usr/local/bin + ${CHOCOLATEY_BIN_PATH} + DOC "Path to Asciidoctor or AsciidoctorJ" +) + +if(ASCIIDOCTOR_EXECUTABLE) + # As of 2.2.0 the AsciidctorJ wrapper script sets -Xmn128m -Xms256m -Xmx256m. + # This isn't enough for the User's Guide. + set(_asciidoctorj_opts "-Xmn256m -Xms512m -Xmx2048m $ENV{ASCIIDOCTORJ_OPTS}") + execute_process( COMMAND ${ASCIIDOCTOR_EXECUTABLE} --version OUTPUT_VARIABLE _ad_full_version ) + separate_arguments(_ad_full_version) + list(GET _ad_full_version 1 ASCIIDOCTOR_VERSION) + + function(set_asciidoctor_target_properties _target) + set_target_properties(${_target} PROPERTIES + FOLDER "Documentation" + EXCLUDE_FROM_DEFAULT_BUILD True + ) + endfunction(set_asciidoctor_target_properties) + + set (_asciidoctor_common_args + # Doesn't work with AsciidoctorJ? + # --failure-level=WARN + # --trace + --quiet + --attribute build_dir=${CMAKE_BINARY_DIR}/docbook + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/ws_utils.rb + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/commaize-block.rb + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/cveidlink-inline-macro.rb + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/manarg-block.rb + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/wsbuglink-inline-macro.rb + --require ${CMAKE_SOURCE_DIR}/docbook/asciidoctor-macros/wssalink-inline-macro.rb + ) + + set(_asciidoctor_common_command + ${CMAKE_COMMAND} -E env TZ=UTC + ${ASCIIDOCTOR_EXECUTABLE} + ${_asciidoctor_common_args} + ) + + set(_asciidoctor_docbook_common_command + ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts} + ${ASCIIDOCTOR_EXECUTABLE} + ${_asciidoctor_common_args} + ) + + MACRO( ASCIIDOCTOR2DOCBOOK _asciidocsource ) + GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE ) + set( _output_xml ${_source_base_name}.xml ) + + add_custom_command( + OUTPUT + ${_output_xml} + COMMAND ${_asciidoctor_docbook_common_command} + --backend docbook + --out-file ${_output_xml} + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + DEPENDS + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + ${ARGN} + ) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + add_custom_command( + OUTPUT + ${_output_xml}-stamp + COMMAND ${CMAKE_COMMAND} -E touch ${_output_xml}-stamp + DEPENDS ${_output_xml} + ) + add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}-stamp) + else() + add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}) + endif() + set_asciidoctor_target_properties(generate_${_output_xml}) + unset(_output_xml) + ENDMACRO() + + # Single page only, for the release notes and man pages. + MACRO( ASCIIDOCTOR2HTML _asciidocsource ) + GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE ) + set( _output_html ${_source_base_name}.html ) + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_html} + COMMAND ${_asciidoctor_common_command} + --backend html + --out-file ${_output_html} + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + DEPENDS + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + ${ARGN} + ) + add_custom_target(generate_${_output_html} DEPENDS ${_output_html}) + set_asciidoctor_target_properties(generate_${_output_html}) + unset(_output_html) + ENDMACRO() + + MACRO( ASCIIDOCTOR2TXT _asciidocsource ) + GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE ) + set( _output_html ${_source_base_name}.html ) + set( _output_txt ${_source_base_name}.txt ) + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_txt} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py + ${_output_html} + > ${_output_txt} + DEPENDS + ${MAN_INCLUDES} + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + ${_output_html} + ${ARGN} + ) + unset(_output_html) + unset(_output_txt) + ENDMACRO() + + # Generate one or more ROFF man pages + MACRO(ASCIIDOCTOR2ROFFMAN _man_section) + set(_input_adoc) + set(_output_man) + foreach(_src_file ${ARGN}) + list(APPEND _input_adoc ${_src_file}) + GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE ) + list(APPEND _output_man ${_source_base_name}.${_man_section} ) + endforeach() + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_man} + COMMAND ${_asciidoctor_common_command} + --backend manpage + --destination-dir ${CMAKE_CURRENT_BINARY_DIR} + ${_input_adoc} + DEPENDS + ${MAN_INCLUDES} + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${_input_adoc} + ) + unset(_src_file) + unset(_input_adoc) + unset(_output_man) + ENDMACRO() + + # Generate one or more HTML man pages + MACRO(ASCIIDOCTOR2HTMLMAN) + set(_input_adoc) + set(_output_man) + foreach(_src_file ${ARGN}) + list(APPEND _input_adoc ${_src_file}) + GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE ) + list(APPEND _output_man ${_source_base_name}.html ) + endforeach() + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_man} + COMMAND ${_asciidoctor_common_command} + --backend html + --destination-dir ${CMAKE_CURRENT_BINARY_DIR} + ${_input_adoc} + DEPENDS + ${MAN_INCLUDES} + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${_input_adoc} + ) + unset(_src_file) + unset(_input_adoc) + unset(_output_man) + ENDMACRO() + + # news: release-notes.txt + # ${CMAKE_COMMAND} -E copy_if_different release-notes.txt ../NEWS + + FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE + NAMES + asciidoctorj + asciidoctor-pdf + PATHS + /bin + /usr/bin + /usr/local/bin + ${CHOCOLATEY_BIN_PATH} + DOC "Path to Asciidoctor PDF or AsciidoctorJ" + ) + + if(ASCIIDOCTOR_PDF_EXECUTABLE) + + set(_asciidoctor_pdf_common_command + ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}" + ${ASCIIDOCTOR_PDF_EXECUTABLE} + --require asciidoctor-pdf + --backend pdf + ${_asciidoctor_common_args} + ) + + MACRO( ASCIIDOCTOR2PDF _title _asciidocsource ) + GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE ) + set(_generate_pdf "generate_${_source_base_name}_pdf") + set(_output_pdf "${_title}.pdf") + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_pdf} + COMMAND ${_asciidoctor_pdf_common_command} + --out-file "${_output_pdf}" + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + DEPENDS + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + ${ARGN} + VERBATIM + ) + add_custom_target(${_generate_pdf} DEPENDS ${_output_pdf}) + set_asciidoctor_target_properties(${_generate_pdf}) + unset(_generate_pdf) + unset(_output_pdf) + ENDMACRO() + + else(ASCIIDOCTOR_PDF_EXECUTABLE) + + MACRO( ASCIIDOCTOR2PDF _asciidocsource ) + ENDMACRO() + + endif(ASCIIDOCTOR_PDF_EXECUTABLE) + + FIND_PROGRAM(ASCIIDOCTOR_EPUB_EXECUTABLE + NAMES + asciidoctorj + asciidoctor-epub3 + PATHS + /bin + /usr/bin + /usr/local/bin + ${CHOCOLATEY_BIN_PATH} + DOC "Path to Asciidoctor EPUB3 or AsciidoctorJ" + ) + + if(ASCIIDOCTOR_EPUB_EXECUTABLE) + + set(_asciidoctor_epub_common_command + ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}" + ${ASCIIDOCTOR_EPUB_EXECUTABLE} + --backend epub3 + ${_asciidoctor_common_args} + ) + + MACRO(ASCIIDOCTOR2EPUB _title _asciidocsource) + GET_FILENAME_COMPONENT(_source_base_name ${_asciidocsource} NAME_WE) + set(_generate_epub "generate_${_source_base_name}_epub") + set(_output_epub "${_title}.epub") + + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output_epub} + COMMAND ${_asciidoctor_epub_common_command} + --out-file "${_output_epub}" + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + DEPENDS + ${CMAKE_SOURCE_DIR}/docbook/attributes.adoc + ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource} + ${ARGN} + VERBATIM + ) + add_custom_target(${_generate_epub} DEPENDS ${_output_epub}) + set_asciidoctor_target_properties(${_generate_epub}) + unset(_generate_epub) + unset(_output_epub) + ENDMACRO() + + else(ASCIIDOCTOR_EPUB_EXECUTABLE) + + MACRO(ASCIIDOCTOR2EPUB _asciidocsource) + ENDMACRO() + + endif(ASCIIDOCTOR_EPUB_EXECUTABLE) + +endif(ASCIIDOCTOR_EXECUTABLE) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( Asciidoctor + REQUIRED_VARS ASCIIDOCTOR_EXECUTABLE + VERSION_VAR ASCIIDOCTOR_VERSION + ) + +mark_as_advanced( ASCIIDOCTOR_EXECUTABLE ) diff --git a/cmake/modules/FindBCG729.cmake b/cmake/modules/FindBCG729.cmake new file mode 100644 index 0000000..37b5693 --- /dev/null +++ b/cmake/modules/FindBCG729.cmake @@ -0,0 +1,57 @@ +# Find the system's bcg729 includes and library +# +# BCG729_INCLUDE_DIRS - where to find bcg729/decoder.h +# BCG729_LIBRARIES - List of libraries when using bcg729 +# BCG729_FOUND - True if bcg729 found +# BCG729_DLL_DIR - (Windows) Path to the bcg729 DLL +# BCG729_DLL - (Windows) Name of the bcg729 DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "bcg729-.*" "BCG729_HINTS" ) + +if (NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_search_module(BCG729 QUIET bcg729) +endif() + +find_path( BCG729_INCLUDE_DIR + NAMES bcg729/decoder.h + HINTS + "${BCG729_INCLUDE_DIR}" + "${BCG729_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library( BCG729_LIBRARY + NAMES bcg729 + HINTS + "${BCG729_LIBDIR}" + "${BCG729_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( BCG729 DEFAULT_MSG BCG729_LIBRARY BCG729_INCLUDE_DIR ) + +if( BCG729_FOUND ) + set( BCG729_INCLUDE_DIRS ${BCG729_INCLUDE_DIR} ) + set( BCG729_LIBRARIES ${BCG729_LIBRARY} ) + if (WIN32) + set ( BCG729_DLL_DIR "${BCG729_HINTS}/bin" + CACHE PATH "Path to bcg729 DLL" + ) + file( GLOB _bcg729_dll RELATIVE "${BCG729_DLL_DIR}" + "${BCG729_DLL_DIR}/libbcg729.dll" + ) + set ( BCG729_DLL ${_bcg729_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "bcg729 DLL file name" + ) + mark_as_advanced( BCG729_DLL_DIR BCG729_DLL ) + endif() +else() + set( BCG729_INCLUDE_DIRS ) + set( BCG729_LIBRARIES ) +endif() + +mark_as_advanced( BCG729_LIBRARIES BCG729_INCLUDE_DIRS ) diff --git a/cmake/modules/FindBROTLI.cmake b/cmake/modules/FindBROTLI.cmake new file mode 100644 index 0000000..4ab8dbb --- /dev/null +++ b/cmake/modules/FindBROTLI.cmake @@ -0,0 +1,50 @@ +# +# - Find brotli +# Find brotli includes and libraries +# +# BROTLI_INCLUDE_DIRS - where to find brotli header files +# BROTLI_LIBRARIES - List of libraries when using brotli. +# BROTLI_FOUND - True if brotli found. +# BROTLI_DLL_DIR - (Windows) Path to the brotli DLLs +# BROTLI_DLLS - (Windows) Name of the brotli DLLs + +include( FindWSWinLibs ) +FindWSWinLibs( "brotli-.*" "BROTLI_HINTS" ) + +find_path(BROTLI_INCLUDE_DIR + NAMES "brotli/decode.h" + HINTS "${BROTLI_HINTS}/include" +) + +find_library(BROTLIDEC_LIBRARY + NAMES brotlidec + HINTS "${BROTLI_HINTS}/lib" +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( BROTLI DEFAULT_MSG BROTLIDEC_LIBRARY BROTLI_INCLUDE_DIR ) + +if( BROTLI_FOUND ) + set( BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR} ) + set( BROTLI_LIBRARIES ${BROTLIDEC_LIBRARY} ) + + if (WIN32) + set ( BROTLI_DLL_DIR "${BROTLI_HINTS}/bin" + CACHE PATH "Path to the brotli DLLs" + ) + file( GLOB _brotli_dlls RELATIVE "${BROTLI_DLL_DIR}" + "${BROTLI_DLL_DIR}/brotlicommon*.dll" + "${BROTLI_DLL_DIR}/brotlidec*.dll" + ) + set ( BROTLI_DLLS ${_brotli_dlls} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "brotli DLL list" + ) + mark_as_advanced( BROTLI_DLL_DIR BROTLI_DLLS ) + endif() +else() + set( BROTLI_INCLUDE_DIRS ) + set( BROTLI_LIBRARIES ) +endif() + +mark_as_advanced( BROTLI_LIBRARIES BROTLI_INCLUDE_DIRS ) diff --git a/cmake/modules/FindCAP.cmake b/cmake/modules/FindCAP.cmake new file mode 100644 index 0000000..0ed69f6 --- /dev/null +++ b/cmake/modules/FindCAP.cmake @@ -0,0 +1,40 @@ +# +# - Find capabilities +# Find the native CAP includes and library +# +# CAP_INCLUDE_DIRS - where to find cap.h, etc. +# CAP_LIBRARIES - List of libraries when using cap. +# CAP_FOUND - True if cap found. + + +IF (CAP_INCLUDE_DIRS) + # Already in cache, be silent + SET(CAP_FIND_QUIETLY TRUE) +ENDIF (CAP_INCLUDE_DIRS) + +find_package(PkgConfig) +pkg_search_module(CAP libcap) + +FIND_PATH(CAP_INCLUDE_DIR sys/capability.h + HINTS ${CAP_INCLUDEDIR} +) + +SET(CAP_NAMES cap) +FIND_LIBRARY(CAP_LIBRARY NAMES ${CAP_NAMES} + HINTS ${CAP_LIBDIR} +) + +# handle the QUIETLY and REQUIRED arguments and set CAP_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CAP DEFAULT_MSG CAP_LIBRARY CAP_INCLUDE_DIR) + +IF(CAP_FOUND) + SET( CAP_LIBRARIES ${CAP_LIBRARY} ) + SET( CAP_INCLUDE_DIRS ${CAP_INCLUDE_DIR} ) +ELSE(CAP_FOUND) + SET( CAP_LIBRARIES ) + SET( CAP_INCLUDE_DIRS ) +ENDIF(CAP_FOUND) + +MARK_AS_ADVANCED( CAP_LIBRARIES CAP_INCLUDE_DIRS ) diff --git a/cmake/modules/FindCARES.cmake b/cmake/modules/FindCARES.cmake new file mode 100644 index 0000000..f69a2a9 --- /dev/null +++ b/cmake/modules/FindCARES.cmake @@ -0,0 +1,81 @@ +# +# - Find cares +# Find the native CARES includes and library +# +# CARES_INCLUDE_DIRS - where to find cares.h, etc. +# CARES_LIBRARIES - List of libraries when using cares. +# CARES_FOUND - True if cares found. +# CARES_DLL_DIR - (Windows) Path to the c-ares DLL. +# CARES_DLL - (Windows) Name of the c-ares DLL. + + +IF (CARES_INCLUDE_DIRS) + # Already in cache, be silent + SET(CARES_FIND_QUIETLY TRUE) +ENDIF (CARES_INCLUDE_DIRS) + +INCLUDE(FindWSWinLibs) +FindWSWinLibs("c-ares-.*" "CARES_HINTS") + +find_path( CARES_INCLUDE_DIR + NAMES ares.h + PATH_SUFFIXES + include + HINTS + "${CARES_INCLUDEDIR}" + "${CARES_HINTS}" +) + +find_library( CARES_LIBRARY + NAMES cares libcares-2 + PATH_SUFFIXES + lib64 lib + HINTS + "${CARES_LIBDIR}" + "${CARES_HINTS}" +) + +# Try to retrieve version from header if found +if(CARES_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+ARES_VERSION_STR[ \t]+\"([^\"]+)\".*") + file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" CARES_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" CARES_VERSION "${CARES_VERSION}") + unset(_version_regex) +endif() + +# handle the QUIETLY and REQUIRED arguments and set CARES_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CARES + REQUIRED_VARS CARES_LIBRARY CARES_INCLUDE_DIR + VERSION_VAR CARES_VERSION) + +IF(CARES_FOUND) + SET( CARES_LIBRARIES ${CARES_LIBRARY} ) + SET( CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR} ) + if (WIN32) + set ( CARES_DLL_DIR "${CARES_HINTS}/bin" + CACHE PATH "Path to C-Ares DLL" + ) + file( GLOB _cares_dll RELATIVE "${CARES_DLL_DIR}" + "${CARES_DLL_DIR}/cares.dll" + ) + set ( CARES_DLL ${_cares_dll} + CACHE FILEPATH "C-Ares DLL file name" + ) + file( GLOB _cares_pdb RELATIVE "${CARES_DLL_DIR}" + "${CARES_DLL_DIR}/cares.pdb" + ) + set ( CARES_PDB ${_cares_pdb} + CACHE FILEPATH "C-Ares PDB file name" + ) + mark_as_advanced( CARES_DLL_DIR CARES_DLL CARES_PDB ) + endif() +ELSE(CARES_FOUND) + SET( CARES_LIBRARIES ) + SET( CARES_INCLUDE_DIRS ) + SET( CARES_DLL_DIR ) + SET( CARES_DLL ) +ENDIF(CARES_FOUND) + +MARK_AS_ADVANCED( CARES_LIBRARIES CARES_INCLUDE_DIRS ) diff --git a/cmake/modules/FindChocolatey.cmake b/cmake/modules/FindChocolatey.cmake new file mode 100644 index 0000000..81510e1 --- /dev/null +++ b/cmake/modules/FindChocolatey.cmake @@ -0,0 +1,22 @@ +# FindChocolatey +# ---------- +# +# This module looks for Chocolatey + +if(WIN32) + if(ENV{ChocolateyInstall}) + set(_chocolateyinstall_bin "$ENV{ChocolateyInstall}/bin") + endif() + + find_path(CHOCOLATEY_BIN_PATH + choco.exe + PATHS + ${_chocolateyinstall_bin} + "$ENV{ProgramData}/chocolatey/bin" + C:/Chocolatey/bin + DOC "Chocolatey binary path" + NO_DEFAULT_PATH + ) + + mark_as_advanced(CHOCOLATEY_BIN_PATH) +endif() diff --git a/cmake/modules/FindDOXYGEN.cmake b/cmake/modules/FindDOXYGEN.cmake new file mode 100644 index 0000000..52e129a --- /dev/null +++ b/cmake/modules/FindDOXYGEN.cmake @@ -0,0 +1,47 @@ +# +# - Find Doxygen +# This module looks for a native (non-Cygwin) Doxygen. +# + +find_program( DOXYGEN_EXECUTABLE + NAMES + doxygen + PATHS + /bin + /usr/bin + /usr/local/bin + /sbin + $ENV{ProgramFiles}/doxygen/bin +) + +# We set various paths in doxygen.cfg via configure_file(). These are +# native system paths which aren't compatible with Cygwin's Doxygen. +string(TOLOWER ${DOXYGEN_EXECUTABLE} _de_lower) +if(${_de_lower} MATCHES "cyg") + set(_ignore_reason "Cygwin Doxygen found at ${DOXYGEN_EXECUTABLE}. Ignoring.") + message(STATUS ${_ignore_reason}) + set(DOXYGEN_EXECUTABLE DOXYGEN_EXECUTABLE-NOTFOUND CACHE FILEPATH ${_ignore_reason} FORCE) +endif() + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( DOXYGEN DEFAULT_MSG DOXYGEN_EXECUTABLE ) + +mark_as_advanced( DOXYGEN_EXECUTABLE ) + +macro( DOXYGEN2HTML _output ) + GET_FILENAME_COMPONENT(_OUTDIR ${_output} PATH) + SET(_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/${_OUTDIR}) + + add_custom_command( + OUTPUT + COMMAND cmake + -E make_directory ${_OUTDIR} + COMMAND $(DOXYGEN_EXECUTABLE) + doxygen.cfg + COMMAND chmod + -R og+rX ${_OUTDIR} + DEPENDS + doxygen.cfg + ) +endmacro() + diff --git a/cmake/modules/FindFseeko.cmake b/cmake/modules/FindFseeko.cmake new file mode 100644 index 0000000..ca53a5a --- /dev/null +++ b/cmake/modules/FindFseeko.cmake @@ -0,0 +1,85 @@ +# CMake support for fseeko +# +# Based on FindLFS.cmake by +# Copyright (C) 2016 Julian Andres Klode . +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# This defines the following variables +# +# FSEEKO_DEFINITIONS - List of definitions to pass to add_definitions() +# FSEEKO_COMPILE_OPTIONS - List of definitions to pass to add_compile_options() +# FSEEKO_LIBRARIES - List of libraries and linker flags +# FSEEKO_FOUND - If there is Large files support +# + +include(CheckCSourceCompiles) +include(FindPackageHandleStandardArgs) +include(CMakePushCheckState) + +# Check for the availability of fseeko() +# The cases handled are: +# +# * Native fseeko() +# * Preprocessor flag -D_LARGEFILE_SOURCE +# +function(_fseeko_check) + set(_fseeko_cppflags) + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET 1) + set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS}) + message(STATUS "Looking for native fseeko support") + check_symbol_exists(fseeko stdio.h fseeko_native) + cmake_pop_check_state() + if (fseeko_native) + message(STATUS "Looking for native fseeko support - found") + set(FSEEKO_FOUND TRUE) + else() + message(STATUS "Looking for native fseeko support - not found") + endif() + + if (NOT FSEEKO_FOUND) + # See if it's available with _LARGEFILE_SOURCE. + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET 1) + set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS} "-D_LARGEFILE_SOURCE") + check_symbol_exists(fseeko stdio.h fseeko_need_largefile_source) + cmake_pop_check_state() + if (fseeko_need_largefile_source) + message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - found") + set(FSEEKO_FOUND TRUE) + set(_fseeko_cppflags "-D_LARGEFILE_SOURCE") + else() + message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - not found") + endif() + endif() + + set(FSEEKO_DEFINITIONS ${_fseeko_cppflags} CACHE STRING "Extra definitions for fseeko support") + set(FSEEKO_COMPILE_OPTIONS "" CACHE STRING "Extra compiler options for fseeko support") + set(FSEEKO_LIBRARIES "" CACHE STRING "Extra definitions for fseeko support") + set(FSEEKO_FOUND ${FSEEKO_FOUND} CACHE INTERNAL "Found fseeko") +endfunction() + +if (NOT FSEEKO_FOUND) + _fseeko_check() +endif() + +find_package_handle_standard_args(FSEEKO "Could not find fseeko. Set FSEEKO_DEFINITIONS, FSEEKO_COMPILE_OPTIONS, FSEEKO_LIBRARIES." FSEEKO_FOUND) diff --git a/cmake/modules/FindGCRYPT.cmake b/cmake/modules/FindGCRYPT.cmake new file mode 100644 index 0000000..1da7a66 --- /dev/null +++ b/cmake/modules/FindGCRYPT.cmake @@ -0,0 +1,89 @@ +# +# - Find gcrypt +# Find the native GCRYPT includes and library +# +# GCRYPT_INCLUDE_DIRS - where to find gcrypt.h, etc. +# GCRYPT_LIBRARIES - List of libraries when using gcrypt. +# GCRYPT_FOUND - True if gcrypt found. +# GCRYPT_DLL_DIR - (Windows) Path to the Libgcrypt DLLs. +# GCRYPT_DLLS - (Windows) List of required Libgcrypt DLLs. + + +if(GCRYPT_INCLUDE_DIRS) + # Already in cache, be silent + set(GCRYPT_FIND_QUIETLY TRUE) +endif() + +include(FindWSWinLibs) +FindWSWinLibs("libgcrypt-.*" "GCRYPT_HINTS") + +find_path(GCRYPT_INCLUDE_DIR + NAMES gcrypt.h + PATH_SUFFIXES + include + HINTS + "${GCRYPT_INCLUDEDIR}" + "${GCRYPT_HINTS}" +) + +# libgcrypt-20 is used in libgcrypt-1.8.3-win??ws (from Debian). +# libgcrypt is used in libgcrypt-1.10.1-2-win??ws (from Debian). +find_library(GCRYPT_LIBRARY + NAMES gcrypt libgcrypt libgcrypt-20 + PATH_SUFFIXES + lib + HINTS + "${GCRYPT_LIBDIR}" + "${GCRYPT_HINTS}" +) + +# libgpg-error6-0 is used in libgcrypt-1.7.6-win??ws (built from source). +# libgpg-error-0 is used in libgcrypt-1.8.3-win??ws (from Debian). +# libgpg-error is used in libgcrypt-1.10.1-2-win??ws (from Debian). +find_library(GCRYPT_ERROR_LIBRARY + NAMES gpg-error libgpg-error libgpg-error-0 libgpg-error6-0 + PATH_SUFFIXES + lib + HINTS + "${GCRYPT_LIBDIR}" + "${GCRYPT_HINTS}" +) + +# Try to retrieve version from header if found (available since libgcrypt 1.3.0) +if(GCRYPT_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+GCRYPT_VERSION[ \t]+\"([0-9\.]+\.[0-9]+).*") + file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" GCRYPT_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" GCRYPT_VERSION "${GCRYPT_VERSION}") + unset(_version_regex) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GCRYPT + REQUIRED_VARS GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR + VERSION_VAR GCRYPT_VERSION) + +if(GCRYPT_FOUND) + set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY} ${GCRYPT_ERROR_LIBRARY}) + set(GCRYPT_INCLUDE_DIRS ${GCRYPT_INCLUDE_DIR}) + if(WIN32) + set(GCRYPT_DLL_DIR "${GCRYPT_HINTS}/bin" + CACHE PATH "Path to the Libgcrypt DLLs" + ) + file(GLOB _gcrypt_dlls RELATIVE "${GCRYPT_DLL_DIR}" + "${GCRYPT_DLL_DIR}/libgcrypt-*.dll" + "${GCRYPT_DLL_DIR}/libgpg-error*.dll" + ) + set(GCRYPT_DLLS ${_gcrypt_dlls} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "Libgcrypt DLL list" + ) + mark_as_advanced(GCRYPT_DLL_DIR GCRYPT_DLLS) + endif() +else() + set(GCRYPT_LIBRARIES) + set(GCRYPT_INCLUDE_DIRS) + set(GCRYPT_DLL_DIR) + set(GCRYPT_DLLS) +endif() + +mark_as_advanced(GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIRS) diff --git a/cmake/modules/FindGLIB2.cmake b/cmake/modules/FindGLIB2.cmake new file mode 100644 index 0000000..6b3876b --- /dev/null +++ b/cmake/modules/FindGLIB2.cmake @@ -0,0 +1,205 @@ +# +# - Try to find the GLIB2 libraries +# Once done this will define +# +# GLIB2_FOUND - system has glib2 +# GLIB2_INCLUDE_DIRS - the glib2 include directory +# GLIB2_LIBRARIES - glib2 library +# GLIB2_DLL_DIR_DEBUG - (Windows) Path to required GLib2 DLLs in debug build. +# GLIB2_DLL_DIR_RELEASE - (Windows) Path to required GLib2 DLLs in release builds. +# GLIB2_DLLS_DEBUG - (Windows) List of required GLib2 DLLs in debug builds. +# GLIB2_DLLS_RELEASE - (Windows) List of required GLib2 DLLs in release builds. + +# Copyright (c) 2008 Laurent Montel, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if( GLIB2_MAIN_INCLUDE_DIR AND GLIB2_LIBRARIES ) + # Already in cache, be silent + set( GLIB2_FIND_QUIETLY TRUE ) +endif() + +include( FindWSWinLibs ) +FindWSWinLibs( "vcpkg-export-*" "GLIB2_HINTS" ) + +if (NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module( PC_GLIB2 glib-2.0 ) +endif() + +find_path( GLIB2_MAIN_INCLUDE_DIR + NAMES + glib.h + HINTS + "${PC_GLIB2_INCLUDEDIR}" + "${GLIB2_HINTS}/include" + PATH_SUFFIXES + glib-2.0 + glib-2.0/include + PATHS + /opt/gnome/include + /opt/local/include + /sw/include + /usr/include + /usr/local/include +) + +include(FindWSLibrary) +FindWSLibrary( GLIB2_LIBRARY + NAMES + glib-2.0 + libglib-2.0 + HINTS + "${PC_GLIB2_LIBDIR}" + WIN32_HINTS + ${GLIB2_HINTS} + PATHS + /opt/gnome/lib64 + /opt/gnome/lib + /opt/lib/ + /opt/local/lib + /sw/lib/ + /usr/lib64 + /usr/lib +) + +if (USE_REPOSITORY) + # In the Windows vcpkg port glibconfig.h is in + # installed/$ARCH-windows/lib/glib-2.0/include. + set( glib2LibDir "${GLIB2_HINTS}/lib" ) +else() + # On UNIX and UNIX-like platforms, the glibconfig.h include dir + # should be in glib-2.0/include in the library directory. + get_filename_component( glib2LibDir "${GLIB2_LIBRARY}" PATH) +endif() + +find_path( GLIB2_INTERNAL_INCLUDE_DIR + NAMES + glibconfig.h + HINTS + "${PC_GLIB2_LIBDIR}" + "${glib2LibDir}" + "${GLIB2_INCLUDEDIR}" + ${CMAKE_SYSTEM_LIBRARY_PATH} + PATH_SUFFIXES + glib-2.0/include +) + +if(PC_GLIB2_VERSION) + set(GLIB2_VERSION ${PC_GLIB2_VERSION}) +elseif(GLIB2_INTERNAL_INCLUDE_DIR) + # On systems without pkg-config (e.g. Windows), search its header + # (available since the initial commit of GLib). + file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MAJOR_VERSION + REGEX "#define[ ]+GLIB_MAJOR_VERSION[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" GLIB_MAJOR_VERSION ${GLIB_MAJOR_VERSION}) + file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MINOR_VERSION + REGEX "#define[ ]+GLIB_MINOR_VERSION[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" GLIB_MINOR_VERSION ${GLIB_MINOR_VERSION}) + file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MICRO_VERSION + REGEX "#define[ ]+GLIB_MICRO_VERSION[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" GLIB_MICRO_VERSION ${GLIB_MICRO_VERSION}) + set(GLIB2_VERSION ${GLIB_MAJOR_VERSION}.${GLIB_MINOR_VERSION}.${GLIB_MICRO_VERSION}) +else() + # When using VERSION_VAR it must be set to a valid value or undefined to + # mean "not found". It's not enough to use the empty string or any other CMake false boolean. + unset(GLIB2_VERSION) +endif() + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( GLIB2 + REQUIRED_VARS GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR + VERSION_VAR GLIB2_VERSION +) + +if( GLIB2_FOUND ) + set( GLIB2_LIBRARIES ${GLIB2_LIBRARY} ) + # Include transitive dependencies for static linking. + if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a") + find_library(PCRE_LIBRARY pcre) + list(APPEND GLIB2_LIBRARIES -pthread ${PCRE_LIBRARY}) + endif() + set( GLIB2_INCLUDE_DIRS ${GLIB2_MAIN_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR} ) + if ( USE_REPOSITORY AND GLIB2_FOUND ) + set ( GLIB2_DLL_DIR_RELEASE "${GLIB2_HINTS}/bin" + CACHE PATH "Path to GLib2 release DLLs" + ) + set ( GLIB2_DLL_DIR_DEBUG "${GLIB2_HINTS}/debug/bin" + CACHE PATH "Path to GLib2 debug DLLs" + ) + + # GTK+ required GObject and GIO. We probably don't. + file( GLOB _glib2_dlls_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}" + # "${GLIB2_DLL_DIR_RELEASE}/gio-2.0-0.dll" + "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.dll" + "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.dll" + # "${GLIB2_DLL_DIR_RELEASE}/gobject-2.0-0.dll" + "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.dll" + "${GLIB2_DLL_DIR_RELEASE}/charset-1.dll" + # gnutls-3.6.3-1-win64ws ships with libffi-6.dll + # "${GLIB2_DLL_DIR_RELEASE}/libffi.dll" + "${GLIB2_DLL_DIR_RELEASE}/iconv-2.dll" + "${GLIB2_DLL_DIR_RELEASE}/intl-8.dll" + ) + set ( GLIB2_DLLS_RELEASE ${_glib2_dlls_release} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "GLib 2 release DLL list" + ) + file( GLOB _glib2_dlls_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}" + # "${GLIB2_DLL_DIR_DEBUG}/gio-2.0-0.dll" + "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.dll" + "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.dll" + # "${GLIB2_DLL_DIR_DEBUG}/gobject-2.0-0.dll" + "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.dll" + "${GLIB2_DLL_DIR_DEBUG}/charset-1.dll" + # gnutls-3.6.3-1-win64ws ships with libffi-6.dll + # "${GLIB2_DLL_DIR_DEBUG}/libffi.dll" + "${GLIB2_DLL_DIR_DEBUG}/iconv-2.dll" + "${GLIB2_DLL_DIR_DEBUG}/intl-8.dll" + ) + set ( GLIB2_DLLS_DEBUG ${_glib2_dlls_debug} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "GLib 2 debug DLL list" + ) + + file( GLOB _glib2_pdbs_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}" + "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.pdb" + "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.pdb" + "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.pdb" + # "${GLIB2_DLL_DIR_RELEASE}/libcharset.pdb" + # "${GLIB2_DLL_DIR_RELEASE}/libiconv.pdb" + # "${GLIB2_DLL_DIR_RELEASE}/libintl.pdb" + ) + set ( GLIB2_PDBS_RELEASE ${_glib2_pdbs_release} + CACHE FILEPATH "GLib2 debug release PDB list" + ) + file( GLOB _glib2_pdbs_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}" + "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.pdb" + "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.pdb" + "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.pdb" + # "${GLIB2_DLL_DIR_DEBUG}/libcharset.pdb" + # "${GLIB2_DLL_DIR_DEBUG}/libiconv.pdb" + # "${GLIB2_DLL_DIR_DEBUG}/libintl.pdb" + ) + set ( GLIB2_PDBS_DEBUG ${_glib2_pdbs_debug} + CACHE FILEPATH "GLib2 debug debug PDB list" + ) + + mark_as_advanced( GLIB2_DLL_DIR_RELEASE GLIB2_DLLS_RELEASE GLIB2_PDBS_RELEASE ) + mark_as_advanced( GLIB2_DLL_DIR_DEBUG GLIB2_DLLS_DEBUG GLIB2_PDBS_DEBUG ) + endif() +elseif( GLIB2_FIND_REQUIRED ) + message( SEND_ERROR "Package required but not found" ) +else() + set( GLIB2_LIBRARIES ) + set( GLIB2_MAIN_INCLUDE_DIRS ) + set( GLIB2_DLL_DIR_RELEASE ) + set( GLIB2_DLL_DIR_DEBUG ) + set( GLIB2_PDBS_RELEASE ) + set( GLIB2_PDBS_DEBUG ) + set( GLIB2_DLLS ) +endif() + +mark_as_advanced( GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES ) diff --git a/cmake/modules/FindGMODULE2.cmake b/cmake/modules/FindGMODULE2.cmake new file mode 100644 index 0000000..187faef --- /dev/null +++ b/cmake/modules/FindGMODULE2.cmake @@ -0,0 +1,48 @@ +# +# - Try to find GModule2 +# Find GModule headers, libraries and the answer to all questions. +# +# GMODULE2_FOUND True if GMODULE2 was found +# GMODULE2_INCLUDE_DIRS Location of GMODULE2 headers +# GMODULE2_LIBRARIES List of libraries to use GMODULE2 +# + +include(FindWSWinLibs) +FindWSWinLibs("vcpkg-export-*" "GMODULE2_HINTS") + +if(NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_GMODULE2 gmodule-2.0) +endif() + +find_path(GMODULE2_INCLUDE_DIR + NAMES + gmodule.h + PATH_SUFFIXES + glib-2.0 + HINTS + ${PC_GMODULE2_INCLUDE_DIRS} + "${GMODULE2_HINTS}/include" +) +include(FindWSLibrary) +FindWSLibrary(GMODULE2_LIBRARY + NAMES + gmodule-2.0 gmodule + HINTS + ${PC_GMODULE2_LIBRARY_DIRS} + WIN32_HINTS + ${GMODULE2_HINTS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GMODULE2 DEFAULT_MSG GMODULE2_LIBRARY GMODULE2_INCLUDE_DIR) + +if(GMODULE2_FOUND) + set(GMODULE2_INCLUDE_DIRS ${GMODULE2_INCLUDE_DIR}) + set(GMODULE2_LIBRARIES ${GMODULE2_LIBRARY}) +else() + set(GMODULE2_INCLUDE_DIRS) + set(GMODULE2_LIBRARIES) +endif() + +mark_as_advanced(GMODULE2_LIBRARIES GMODULE2_INCLUDE_DIRS) diff --git a/cmake/modules/FindGNUTLS.cmake b/cmake/modules/FindGNUTLS.cmake new file mode 100644 index 0000000..853da4e --- /dev/null +++ b/cmake/modules/FindGNUTLS.cmake @@ -0,0 +1,92 @@ +# +# - Find gnutls +# Find the native GNUTLS includes and library +# +# GNUTLS_INCLUDE_DIRS - where to find gnutls.h, etc. +# GNUTLS_LIBRARIES - List of libraries when using gnutls. +# GNUTLS_FOUND - True if gnutls found. +# GNUTLS_DLL_DIR - (Windows) Path to the GnuTLS DLLs. +# GNUTLS_DLLS - (Windows) List of required GnuTLS DLLs. + + +if(GNUTLS_INCLUDE_DIRS) + # Already in cache, be silent + set(GNUTLS_FIND_QUIETLY TRUE) +endif() + +include(FindWSWinLibs) +findwswinlibs("gnutls-.*" "GNUTLS_HINTS") + +if(NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(GNUTLS gnutls) +endif() + +# sources include gnutls/gnutls.h, look for that location instead of gnutls.h. +find_path(GNUTLS_INCLUDE_DIR + NAMES + gnutls/gnutls.h + HINTS + "${GNUTLS_INCLUDEDIR}" + "${GNUTLS_HINTS}/include" +) + +find_library(GNUTLS_LIBRARY + NAMES + gnutls libgnutls-28 libgnutls-30 + HINTS + "${GNUTLS_LIBDIR}" + "${GNUTLS_HINTS}/lib" +) + +# On systems without pkg-config (e.g. Windows), search its header +# (available since GnuTLS 0.1.3) +if(NOT GNUTLS_VERSION) + if(GNUTLS_INCLUDE_DIR) + set(_version_regex "^#define[ \t]+GNUTLS_VERSION[ \t]+\"([^\"]+)\".*") + file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VERSION REGEX "${_version_regex}") + string(REGEX REPLACE "${_version_regex}" "\\1" GNUTLS_VERSION "${GNUTLS_VERSION}") + unset(_version_regex) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GNUTLS + REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR + VERSION_VAR GNUTLS_VERSION) + +if(GNUTLS_FOUND) + set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY}) + set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR}) + if(WIN32) + set(GNUTLS_DLL_DIR "${GNUTLS_HINTS}/bin" + CACHE PATH "Path to the GnuTLS DLLs" + ) + # Note: 32-bit glib2-2.52.2-1.34-win32ws needs libgcc_s_sjlj-1.dll too. + file(GLOB _gnutls_dlls RELATIVE "${GNUTLS_DLL_DIR}" + "${GNUTLS_DLL_DIR}/libgmp-*.dll" + "${GNUTLS_DLL_DIR}/libgcc_s_*.dll" + "${GNUTLS_DLL_DIR}/libffi-*.dll" + "${GNUTLS_DLL_DIR}/libgnutls-*.dll" + "${GNUTLS_DLL_DIR}/libhogweed-*.dll" + "${GNUTLS_DLL_DIR}/libiconv-*.dll" + "${GNUTLS_DLL_DIR}/libintl-*.dll" + "${GNUTLS_DLL_DIR}/libnettle-*.dll" + "${GNUTLS_DLL_DIR}/libp11-kit-*.dll" + "${GNUTLS_DLL_DIR}/libtasn1-*.dll" + "${GNUTLS_DLL_DIR}/libwinpthread-*.dll" + ) + set(GNUTLS_DLLS ${_gnutls_dlls} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "GnuTLS DLL list" + ) + mark_as_advanced(GNUTLS_DLL_DIR GNUTLS_DLLS) + endif() +else() + set(GNUTLS_LIBRARIES) + set(GNUTLS_INCLUDE_DIRS) + set(GNUTLS_DLL_DIR) + set(GNUTLS_DLLS) +endif() + +mark_as_advanced(GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIRS) diff --git a/cmake/modules/FindGTHREAD2.cmake b/cmake/modules/FindGTHREAD2.cmake new file mode 100644 index 0000000..172ee55 --- /dev/null +++ b/cmake/modules/FindGTHREAD2.cmake @@ -0,0 +1,48 @@ +# +# - Try to find GThread2 +# Find GThread headers, libraries and the answer to all questions. +# +# GTHREAD2_FOUND True if GTHREAD2 was found +# GTHREAD2_INCLUDE_DIRS Location of GTHREAD2 headers +# GTHREAD2_LIBRARIES List of libraries to use GTHREAD2 +# + +include(FindWSWinLibs) +FindWSWinLibs("vcpkg-export-*" "GTHREAD2_HINTS") + +if(NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_GTHREAD2 gthread-2.0) +endif() + +find_path(GTHREAD2_INCLUDE_DIR + NAMES + glib/gthread.h + PATH_SUFFIXES + glib-2.0 + HINTS + ${PC_GTHREAD2_INCLUDE_DIRS} + "${GTHREAD2_HINTS}/include" +) +include(FindWSLibrary) +FindWSLibrary(GTHREAD2_LIBRARY + NAMES + gthread-2.0 gthread + HINTS + ${PC_GTHREAD2_LIBRARY_DIRS} + WIN32_HINTS + ${GTHREAD2_HINTS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GTHREAD2 DEFAULT_MSG GTHREAD2_LIBRARY GTHREAD2_INCLUDE_DIR) + +if(GTHREAD2_FOUND) + set(GTHREAD2_INCLUDE_DIRS ${GTHREAD2_INCLUDE_DIR}) + set(GTHREAD2_LIBRARIES ${GTHREAD2_LIBRARY}) +else() + set(GTHREAD2_INCLUDE_DIRS) + set(GTHREAD2_LIBRARIES) +endif() + +mark_as_advanced(GTHREAD2_LIBRARIES GTHREAD2_INCLUDE_DIRS) diff --git a/cmake/modules/FindILBC.cmake b/cmake/modules/FindILBC.cmake new file mode 100644 index 0000000..6dc81a4 --- /dev/null +++ b/cmake/modules/FindILBC.cmake @@ -0,0 +1,77 @@ +# Find the system's ilbc includes and library +# +# ILBC_INCLUDE_DIRS - where to find ilbc.h +# ILBC_LIBRARIES - List of libraries when using ilbc +# ILBC_FOUND - True if ilbc found +# ILBC_DLL_DIR - (Windows) Path to the ilbc DLL +# ILBC_DLL - (Windows) Name of the ilbc DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "libilbc-.*" "ILBC_HINTS" ) + +if (NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(PC_ILBC libilbc) +endif() + +find_path(ILBC_INCLUDE_DIR + NAMES ilbc.h + HINTS + "${PC_ILBC_INCLUDE_DIRS}" + "${ILBC_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library(ILBC_LIBRARY + NAMES + ilbc + libilbc-2 + HINTS + "${PC_ILBC_LIBRARY_DIRS}" + "${ILBC_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +# Check if ilbc library is WebRTC from https://github.com/TimothyGu/libilbc +if(ILBC_INCLUDE_DIR AND ILBC_LIBRARY) + include(CheckSymbolExists) + cmake_push_check_state() + set(CMAKE_REQUIRED_INCLUDES ${ILBC_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${ILBC_LIBRARY}) + check_symbol_exists("WebRtcIlbcfix_DecoderCreate" "ilbc.h" HAVE_ILBC_LIB_WEBRTC) + cmake_pop_check_state() + + if(NOT HAVE_ILBC_LIB_WEBRTC) + message(STATUS "Ignoring incompatible iLBC library.") + # Unset the variables so the search will rerun next time + set(ILBC_INCLUDE_DIR "ILBC_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE) + set(ILBC_LIBRARY "ILBC_LIBRARY-NOTFOUND" CACHE FILEPATH "" FORCE) + unset(HAVE_ILBC_LIB_WEBRTC CACHE) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ILBC DEFAULT_MSG ILBC_LIBRARY ILBC_INCLUDE_DIR) + +if( ILBC_FOUND ) + set( ILBC_INCLUDE_DIRS ${ILBC_INCLUDE_DIR} ) + set( ILBC_LIBRARIES ${ILBC_LIBRARY} ) + if (WIN32) + set ( ILBC_DLL_DIR "${ILBC_HINTS}/bin" + CACHE PATH "Path to ilbc DLL" + ) + file( GLOB _ilbc_dll RELATIVE "${ILBC_DLL_DIR}" + "${ILBC_DLL_DIR}/libilbc-*.dll" + ) + set ( ILBC_DLL ${_ilbc_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "ilbc DLL file name" + ) + mark_as_advanced( ILBC_DLL_DIR ILBC_DLL ) + endif() +else() + set( ILBC_INCLUDE_DIRS ) + set( ILBC_LIBRARIES ) +endif() + +mark_as_advanced( ILBC_LIBRARIES ILBC_INCLUDE_DIRS ) diff --git a/cmake/modules/FindKERBEROS.cmake b/cmake/modules/FindKERBEROS.cmake new file mode 100644 index 0000000..2884fe3 --- /dev/null +++ b/cmake/modules/FindKERBEROS.cmake @@ -0,0 +1,126 @@ +# +# - Find Kerberos +# Find the native Kerberos includes and library +# +# KERBEROS_INCLUDE_DIRS - where to find krb5.h, etc. +# KERBEROS_DEFINITIONS - -D and other compiler flags to use with krb5. +# KERBEROS_LIBRARIES - List of libraries when using krb5. +# KERBEROS_LINK_FLAGS - other linker flags to use with krb5. +# KERBEROS_FOUND - True if krb5 found. +# KERBEROS_DLL_DIR - (Windows) Path to the Kerberos DLLs. +# KERBEROS_DLLS - (Windows) List of required Kerberos DLLs. +# HAVE_HEIMDAL_KERBEROS - set if the Kerberos vendor is Heimdal +# HAVE_MIT_KERBEROS - set if the Kerberos vendor is MIT + + +if(KERBEROS_INCLUDE_DIRS) + # Already in cache, be silent + set(KERBEROS_FIND_QUIETLY TRUE) +endif() + +include(FindWSWinLibs) +FindWSWinLibs("krb5-.*" "KERBEROS_HINTS") + +if(NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(KERBEROS krb5 mit-krb5 heimdal-krb5) +endif() + +if(KERBEROS_FOUND) + # + # Turn KERBEROS_CFLAGS_OTHER into KERBEROS_DEFINITIONS; + # _DEFINITIONS really means "flags other than -I, + # including both -D and other flags". + # + set(KERBEROS_DEFINITIONS "${KERBEROS_CFLAGS_OTHER}") + + # + # KERBEROS_LIBRARIES is a list of library names, not library + # paths, and KERBEROS_LIBRARY_DIRS is a list of -L flag + # arguments. Turn KERBEROS_LIBRARIES into a list of absolute + # paths for libraries, by searching for the libraries in + # directories including KERBEROS_LIBRARY_DIRS. + # + set(_kerberos_libraries "${KERBEROS_LIBRARIES}") + set(KERBEROS_LIBRARIES "") + foreach(_library ${_kerberos_libraries}) + # + # Search for the library, using the library directories from + # pkg_search_module as hints. + # + find_library(_abspath_${_library} NAMES ${_library} + HINTS ${KERBEROS_LIBDIR} ${KERBEROS_LIBRARY_DIRS}) + list(APPEND KERBEROS_LIBRARIES ${_abspath_${_library}}) + endforeach() +else() + # Fallback detection if pkg-config files are not installed. + # Note, this fallback will not add k5crypto and com_err libraries on Linux, + # ensure that pkg-config files are installed for full support. + find_path(KERBEROS_INCLUDE_DIR krb5.h + HINTS + "${KERBEROS_HINTS}/include" + ) + + set(KERBEROS_NAMES krb5 krb5_32 krb5_64) + find_library(KERBEROS_LIBRARY NAMES ${KERBEROS_NAMES} + HINTS + "${KERBEROS_HINTS}/lib" + ) + + # handle the QUIETLY and REQUIRED arguments and set KERBEROS_FOUND to TRUE if + # all listed variables are TRUE + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(KERBEROS DEFAULT_MSG KERBEROS_LIBRARY KERBEROS_INCLUDE_DIR) + + if(KERBEROS_FOUND) + set(KERBEROS_LIBRARIES ${KERBEROS_LIBRARY}) + set(KERBEROS_INCLUDE_DIRS ${KERBEROS_INCLUDE_DIR}) + else() + set(KERBEROS_LIBRARIES) + set(KERBEROS_INCLUDE_DIRS) + endif() +endif() + +# Try to detect the installed Kerberos vendor, assume MIT if it was not Heimdal. +if(KERBEROS_FOUND) + include(CheckSymbolExists) + include(CheckFunctionExists) + set(CMAKE_REQUIRED_INCLUDES ${KERBEROS_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES ${KERBEROS_LIBRARIES}) + #see also HAVE_HEIMDAL_KERBEROS in cmakeconfig.h.in + check_symbol_exists("heimdal_version" "krb5.h" HAVE_HEIMDAL_KERBEROS) + # see also HAVE_KRB5_PAC_VERIFY cmakeconfig.h.in + check_symbol_exists("krb5_pac_verify" "krb5.h" HAVE_KRB5_PAC_VERIFY) + # see also HAVE_KRB5_C_FX_CF2_SIMPLE in cmakeconfig.h.in + check_symbol_exists("krb5_c_fx_cf2_simple" "krb5.h" HAVE_KRB5_C_FX_CF2_SIMPLE) + check_function_exists(decode_krb5_enc_tkt_part HAVE_DECODE_KRB5_ENC_TKT_PART) + check_function_exists(encode_krb5_enc_tkt_part HAVE_ENCODE_KRB5_ENC_TKT_PART) + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_LIBRARIES) + if(NOT HAVE_HEIMDAL_KERBEROS) + set(HAVE_MIT_KERBEROS 1) + endif() +endif() + +if(WIN32) + if(KERBEROS_FOUND) + set(KERBEROS_DLL_DIR "${KERBEROS_HINTS}/bin" + CACHE PATH "Path to the Kerberos DLLs" + ) + file(GLOB _kerberos_dlls RELATIVE "${KERBEROS_DLL_DIR}" + "${KERBEROS_DLL_DIR}/comerr??.dll" + "${KERBEROS_DLL_DIR}/krb5_??.dll" + "${KERBEROS_DLL_DIR}/k5sprt??.dll" + ) + set(KERBEROS_DLLS ${_kerberos_dlls} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "Kerberos DLL list" + ) + mark_as_advanced(KERBEROS_DLL_DIR KERBEROS_DLLS) + else() + set(KERBEROS_DLL_DIR) + set(KERBEROS_DLLS) + endif() +endif() + +mark_as_advanced(KERBEROS_LIBRARIES KERBEROS_INCLUDE_DIRS KERBEROS_DEFINITIONS) diff --git a/cmake/modules/FindLEX.cmake b/cmake/modules/FindLEX.cmake new file mode 100644 index 0000000..20caa09 --- /dev/null +++ b/cmake/modules/FindLEX.cmake @@ -0,0 +1,46 @@ +# +# - Find flex/lex executable +# + +include(FindChocolatey) + +find_program(LEX_EXECUTABLE + NAMES + win_flex + flex + lex + PATHS + ${CHOCOLATEY_BIN_PATH} + /bin + /usr/bin + /usr/local/bin + /sbin +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LEX DEFAULT_MSG LEX_EXECUTABLE) + +MARK_AS_ADVANCED(LEX_EXECUTABLE) + +# flex a .l file + +MACRO(ADD_LEX_FILES _source _generated) + FOREACH (_current_FILE ${ARGN}) + GET_FILENAME_COMPONENT(_in ${_current_FILE} ABSOLUTE) + GET_FILENAME_COMPONENT(_basename ${_current_FILE} NAME_WE) + + SET(_outc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.c) + SET(_outh ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_lex.h) + + ADD_CUSTOM_COMMAND( + OUTPUT ${_outc} ${_outh} + COMMAND ${LEX_EXECUTABLE} $<$,$>:--debug> -o${_outc} --header-file=${_outh} ${_in} + DEPENDS ${_in} + ) + LIST(APPEND ${_source} ${_in}) + LIST(APPEND ${_generated} ${_outc}) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + ENDFOREACH (_current_FILE) +ENDMACRO(ADD_LEX_FILES) + diff --git a/cmake/modules/FindLFS.cmake b/cmake/modules/FindLFS.cmake new file mode 100644 index 0000000..be5f0d4 --- /dev/null +++ b/cmake/modules/FindLFS.cmake @@ -0,0 +1,153 @@ +# CMake support for large files +# +# Copyright (C) 2016 Julian Andres Klode . +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# This defines the following variables +# +# LFS_DEFINITIONS - List of definitions to pass to add_definitions() +# LFS_COMPILE_OPTIONS - List of definitions to pass to add_compile_options() +# LFS_LIBRARIES - List of libraries and linker flags +# LFS_FOUND - If there is Large files support +# + +include(CheckCSourceCompiles) +include(FindPackageHandleStandardArgs) +include(CMakePushCheckState) + +# Test program to check for LFS. Requires that off_t has at least 8 byte large +set(_lfs_test_source + " + #include + typedef char my_static_assert[sizeof(off_t) >= 8 ? 1 : -1]; + int main(void) { return 0; } + " +) + +# Check if the given options are needed +# +# This appends to the variables _lfs_cppflags, _lfs_cflags, and _lfs_ldflags, +# it also sets LFS_FOUND to 1 if it works. +function(_lfs_check_compiler_option var options definitions libraries) + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET 1) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${options}) + set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${definitions}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_DEFINITIONS} ${libraries}) + + message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries}") + check_c_source_compiles("${_lfs_test_source}" ${var}) + cmake_pop_check_state() + + if(${var}) + message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - found") + set(_lfs_cppflags ${_lfs_cppflags} ${definitions} PARENT_SCOPE) + set(_lfs_cflags ${_lfs_cflags} ${options} PARENT_SCOPE) + set(_lfs_ldflags ${_lfs_ldflags} ${libraries} PARENT_SCOPE) + set(LFS_FOUND TRUE PARENT_SCOPE) + else() + message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - not found") + endif() +endfunction() + +# Check for the availability of LFS. +# The cases handled are: +# +# * Native LFS +# * Output of getconf LFS_CFLAGS; getconf LFS_LIBS; getconf LFS_LDFLAGS +# * Preprocessor flag -D_FILE_OFFSET_BITS=64 +# * Preprocessor flag -D_LARGE_FILES +# +function(_lfs_check) + set(_lfs_cflags) + set(_lfs_cppflags) + set(_lfs_ldflags) + set(_lfs_libs) + cmake_push_check_state() + set(CMAKE_REQUIRED_QUIET 1) + message(STATUS "Looking for native LFS support") + check_c_source_compiles("${_lfs_test_source}" lfs_native) + cmake_pop_check_state() + if (lfs_native) + message(STATUS "Looking for native LFS support - found") + set(LFS_FOUND TRUE) + else() + message(STATUS "Looking for native LFS support - not found") + endif() + + if (NOT LFS_FOUND) + # Check using getconf. If getconf fails, don't worry, the check in + # _lfs_check_compiler_option will fail as well. + execute_process(COMMAND getconf LFS_CFLAGS + OUTPUT_VARIABLE _lfs_cflags_raw + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + execute_process(COMMAND getconf LFS_LIBS + OUTPUT_VARIABLE _lfs_libs_tmp + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + execute_process(COMMAND getconf LFS_LDFLAGS + OUTPUT_VARIABLE _lfs_ldflags_tmp + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + + separate_arguments(_lfs_cflags_raw) + separate_arguments(_lfs_ldflags_tmp) + separate_arguments(_lfs_libs_tmp) + + # Move -D flags to the place they are supposed to be + foreach(flag ${_lfs_cflags_raw}) + if (flag MATCHES "-D.*") + list(APPEND _lfs_cppflags_tmp ${flag}) + else() + list(APPEND _lfs_cflags_tmp ${flag}) + endif() + endforeach() + + # Check if the flags we received (if any) produce working LFS support + _lfs_check_compiler_option(lfs_getconf_works + "${_lfs_cflags_tmp}" + "${_lfs_cppflags_tmp}" + "${_lfs_libs_tmp};${_lfs_ldflags_tmp}") + endif() + + if(NOT LFS_FOUND) # IRIX stuff + _lfs_check_compiler_option(lfs_need_n32 "-n32" "" "") + endif() + if(NOT LFS_FOUND) # Linux and friends + _lfs_check_compiler_option(lfs_need_file_offset_bits "" "-D_FILE_OFFSET_BITS=64" "") + endif() + if(NOT LFS_FOUND) # AIX + _lfs_check_compiler_option(lfs_need_large_files "" "-D_LARGE_FILES=1" "") + endif() + + set(LFS_DEFINITIONS ${_lfs_cppflags} CACHE STRING "Extra definitions for large file support") + set(LFS_COMPILE_OPTIONS ${_lfs_cflags} CACHE STRING "Extra definitions for large file support") + set(LFS_LIBRARIES ${_lfs_libs} ${_lfs_ldflags} CACHE STRING "Extra definitions for large file support") + set(LFS_FOUND ${LFS_FOUND} CACHE INTERNAL "Found LFS") +endfunction() + +if (NOT LFS_FOUND) + _lfs_check() +endif() + +find_package_handle_standard_args(LFS "Could not find LFS. Set LFS_DEFINITIONS, LFS_COMPILE_OPTIONS, LFS_LIBRARIES." LFS_FOUND) diff --git a/cmake/modules/FindLIBSSH.cmake b/cmake/modules/FindLIBSSH.cmake new file mode 100644 index 0000000..31346a3 --- /dev/null +++ b/cmake/modules/FindLIBSSH.cmake @@ -0,0 +1,109 @@ +# - Try to find LibSSH +# Once done this will define +# +# LIBSSH_FOUND - system has LibSSH +# LIBSSH_INCLUDE_DIRS - the LibSSH include directory +# LIBSSH_LIBRARIES - Link these to use LibSSH +# +# Copyright (c) 2009 Andreas Schneider +# Modified by Peter Wu to use standard +# find_package(LIBSSH ...) without external module. +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +if(LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS) + # in cache already + set(LIBSSH_FOUND TRUE) +else () + + include(FindWSWinLibs) + FindWSWinLibs("libssh-.*" "LIBSSH_HINTS") + + find_path(LIBSSH_INCLUDE_DIR + NAMES + libssh/libssh.h + HINTS + "${LIBSSH_HINTS}/include" + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ${CMAKE_INCLUDE_PATH} + ${CMAKE_INSTALL_PREFIX}/include + ) + + find_library(LIBSSH_LIBRARY + NAMES + ssh + libssh + HINTS + "${LIBSSH_HINTS}/lib" + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ${CMAKE_LIBRARY_PATH} + ${CMAKE_INSTALL_PREFIX}/lib + ) + + if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY) + include(CheckSymbolExists) + + set(LIBSSH_INCLUDE_DIRS + ${LIBSSH_INCLUDE_DIR} + ) + set(LIBSSH_LIBRARIES + ${LIBSSH_LIBRARY} + ) + + # libssh >= 0.9.5 has libssh_version.h + set(_libssh_version_header "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h") + if(NOT EXISTS "${_libssh_version_header}") + set(_libssh_version_header "${LIBSSH_INCLUDE_DIR}/libssh/libssh.h") + endif() + + file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_MAJOR + REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+") + # Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR + if(LIBSSH_VERSION_MAJOR) + string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR}) + file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_MINOR + REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR}) + file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_PATCH + REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH}) + set(LIBSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH}) + endif() + endif() + + # handle the QUIETLY and REQUIRED arguments and set LIBSSH_FOUND to TRUE if + # all listed variables are TRUE and the requested version matches. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(LIBSSH + REQUIRED_VARS LIBSSH_LIBRARIES LIBSSH_INCLUDE_DIRS LIBSSH_VERSION + VERSION_VAR LIBSSH_VERSION) + + if(WIN32) + set(LIBSSH_DLL_DIR "${LIBSSH_HINTS}/bin" + CACHE PATH "Path to libssh DLLs" + ) + file(GLOB _libssh_dlls RELATIVE "${LIBSSH_DLL_DIR}" + "${LIBSSH_DLL_DIR}/libssh.dll" + ) + set(LIBSSH_DLLS ${_libssh_dlls} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "libssh DLL file name" + ) + mark_as_advanced(LIBSSH_DLL_DIR LIBSSH_DLL) + endif() + + # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARIES) + +endif() diff --git a/cmake/modules/FindLZ4.cmake b/cmake/modules/FindLZ4.cmake new file mode 100644 index 0000000..83e639d --- /dev/null +++ b/cmake/modules/FindLZ4.cmake @@ -0,0 +1,74 @@ +# +# - Find lz4 +# Find LZ4 includes and library +# +# LZ4_INCLUDE_DIRS - where to find lz4.h, etc. +# LZ4_LIBRARIES - List of libraries when using LZ4. +# LZ4_FOUND - True if LZ4 found. +# LZ4_DLL_DIR - (Windows) Path to the LZ4 DLL +# LZ4_DLL - (Windows) Name of the LZ4 DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "lz4-.*" "LZ4_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(LZ4 lz4 liblz4) +endif() + +find_path(LZ4_INCLUDE_DIR + NAMES lz4.h + HINTS "${LZ4_INCLUDEDIR}" "${LZ4_HINTS}/include" + PATHS + /usr/local/include + /usr/include +) + +find_library(LZ4_LIBRARY + NAMES lz4 liblz4 + HINTS "${LZ4_LIBDIR}" "${LZ4_HINTS}/lib" + PATHS + /usr/local/lib + /usr/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR ) + +if( LZ4_FOUND ) + include( CheckIncludeFile ) + include( CMakePushCheckState ) + + set( LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR} ) + set( LZ4_LIBRARIES ${LZ4_LIBRARY} ) + + cmake_push_check_state() + set( CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIRS} ) + check_include_file( lz4frame.h HAVE_LZ4FRAME_H ) + cmake_pop_check_state() + + if (WIN32) + set ( LZ4_DLL_DIR "${LZ4_HINTS}/bin" + CACHE PATH "Path to LZ4 DLL" + ) + file( GLOB _lz4_dll RELATIVE "${LZ4_DLL_DIR}" + "${LZ4_DLL_DIR}/lz4*.dll" + ) + set ( LZ4_DLL ${_lz4_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "LZ4 DLL file name" + ) + file( GLOB _lz4_pdb RELATIVE "${LZ4_DLL_DIR}" + "${LZ4_DLL_DIR}/lz4*.pdb" + ) + set ( LZ4_PDB ${_lz4_pdb} + CACHE FILEPATH "LZ4 PDB file name" + ) + mark_as_advanced( LZ4_DLL_DIR LZ4_DLL LZ4_PDB ) + endif() +else() + set( LZ4_INCLUDE_DIRS ) + set( LZ4_LIBRARIES ) +endif() + +mark_as_advanced( LZ4_LIBRARIES LZ4_INCLUDE_DIRS ) diff --git a/cmake/modules/FindLibXml2.cmake b/cmake/modules/FindLibXml2.cmake new file mode 100644 index 0000000..f3e4762 --- /dev/null +++ b/cmake/modules/FindLibXml2.cmake @@ -0,0 +1,124 @@ +# This code was copied from https://gitlab.kitware.com/cmake/cmake/raw/master/Modules/FindLibXml2.cmake +# and modified to support Wireshark Windows 3rd party packages + +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindLibXml2 +----------- + +Find the XML processing library (libxml2). + +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if +libxml2 has been found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``LIBXML2_FOUND`` + true if libxml2 headers and libraries were found +``LIBXML2_INCLUDE_DIR`` + the directory containing LibXml2 headers +``LIBXML2_INCLUDE_DIRS`` + list of the include directories needed to use LibXml2 +``LIBXML2_LIBRARIES`` + LibXml2 libraries to be linked +``LIBXML2_DEFINITIONS`` + the compiler switches required for using LibXml2 +``LIBXML2_XMLLINT_EXECUTABLE`` + path to the XML checking tool xmllint coming with LibXml2 +``LIBXML2_VERSION_STRING`` + the version of LibXml2 found (since CMake 2.8.8) + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``LIBXML2_INCLUDE_DIR`` + the directory containing LibXml2 headers +``LIBXML2_LIBRARY`` + path to the LibXml2 library +#]=======================================================================] + +include(FindWSWinLibs) +FindWSWinLibs("vcpkg-export-.*" LIBXML2_HINTS) + +if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig + # use pkg-config to get the directories and then use these values + # in the find_path() and find_library() calls + find_package(PkgConfig QUIET) + PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0) + set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER}) +endif() + +find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h + HINTS + ${PC_LIBXML_INCLUDEDIR} + ${PC_LIBXML_INCLUDE_DIRS} + ${LIBXML2_HINTS}/include + PATH_SUFFIXES libxml2 + ) + +# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of +# the cache entry storing the find_library result. Use the +# value if it was set by the project or user. +if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY) + set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) +endif() + +find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 libxml2-2 + HINTS + ${PC_LIBXML_LIBDIR} + ${PC_LIBXML_LIBRARY_DIRS} + ${LIBXML2_HINTS}/lib + ) + +find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint + HINTS + ${LIBXML2_HINTS}/bin + ) +# for backwards compat. with KDE 4.0.x: +set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}") + +if(PC_LIBXML_VERSION) + set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION}) +elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h") + file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str + REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + LIBXML2_VERSION_STRING "${libxml2_version_str}") + unset(libxml2_version_str) +endif() + +set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS}) +set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY}) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 + REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR + VERSION_VAR LIBXML2_VERSION_STRING) + +mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE) + +if(LibXml2_FOUND) + # Include transitive dependencies for static linking. + if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a") + list(APPEND LIBXML2_LIBRARIES ${PC_LIBXML_LIBRARIES}) + endif() + + if (NOT TARGET LibXml2::LibXml2) + add_library(LibXml2::LibXml2 UNKNOWN IMPORTED) + set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}") + set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}") + endif() +endif() + +AddWSWinDLLS(LibXml2 LIBXML2_HINTS "libxml2*" "liblzma*") diff --git a/cmake/modules/FindLua.cmake b/cmake/modules/FindLua.cmake new file mode 100644 index 0000000..23e50a6 --- /dev/null +++ b/cmake/modules/FindLua.cmake @@ -0,0 +1,243 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindLua +------- + +Locate Lua library. + +.. versionadded:: 3.18 + Support for Lua 5.4. + +This module defines: + +``LUA_FOUND`` + if false, do not try to link to Lua +``LUA_LIBRARIES`` + both lua and lualib +``LUA_INCLUDE_DIR`` + where to find lua.h +``LUA_VERSION_STRING`` + the version of Lua found +``LUA_VERSION_MAJOR`` + the major version of Lua +``LUA_VERSION_MINOR`` + the minor version of Lua +``LUA_VERSION_PATCH`` + the patch version of Lua + +Note that the expected include convention is + +:: + + #include "lua.h" + +and not + +:: + + #include + +This is because, the lua location is not standardized and may exist in +locations other than lua/ +#]=======================================================================] + +cmake_policy(PUSH) # Policies apply to functions at definition-time +cmake_policy(SET CMP0012 NEW) # For while(TRUE) + +INCLUDE(FindWSWinLibs) +FindWSWinLibs("lua-5*" "LUA_HINTS") + +unset(_lua_include_subdirs) +unset(_lua_library_names) +unset(_lua_append_versions) + +# this is a function only to have all the variables inside go away automatically +function(_lua_get_versions) + set(LUA_VERSIONS5 ${LUA_FIND_VERSIONS}) + list(FILTER LUA_VERSIONS5 INCLUDE REGEX "5\.[21]") + set(_lua_append_versions ${LUA_VERSIONS5}) + message(STATUS "Considering the following Lua versions: ${_lua_append_versions}") + + set(_lua_append_versions "${_lua_append_versions}" PARENT_SCOPE) +endfunction() + +function(_lua_set_version_vars) + set(_lua_include_subdirs_raw "lua") + + foreach (ver IN LISTS _lua_append_versions) + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}") + list(APPEND _lua_include_subdirs_raw + lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} + lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + ) + endforeach () + + # Prepend "include/" to each path directly after the path + set(_lua_include_subdirs "include") + foreach (dir IN LISTS _lua_include_subdirs_raw) + list(APPEND _lua_include_subdirs "${dir}" "include/${dir}") + endforeach () + + set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE) +endfunction(_lua_set_version_vars) + +function(_lua_get_header_version) + unset(LUA_VERSION_STRING PARENT_SCOPE) + set(_hdr_file "${LUA_INCLUDE_DIR}/lua.h") + + if (NOT EXISTS "${_hdr_file}") + return() + endif () + + # At least 5.[012] have different ways to express the version + # so all of them need to be tested. Lua 5.2 defines LUA_VERSION + # and LUA_RELEASE as joined by the C preprocessor, so avoid those. + file(STRINGS "${_hdr_file}" lua_version_strings + REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") + + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};") + if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};") + set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}") + else () + string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") + if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") + endif () + string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}") + endif () + foreach (ver IN LISTS _lua_append_versions) + if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}") + set(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR} PARENT_SCOPE) + set(LUA_VERSION_MINOR ${LUA_VERSION_MINOR} PARENT_SCOPE) + set(LUA_VERSION_PATCH ${LUA_VERSION_PATCH} PARENT_SCOPE) + set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE) + return() + endif () + endforeach () +endfunction(_lua_get_header_version) + +function(_lua_find_header) + _lua_set_version_vars() + + # Initialize as local variable + set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH}) + while (TRUE) + # Find the next header to test. Check each possible subdir in order + # This prefers e.g. higher versions as they are earlier in the list + # It is also consistent with previous versions of FindLua + foreach (subdir IN LISTS _lua_include_subdirs) + find_path(LUA_INCLUDE_DIR lua.h + HINTS ${LUA_HINTS} ENV LUA_DIR + PATH_SUFFIXES ${subdir} + ) + if (LUA_INCLUDE_DIR) + break() + endif() + endforeach() + # Did not found header -> Fail + if (NOT LUA_INCLUDE_DIR) + return() + endif() + _lua_get_header_version() + # Found accepted version -> Ok + if (LUA_VERSION_STRING) + if (LUA_Debug) + message(STATUS "Found suitable version ${LUA_VERSION_STRING} in ${LUA_INCLUDE_DIR}/lua.h") + endif() + return() + endif() + # Found wrong version -> Ignore this path and retry + if (LUA_Debug) + message(STATUS "Ignoring unsuitable version in ${LUA_INCLUDE_DIR}") + endif() + list(APPEND CMAKE_IGNORE_PATH "${LUA_INCLUDE_DIR}") + unset(LUA_INCLUDE_DIR CACHE) + unset(LUA_INCLUDE_DIR) + unset(LUA_INCLUDE_DIR PARENT_SCOPE) + endwhile () +endfunction() + +_lua_get_versions() +_lua_find_header() +_lua_get_header_version() +unset(_lua_append_versions) + +if (LUA_VERSION_STRING) + set(_lua_library_names + lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR} + lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} + lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} + lua.${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR} + ) +endif () + +find_library(LUA_LIBRARY + NAMES ${_lua_library_names} lua + NAMES_PER_DIR + HINTS + ${LUA_HINTS} + ENV LUA_DIR + PATH_SUFFIXES lib +) +unset(_lua_library_names) + +if (LUA_LIBRARY) + # include the math library for Unix + if (UNIX AND NOT APPLE AND NOT BEOS) + find_library(LUA_MATH_LIBRARY m) + mark_as_advanced(LUA_MATH_LIBRARY) + set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}") + + # include dl library for statically-linked Lua library + get_filename_component(LUA_LIB_EXT ${LUA_LIBRARY} EXT) + if(LUA_LIB_EXT STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) + list(APPEND LUA_LIBRARIES ${CMAKE_DL_LIBS}) + endif() + + # For Windows and Mac, don't need to explicitly include the math library + else () + set(LUA_LIBRARIES "${LUA_LIBRARY}") + endif () +endif () + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY) + +cmake_policy(POP) + +IF(Lua_FOUND) + SET( LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR} ) + if (WIN32) + set ( LUA_DLL_DIR "${LUA_HINTS}" CACHE PATH "Path to Lua DLL") + file( GLOB _lua_dll RELATIVE "${LUA_DLL_DIR}" "${LUA_DLL_DIR}/lua*.dll") + set ( LUA_DLL ${_lua_dll} CACHE FILEPATH "Lua DLL file name") + mark_as_advanced( LUA_DLL_DIR LUA_DLL ) + endif() + if(LUA_DLL_DIR MATCHES ".*/lua-.*-unicode-.*") + # Do we have Lua with Unicode for Windows patches? + # https://github.com/Lekensteyn/lua-unicode + # XXX Would be better if it was possible to + # detect a Lua-unicode build from C and Lua code + # but upstream rejected patches for that so we do + # it here. + set(HAVE_LUA_UNICODE True) + endif() +ELSE(Lua_FOUND) + SET( LUA_LIBRARIES ) + SET( LUA_INCLUDE_DIRS ) + SET( LUA_DLL_DIR ) + SET( LUA_DLL ) +ENDIF(Lua_FOUND) diff --git a/cmake/modules/FindM.cmake b/cmake/modules/FindM.cmake new file mode 100644 index 0000000..402a8bc --- /dev/null +++ b/cmake/modules/FindM.cmake @@ -0,0 +1,52 @@ +# +# - Find math +# Find the native M includes and library +# +# M_INCLUDE_DIRS - where to find math.h, etc. +# M_LIBRARIES - List of libraries when using math. +# M_FOUND - True if math found. + + +IF (M_INCLUDE_DIRS) + # Already in cache, be silent + SET(M_FIND_QUIETLY TRUE) +ENDIF (M_INCLUDE_DIRS) + +# +# On macOS, make sure we do *NOT* find math.h in the Kernel framework, +# as that will convince CMake to cause the build to look there for +# headers. +# +# For some unknown reason, on Yosemite, math.h is included in the Kernel +# framework. That framework exists to supply headers for building +# *kernel* modules; it includes versions of C headers that are similar +# to the standard userland headers, but not similar enough to be usable +# when building userland code. +# +# Unless told not to look first in the framework paths, CMake will, on +# Yosemite, or when using the Yosemite SDK, find math.h in the Kernel +# framework, and add the header directory for the Kernel framework to +# the list of places to look for headers, causing it to pick up other +# headers from there as well. This causes the build to fail. +# +SET(SAVED_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) +SET(CMAKE_FIND_FRAMEWORK LAST) +FIND_PATH(M_INCLUDE_DIR math.h) +SET(CMAKE_FIND_FRAMEWORK ${SAVED_CMAKE_FIND_FRAMEWORK}) + +set(M_LIBRARY m) + +# handle the QUIETLY and REQUIRED arguments and set M_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(M DEFAULT_MSG M_LIBRARY M_INCLUDE_DIR) + +IF(M_FOUND) + SET( M_LIBRARIES ${M_LIBRARY} ) + SET( M_INCLUDE_DIRS ${M_INCLUDE_DIR} ) +ELSE(M_FOUND) + SET( M_LIBRARIES ) + SET( M_INCLUDE_DIRS ) +ENDIF(M_FOUND) + +MARK_AS_ADVANCED( M_LIBRARIES M_INCLUDE_DIRS ) diff --git a/cmake/modules/FindMSVC_REDIST.cmake b/cmake/modules/FindMSVC_REDIST.cmake new file mode 100644 index 0000000..2d1237b --- /dev/null +++ b/cmake/modules/FindMSVC_REDIST.cmake @@ -0,0 +1,23 @@ +# +# Find the Microsoft Visual C++ library DLLs. +# These are included with the full frontal (Professional, Enterprise) editions +# of Visual Studio but not Express. +# +# MSVCR_DLL - Path to the redistributable DLLs. +# + +set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) +include(InstallRequiredSystemLibraries) + +# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS will likely give us a list of DLL +# paths containing spaces. We'll assume that they're all in the same +# directory and use it to create something that's easier to pass to +# NSIS. + +set(MSVCR_DLL) +list(GET CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS 0 _msvcr_dll) +if(_msvcr_dll) + get_filename_component(_msvcr_dir ${_msvcr_dll} DIRECTORY) + set(MSVCR_DLL "${_msvcr_dir}/*.*") + file(TO_NATIVE_PATH "${MSVCR_DLL}" MSVCR_DLL) +endif() diff --git a/cmake/modules/FindMaxMindDB.cmake b/cmake/modules/FindMaxMindDB.cmake new file mode 100644 index 0000000..5de81a1 --- /dev/null +++ b/cmake/modules/FindMaxMindDB.cmake @@ -0,0 +1,75 @@ +# +# - Try to find libmaxminddb. +# Once done this will define +# MAXMINDDB_FOUND - System has libmaxminddb +# MAXMINDDB_INCLUDE_DIRS - The libmaxminddb include directories +# MAXMINDDB_LIBRARIES - The libraries needed to use libmaxminddb +# MAXMINDDB_DEFINITIONS - Compiler switches required for using libmaxminddb +# MAXMINDDB_DLL_DIR - (Windows) Path to the MaxMindDB DLL. +# MAXMINDDB_DLL - (Windows) Name of the MaxMindDB DLL. + +IF (MAXMINDDB_INCLUDE_DIRS) + # Already in cache, be silent + SET(MAXMINDDB_FIND_QUIETLY TRUE) +ENDIF (MAXMINDDB_INCLUDE_DIRS) + +INCLUDE(FindWSWinLibs) +FindWSWinLibs("libmaxminddb-.*" "MAXMINDDB_HINTS") + +IF (NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_check_modules(PC_LIBMAXMINDDB QUIET libmaxminddb) + set(MAXMINDDB_DEFINITIONS ${PC_LIBMAXMINDDB_CFLAGS_OTHER}) +endif() + +FIND_PATH(MAXMINDDB_INCLUDE_DIR maxminddb.h + HINTS + ${PC_LIBMAXMINDDB_INCLUDEDIR} ${PC_LIBMAXMINDDB_INCLUDE_DIRS} + "${MAXMINDDB_HINTS}/include" + PATH_SUFFIXES maxminddb +) + +find_library(MAXMINDDB_LIBRARY + NAMES + maxminddb libmaxminddb libmaxminddb-0 + HINTS + ${PC_LIBMAXMINDDB_LIBDIR} ${PC_LIBMAXMINDDB_LIBRARY_DIRS} + "${MAXMINDDB_HINTS}/lib" +) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set MAXMINDDB_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(MaxMindDB DEFAULT_MSG + MAXMINDDB_LIBRARY MAXMINDDB_INCLUDE_DIR) + +IF(MAXMINDDB_FOUND) + INCLUDE(CMakePushCheckState) + CMAKE_PUSH_CHECK_STATE() + SET(MAXMINDDB_LIBRARIES ${MAXMINDDB_LIBRARY} ) + SET(MAXMINDDB_INCLUDE_DIRS ${MAXMINDDB_INCLUDE_DIR} ) + INCLUDE(CheckFunctionExists) + SET(CMAKE_REQUIRED_INCLUDES ${MAXMINDDB_INCLUDE_DIRS}) + SET(CMAKE_REQUIRED_LIBRARIES ${MAXMINDDB_LIBRARIES}) + CMAKE_POP_CHECK_STATE() + if (WIN32) + set ( MAXMINDDB_DLL_DIR "${MAXMINDDB_HINTS}/bin" + CACHE PATH "Path to the MaxMindDB DLL" + ) + file( GLOB _MAXMINDDB_dll RELATIVE "${MAXMINDDB_DLL_DIR}" + "${MAXMINDDB_DLL_DIR}/libmaxminddb*.dll" + ) + set ( MAXMINDDB_DLL ${_MAXMINDDB_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "MaxMindDB DLL file name" + ) + mark_as_advanced( MAXMINDDB_DLL_DIR MAXMINDDB_DLL ) + endif() +ELSE(MAXMINDDB_FOUND) + SET(MAXMINDDB_LIBRARIES ) + SET(MAXMINDDB_INCLUDE_DIRS ) + SET(MAXMINDDB_DLL_DIR ) + SET(MAXMINDDB_DLL ) +ENDIF(MAXMINDDB_FOUND) + +MARK_AS_ADVANCED( MAXMINDDB_LIBRARIES MAXMINDDB_INCLUDE_DIRS ) diff --git a/cmake/modules/FindMinizip.cmake b/cmake/modules/FindMinizip.cmake new file mode 100644 index 0000000..b6d9c86 --- /dev/null +++ b/cmake/modules/FindMinizip.cmake @@ -0,0 +1,81 @@ +# +# - Find minizip libraries +# +# MINIZIP_INCLUDE_DIRS - where to find minizip headers. +# MINIZIP_LIBRARIES - List of libraries when using minizip. +# MINIZIP_FOUND - True if minizip is found. +# MINIZIP_DLL_DIR - (Windows) Path to the minizip DLL. +# MINIZIP_DLL - (Windows) Name of the minizip DLL. + +FindWSWinLibs( "minizip-*" "MINIZIP_HINTS" ) + +if(NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_search_module(MINIZIP QUIET minizip) +endif() + +find_path(MINIZIP_INCLUDE_DIR + NAMES + unzip.h + minizip/unzip.h + HINTS + ${MINIZIP_INCLUDE_DIRS} + "${MINIZIP_HINTS}/include" +) + +get_filename_component(MINIZIP_PARENT_DIR ${MINIZIP_INCLUDE_DIR} DIRECTORY) +if(EXISTS "${MINIZIP_PARENT_DIR}/minizip/unzip.h") + set(MINIZIP_INCLUDE_DIR "${MINIZIP_PARENT_DIR}") +endif() + +find_library(MINIZIP_LIBRARY + NAMES + minizip + HINTS + ${MINIZIP_LIBRARY_DIRS} + "${MINIZIP_HINTS}/lib" +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Minizip + REQUIRED_VARS MINIZIP_LIBRARY MINIZIP_INCLUDE_DIR + VERSION_VAR MINIZIP_VERSION) + +if(MINIZIP_FOUND) + set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY}) + set(MINIZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIR}) + SET(HAVE_MINIZIP ON) + # Some distributions have minizip-ng code instead of the original zlib contrib + # library but keep the old minizip name (because minizip-ng is + # better maintained and provides a compatibility layer). However the + # minizip-ng compatibility layer has some issues. We need to check + # for renamed struct members to avoid an endless game of whack-a-mole. + include(CheckStructHasMember) + check_struct_has_member("zip_fileinfo" "dos_date" "minizip/zip.h" HAVE_MZCOMPAT_DOS_DATE) + if (WIN32) + set ( MINIZIP_DLL_DIR "${MINIZIP_HINTS}/bin" + CACHE PATH "Path to Minizip DLL" + ) + file( GLOB _minizip_dll RELATIVE "${MINIZIP_DLL_DIR}" + "${MINIZIP_DLL_DIR}/minizip.dll" + ) + set ( MINIZIP_DLL ${_minizip_dll} + CACHE FILEPATH "Minizip DLL file name" + ) + file( GLOB _minizip_pdb RELATIVE "${MINIZIP_DLL_DIR}" + "${MINIZIP_DLL_DIR}/minizip.pdb" + ) + set ( MINIZIP_PDB ${_minizip_pdb} + CACHE FILEPATH "Minizip PDB file name" + ) + mark_as_advanced( MINIZIP_DLL_DIR MINIZIP_DLL MINIZIP_PDB ) + endif() +else() + set(MINIZIP_LIBRARIES) + set(MINIZIP_INCLUDE_DIRS) + SET( MINIZIP_DLL_DIR ) + SET( MINIZIP_DLL ) +endif() + +mark_as_advanced(MINIZIP_LIBRARIES MINIZIP_INCLUDE_DIRS) + diff --git a/cmake/modules/FindNGHTTP2.cmake b/cmake/modules/FindNGHTTP2.cmake new file mode 100644 index 0000000..5f06dbe --- /dev/null +++ b/cmake/modules/FindNGHTTP2.cmake @@ -0,0 +1,62 @@ +# Find the system's Nghttp2 includes and library +# +# NGHTTP2_INCLUDE_DIRS - where to find nghttp2.h +# NGHTTP2_LIBRARIES - List of libraries when using nghttp2 +# NGHTTP2_FOUND - True if nghttp2 found +# NGHTTP2_DLL_DIR - (Windows) Path to the Nghttp2 DLL +# NGHTTP2_DLL - (Windows) Name of the Nghttp2 DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "nghttp2-.*" "NGHTTP2_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(NGHTTP2 libnghttp2) +endif() + +find_path( NGHTTP2_INCLUDE_DIR + NAMES nghttp2/nghttp2.h + HINTS + "${NGHTTP2_INCLUDEDIR}" + "${NGHTTP2_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library( NGHTTP2_LIBRARY + NAMES nghttp2 + HINTS + "${NGHTTP2_LIBDIR}" + "${NGHTTP2_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( NGHTTP2 DEFAULT_MSG NGHTTP2_LIBRARY NGHTTP2_INCLUDE_DIR ) + +if( NGHTTP2_FOUND ) + set( NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR} ) + set( NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY} ) + if (WIN32) + set ( NGHTTP2_DLL_DIR "${NGHTTP2_HINTS}/bin" + CACHE PATH "Path to nghttp2 DLL" + ) + file( GLOB _nghttp2_dll RELATIVE "${NGHTTP2_DLL_DIR}" + "${NGHTTP2_DLL_DIR}/nghttp2.dll" + ) + set ( NGHTTP2_DLL ${_nghttp2_dll} + CACHE FILEPATH "nghttp2 DLL file name" + ) + file( GLOB _nghttp2_pdb RELATIVE "${NGHTTP2_DLL_DIR}" + "${NGHTTP2_DLL_DIR}/nghttp2.pdb" + ) + set ( NGHTTP2_PDB ${_nghttp2_pdb} + CACHE FILEPATH "nghttp2 PDB file name" + ) + mark_as_advanced( NGHTTP2_DLL_DIR NGHTTP2_DLL NGHTTP2_PDB ) + endif() +else() + set( NGHTTP2_INCLUDE_DIRS ) + set( NGHTTP2_LIBRARIES ) +endif() + +mark_as_advanced( NGHTTP2_LIBRARIES NGHTTP2_INCLUDE_DIRS ) diff --git a/cmake/modules/FindNGHTTP3.cmake b/cmake/modules/FindNGHTTP3.cmake new file mode 100644 index 0000000..9ec5404 --- /dev/null +++ b/cmake/modules/FindNGHTTP3.cmake @@ -0,0 +1,62 @@ +# Find the system's Nghttp3 includes and library +# +# NGHTTP3_INCLUDE_DIRS - where to find nghttp3.h +# NGHTTP3_LIBRARIES - List of libraries when using nghttp3 +# NGHTTP3_FOUND - True if nghttp3 found +# NGHTTP3_DLL_DIR - (Windows) Path to the Nghttp2 DLL +# NGHTTP3_DLL - (Windows) Name of the Nghttp2 DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "nghttp3-.*" "NGHTTP3_HINTS" ) + +if( NOT WIN32) + find_package(PkgConfig) + pkg_search_module(NGHTTP3 libnghttp3) +endif() + +find_path( NGHTTP3_INCLUDE_DIR + NAMES nghttp3/nghttp3.h + HINTS + "${NGHTTP3_INCLUDEDIR}" + "${NGHTTP3_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library( NGHTTP3_LIBRARY + NAMES nghttp3 + HINTS + "${NGHTTP3_LIBDIR}" + "${NGHTTP3_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( NGHTTP3 DEFAULT_MSG NGHTTP3_LIBRARY NGHTTP3_INCLUDE_DIR ) + +if( NGHTTP3_FOUND ) + set( NGHTTP3_INCLUDE_DIRS ${NGHTTP3_INCLUDE_DIR} ) + set( NGHTTP3_LIBRARIES ${NGHTTP3_LIBRARY} ) + if (WIN32) + set ( NGHTTP3_DLL_DIR "${NGHTTP3_HINTS}/bin" + CACHE PATH "Path to nghttp3 DLL" + ) + file( GLOB _nghttp3_dll RELATIVE "${NGHTTP3_DLL_DIR}" + "${NGHTTP3_DLL_DIR}/nghttp3.dll" + ) + set ( NGHTTP3_DLL ${_nghttp3_dll} + CACHE FILEPATH "nghttp3 DLL file name" + ) + file( GLOB _nghttp3_pdb RELATIVE "${NGHTTP3_DLL_DIR}" + "${NGHTTP3_DLL_DIR}/nghttp3.pdb" + ) + set ( NGHTTP3_PDB ${_nghttp3_pdb} + CACHE FILEPATH "nghttp3 PDB file name" + ) + mark_as_advanced( NGHTTP3_DLL_DIR NGHTTP3_DLL NGHTTP3_PDB ) + endif() +else() + set( NGHTTP3_INCLUDE_DIRS ) + set( NGHTTP3_LIBRARIES ) +endif() + +mark_as_advanced( NGHTTP3_LIBRARIES NGHTTP3_INCLUDE_DIRS ) diff --git a/cmake/modules/FindNL.cmake b/cmake/modules/FindNL.cmake new file mode 100644 index 0000000..d4f003e --- /dev/null +++ b/cmake/modules/FindNL.cmake @@ -0,0 +1,144 @@ +# +# Find the native netlink includes and library +# +# If they exist, differentiate between versions 1, 2 and 3. +# Version 1 does not have netlink/version.h +# Version 2 started separating libraries (libnl{,-genl,-route}). +# Version 3 (>= 3.2) started appending the major version number as suffix to +# library names (libnl-3) +# +# NL_INCLUDE_DIRS - where to find libnl.h, etc. +# NL_LIBRARIES - List of libraries when using libnl. +# NL_FOUND - True if libnl found. + +if(NL_LIBRARIES AND NL_INCLUDE_DIRS) + # in cache already + SET(NL_FOUND TRUE) +else() + SET( SEARCHPATHS + /opt/local + /sw + /usr + /usr/local + ) + + find_package(PkgConfig) + pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 libnl-route-3.0) + if(NOT NL3_FOUND) + pkg_search_module(NL2 libnl-2.0) + endif() + + # Try to find NL 2.0, 3.0 or 3.1 (/usr/include/netlink/version.h) or + # NL >= 3.2 (/usr/include/libnl3/netlink/version.h) + find_path(NL3_INCLUDE_DIR + PATH_SUFFIXES + include/libnl3 + include + NAMES + netlink/version.h + HINTS + "${NL3_libnl-3.0_INCLUDEDIR}" + "${NL2_INCLUDEDIR}" + PATHS + $(SEARCHPATHS) + ) + # NL version >= 2 + if(NL3_INCLUDE_DIR) + find_library(NL3_LIBRARY + NAMES + nl-3 nl + PATH_SUFFIXES + lib64 lib + HINTS + "${NL3_libnl-3.0_LIBDIR}" + "${NL2_LIBDIR}" + PATHS + $(SEARCHPATHS) + ) + find_library(NLGENL_LIBRARY + NAMES + nl-genl-3 nl-genl + PATH_SUFFIXES + lib64 lib + HINTS + "${NL3_libnl-genl-3.0_LIBDIR}" + "${NL2_LIBDIR}" + PATHS + $(SEARCHPATHS) + ) + find_library(NLROUTE_LIBRARY + NAMES + nl-route-3 nl-route + PATH_SUFFIXES + lib64 lib + HINTS + "${NL3_libnl-route-3.0_LIBDIR}" + "${NL2_LIBDIR}" + PATHS + $(SEARCHPATHS) + ) + # + # If we don't have all of those libraries, we can't use libnl. + # + if(NL3_LIBRARY AND NLGENL_LIBRARY AND NLROUTE_LIBRARY) + set(NL_LIBRARY ${NL3_LIBRARY}) + if(NL3_INCLUDE_DIR) + # NL2 and NL3 are similar and just affect how the version is reported in + # the --version output. In cast of doubt, assume NL3 since a library + # without version number could be any of 2.0, 3.0 or 3.1. + if(NOT NL3_FOUND AND NL2_FOUND) + set(HAVE_LIBNL2 1) + else() + set(HAVE_LIBNL3 1) + endif() + endif() + endif() + set(NL_INCLUDE_DIR ${NL3_INCLUDE_DIR}) + endif() + + # libnl-2 and libnl-3 not found, try NL version 1 + if(NOT (NL_LIBRARY AND NL_INCLUDE_DIR)) + pkg_search_module(NL1 libnl-1) + find_path(NL1_INCLUDE_DIR + NAMES + netlink/netlink.h + HINTS + "${NL1_INCLUDEDIR}" + PATHS + $(SEARCHPATHS) + ) + find_library(NL1_LIBRARY + NAMES + nl + PATH_SUFFIXES + lib64 lib + HINTS + "${NL1_LIBDIR}" + PATHS + $(SEARCHPATHS) + ) + set(NL_LIBRARY ${NL1_LIBRARY}) + set(NL_INCLUDE_DIR ${NL1_INCLUDE_DIR}) + if(NL1_LIBRARY AND NL1_INCLUDE_DIR) + set(HAVE_LIBNL1 1) + endif() + endif() +endif() +# MESSAGE(STATUS "LIB Found: ${NL_LIBRARY}, Suffix: ${NLSUFFIX}\n 1:${HAVE_LIBNL1}, 2:${HAVE_LIBNL2}, 3:${HAVE_LIBNL3}.") + +# handle the QUIETLY and REQUIRED arguments and set NL_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(NL DEFAULT_MSG NL_LIBRARY NL_INCLUDE_DIR) + +IF(NL_FOUND) + set(NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY}) + set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIR}) + set(HAVE_LIBNL 1) +else() + set(NL_LIBRARIES ) + set(NL_INCLUDE_DIRS) +endif() + +MARK_AS_ADVANCED( NL_LIBRARIES NL_INCLUDE_DIRS ) + diff --git a/cmake/modules/FindNSIS.cmake b/cmake/modules/FindNSIS.cmake new file mode 100644 index 0000000..1b68cd3 --- /dev/null +++ b/cmake/modules/FindNSIS.cmake @@ -0,0 +1,13 @@ +# +# - Find NSIS +# Find the makensis command +# +# MAKENSIS_EXECUTABLE - path to the makensis utility. +# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS - System runtime DLLs + +# Find makensis +set(_PF86 "PROGRAMFILES(x86)") +find_program(MAKENSIS_EXECUTABLE makensis + PATH "$ENV{PROGRAMFILES}/NSIS" "$ENV{${_PF86}}/NSIS" "$ENV{PROGRAMW6432}/NSIS" + DOC "Path to the makensis utility." +) diff --git a/cmake/modules/FindOPUS.cmake b/cmake/modules/FindOPUS.cmake new file mode 100644 index 0000000..0e7cfe2 --- /dev/null +++ b/cmake/modules/FindOPUS.cmake @@ -0,0 +1,57 @@ +# Find the system's opus includes and library +# +# OPUS_INCLUDE_DIRS - where to find opus.h +# OPUS_LIBRARIES - List of libraries when using opus +# OPUS_FOUND - True if opus found +# OPUS_DLL_DIR - (Windows) Path to the opus DLL +# OPUS_DLL - (Windows) Name of the opus DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "opus-.*" "OPUS_HINTS" ) + +if (NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(OPUS opus) +endif() + +find_path(OPUS_INCLUDE_DIR + NAMES opus/opus.h + HINTS + "${OPUS_INCLUDE_DIRS}" + "${OPUS_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library(OPUS_LIBRARY + NAMES opus + HINTS + "${OPUS_LIBRARY_DIRS}" + "${OPUS_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OPUS DEFAULT_MSG OPUS_LIBRARY OPUS_INCLUDE_DIR) + +if( OPUS_FOUND ) + set( OPUS_INCLUDE_DIRS ${OPUS_INCLUDE_DIR} ) + set( OPUS_LIBRARIES ${OPUS_LIBRARY} ) + if (WIN32) + set ( OPUS_DLL_DIR "${OPUS_HINTS}/bin" + CACHE PATH "Path to opus DLL" + ) + file( GLOB _opus_dll RELATIVE "${OPUS_DLL_DIR}" + "${OPUS_DLL_DIR}/opus.dll" + ) + set ( OPUS_DLL ${_opus_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "opus DLL file name" + ) + mark_as_advanced( OPUS_DLL_DIR OPUS_DLL ) + endif() +else() + set( OPUS_INCLUDE_DIRS ) + set( OPUS_LIBRARIES ) +endif() + +mark_as_advanced( OPUS_LIBRARIES OPUS_INCLUDE_DIRS ) diff --git a/cmake/modules/FindPCAP.cmake b/cmake/modules/FindPCAP.cmake new file mode 100644 index 0000000..eb9565b --- /dev/null +++ b/cmake/modules/FindPCAP.cmake @@ -0,0 +1,329 @@ +# +# - Find libpcap +# Find the native PCAP includes and library +# +# PCAP_INCLUDE_DIRS - where to find pcap.h, etc. +# PCAP_LIBRARIES - List of libraries when using pcap. +# PCAP_FOUND - True if pcap found. + +include(FindWSWinLibs) +FindWSWinLibs("libpcap-*" "PCAP_HINTS") + +# +# First, try pkg-config on platforms other than Windows. +# +if(NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(PC_PCAP libpcap) +endif() + +if(NOT PC_PCAP_FOUND AND NOT WIN32) + # + # That didn't work. Try to retrieve hints from pcap-config. + # Do not use it on Windows as pcap-config is a shell script. + # + find_program(PCAP_CONFIG pcap-config) + if(PCAP_CONFIG) + # + # We have pcap-config; use it. + # + # First, get the include directory. + # + execute_process(COMMAND "${PCAP_CONFIG}" "--cflags" + RESULT_VARIABLE PCAP_CONFIG_RESULT + OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT PCAP_CONFIG_RESULT EQUAL 0) + message(FATAL_ERROR "pcap-config --cflags failed") + endif() + # + # Assumes there's exactly one -I flag in the output + # of pcap-config --cflags. That *should* be the case. + # Note that the hint might be bogus, on macOS it could be + # -I/usr/local/include even though the header isn't + # there (it may be under /usr/include or it may be + # buried in the Xcode app bundle). + # + string(REGEX REPLACE "^-I" "" PCAP_CONFIG_INCLUDE_DIRS "${PCAP_CONFIG_OUTPUT}") + + # Now, get the library search path. + execute_process(COMMAND "${PCAP_CONFIG}" "--libs" + RESULT_VARIABLE PCAP_CONFIG_RESULT + OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT PCAP_CONFIG_RESULT EQUAL 0) + message(FATAL_ERROR "pcap-config --libs failed") + endif() + separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT}) + set(PCAP_CONFIG_LIBRARY_DIRS "") + foreach(_arg IN LISTS LIBS_LIST) + # At most one -L path is expected for -lpcap. + if(_arg MATCHES "^-L") + string(REGEX REPLACE "^-L" "" _dir ${_arg}) + list(APPEND PCAP_CONFIG_LIBRARY_DIRS ${_dir}) + endif() + endforeach() + + if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a") + # Now, get the library directories and libraries for static linking. + # (XXX - what about AIX?) + execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static" + RESULT_VARIABLE PCAP_CONFIG_RESULT + OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT + ) + if(NOT PCAP_CONFIG_RESULT EQUAL 0) + message(FATAL_ERROR "pcap-config --libs --static failed") + endif() + separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT}) + set(PCAP_CONFIG_STATIC_LIBRARY_DIRS "") + set(PCAP_CONFIG_STATIC_LIBRARIES "") + foreach(_arg IN LISTS LIBS_LIST) + if(_arg MATCHES "^-L") + # Add this directory to the library directory hints. + string(REGEX REPLACE "^-L" "" _dir ${_arg}) + list(APPEND PCAP_CONFIG_STATIC_LIBRARY_DIRS ${_dir}) + elseif(_arg MATCHES "^-l") + # Add this library to the requirements for static linking. + string(REGEX REPLACE "^-l" "" _lib ${_arg}) + list(APPEND PCAP_CONFIG_STATIC_LIBRARIES ${_lib}) + endif() + endforeach() + endif() + endif() +endif() + +# +# Locate the actual include directory. For pkg-config the +# PC_PCAP_INCLUDE_DIRS variable could be empty if the default +# header search path is sufficient to locate the header file. +# For macOS, the directory returned by pcap-config is wrong, so +# this will make sure to find a valid path. +# +find_path(PCAP_INCLUDE_DIR + NAMES + pcap/pcap.h + pcap.h + PATH_SUFFIXES + wpcap + HINTS + ${PC_PCAP_INCLUDE_DIRS} + ${PCAP_CONFIG_INCLUDE_DIRS} + "${PCAP_HINTS}/Include" +) + +# On Windows we load wpcap.dll explicitly and probe its functions in +# capture\capture-wpcap.c. We don't want to link with pcap.lib since +# that would bring in the non-capturing (null) pcap.dll from the vcpkg +# library. +if(WIN32 AND NOT CMAKE_CROSSCOMPILING) + set(_pkg_required_vars PCAP_INCLUDE_DIR) +else() + find_library(PCAP_LIBRARY + NAMES + pcap + wpcap + HINTS + ${PC_PCAP_LIBRARY_DIRS} + ${PCAP_CONFIG_LIBRARY_DIRS} + ) + set(_pkg_required_vars PCAP_LIBRARY PCAP_INCLUDE_DIR) +endif() + +if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a") + # Try to find the static library (XXX - what about AIX?) + if(PC_PCAP_FOUND) + set(_pcap_static_libraries ${PC_PCAP_STATIC_LIBRARIES}) + elseif(PCAP_CONFIG) + set(_pcap_static_libraries ${PCAP_CONFIG_STATIC_LIBRARIES}) + else() + # + # No pkg-config nor pcap-config found, hope that this single library is + # sufficient for static linking. + # + set(_pcap_static_libraries pcap) + endif() + + set(PCAP_STATIC_LIBRARIES "") + foreach(_lib IN LISTS _pcap_static_libraries) + # + # Try to find that library, so we get its full path, as + # we do with dynamic libraries. + # + string(MAKE_C_IDENTIFIER "PCAP_STATIC_${_lib}_LIBRARY" _libvar) + find_library(${_libvar} ${_lib} + HINTS + ${PC_PCAP_STATIC_LIBRARY_DIRS} + ${PCAP_CONFIG_STATIC_LIBRARY_DIRS} + ) + set(_libpath ${${_libvar}}) + if(_libpath) + list(APPEND PCAP_STATIC_LIBRARIES ${_libpath}) + endif() + endforeach() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCAP DEFAULT_MSG ${_pkg_required_vars}) +mark_as_advanced(${_pkg_required_vars}) + +if(PCAP_FOUND) + set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR}) + if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a") + # Link with static libpcap and its transitive dependencies. + set(PCAP_LIBRARIES ${PCAP_STATIC_LIBRARIES}) + else() + set(PCAP_LIBRARIES ${PCAP_LIBRARY}) + endif() + + #Functions + include( CMakePushCheckState ) + include( CheckFunctionExists ) + include( CheckVariableExists ) + + cmake_push_check_state() + set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} ) + set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ) + + include(CheckSymbolExists) + + if(WIN32 AND NOT CMAKE_CROSSCOMPILING) + # + # Prepopulate some values. WinPcap 3.1 and later, and Npcap, have these + # in their SDK, and compilation checks on Windows can be slow. We check + # whether they're present at run time, when we load wpcap.dll, and work + # around their absence or report an error. + # + set(HAVE_PCAP_FREECODE TRUE) + set(HAVE_PCAP_CREATE TRUE) + set(HAVE_PCAP_FREE_DATALINKS TRUE) + set(HAVE_PCAP_OPEN TRUE) + set(HAVE_PCAP_SETSAMPLING TRUE) + set(HAVE_PCAP_SET_TSTAMP_PRECISION TRUE) + set(HAVE_PCAP_SET_TSTAMP_TYPE TRUE) + else(WIN32) + # + # Make sure we have at least libpcap 0.8, because we require at + # least libpcap 0.8's APIs. + # + # We check whether pcap_lib_version is defined in the pcap header, + # using it as a proxy for all the 0.8 API's. if not, we fail. + # + check_symbol_exists( pcap_lib_version ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_LIB_VERSION ) + if( NOT HAVE_PCAP_LIB_VERSION ) + message(FATAL_ERROR "You need libpcap 0.8 or later") + endif( NOT HAVE_PCAP_LIB_VERSION ) + + check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) + check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) + check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) + # + # macOS Sonoma's libpcap includes stub versions of the remote- + # capture APIs. They are exported as "weakly linked symbols". + # + # Xcode 15 offers only a macOS Sonoma SDK, which has a .tbd + # file for libpcap that claims it includes those APIs. (Newer + # versions of macOS don't provide the system shared libraries, + # they only provide the dyld shared cache containing those + # libraries, so the OS provides SDKs that include a .tbd file + # to use when linking.) + # + # This means that check_function_exists() will think that + # the remote-capture APIs are present, including pcap_open(). + # + # However, they are *not* present in macOS Ventura and earlier, + # which means that building on Ventura with Xcode 15 produces + # executables that fail to start because one of those APIs + # isn't found in the system libpcap. + # + # Protecting calls to those APIs with __builtin_available() + # does not prevent this, because the libpcap header files + # in the Sonoma SDK mark them as being first available + # in macOS 10.13, just like all the other routines introduced + # in libpcap 1.9, even though they're only available if libpcap + # is built with remote capture enabled or stub routines are + # provided. (A fix to enable this has been checked into the + # libpcap repository, and may end up in a later version of + # the SDK.) + # + # Given all that, and given that the versions of the + # remote-capture APIs in Sonoma are stubs that always fail, + # there doesn't seem to be any point in checking for pcap_open() + # if we're linking against the Apple libpcap. + # + # However, if we're *not* linking against the Apple libpcap, + # we should check for it, so that we can use it if it's present. + # + # So we check for pcap_open if 1) this isn't macOS or 2) the + # the libpcap we found is not a system library, meaning that + # its path begins neither with /usr/lib (meaning it's a system + # dylib) nor /Application/Xcode.app (meaning it's a file in + # the Xcode SDK). + # + if( NOT APPLE OR NOT + (PCAP_LIBRARY MATCHES "/usr/lib/.*" OR + PCAP_LIBRARY MATCHES "/Application/Xcode.app/.*")) + check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) + endif() + if( HAVE_PCAP_OPEN ) + # + # XXX - this *should* be checked for independently of checking + # for pcap_open(), as you might have pcap_setsampling() without + # remote capture support. + # + # However, 1) the sampling options are treated as remote options + # in the GUI and 2) having pcap_setsampling() doesn't mean + # you have sampling support. libpcap needs a way to indicate + # whether a given device supports sampling, and the GUI should + # be changed to decouple them. + # + # (Actually, libpcap needs a general mechanism to offer options + # for particular devices, and Wireshark needs to use that + # mechanism. The former is a work in progress.) + # + # (Note: another work in progress is support for remote + # capturing using pcap_create()/pcap_activate(), which we + # also need to support once it's available.) + # + check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) + endif( HAVE_PCAP_OPEN ) + endif() + + if( HAVE_PCAP_CREATE ) + # + # If we have pcap_create(), we have pcap_set_buffer_size(), and + # can set the capture buffer size. + # + # Otherwise, if this is Windows, we have pcap_setbuff(), and can + # set the capture buffer size. + # + set( CAN_SET_CAPTURE_BUFFER_SIZE TRUE ) + endif() + check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION ) + check_function_exists( "pcap_set_tstamp_type" HAVE_PCAP_SET_TSTAMP_TYPE ) + # Remote pcap checks + if( HAVE_PCAP_OPEN ) + set( HAVE_PCAP_REMOTE 1 ) + endif() + + check_symbol_exists(PCAP_ERROR_PROMISC_PERM_DENIED ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_ERROR_PROMISC_PERM_DENIED) + check_symbol_exists(PCAP_WARNING_TSTAMP_TYPE_NOTSUP ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_WARNING_TSTAMP_TYPE_NOTSUP) + + cmake_pop_check_state() +endif() + +if(PCAP_FOUND AND NOT TARGET pcap::pcap) + if(WIN32) + add_library(pcap::pcap INTERFACE IMPORTED) + set_target_properties(pcap::pcap PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCAP_INCLUDE_DIRS}" + ) + else() + add_library(pcap::pcap UNKNOWN IMPORTED) + set_target_properties(pcap::pcap PROPERTIES + IMPORTED_LOCATION "${PCAP_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${PCAP_INCLUDE_DIRS}" + ) + endif() +endif() diff --git a/cmake/modules/FindPCRE2.cmake b/cmake/modules/FindPCRE2.cmake new file mode 100644 index 0000000..a7d8079 --- /dev/null +++ b/cmake/modules/FindPCRE2.cmake @@ -0,0 +1,102 @@ +# +# - Find PCRE2 libraries +# +# PCRE2_INCLUDE_DIRS - where to find PCRE2 headers. +# PCRE2_LIBRARIES - List of libraries when using PCRE2. +# PCRE2_FOUND - True if PCRE2 is found. +# PCRE2_RELEASE_DLL_DIR - (Windows) Path to the PCRE2 release DLL +# PCRE2_RELEASE_DLL - (Windows) Name of the PCRE2 release DLL +# PCRE2_DEBUG_DLL_DIR - (Windows) Path to the PCRE2 debug DLL +# PCRE2_DEBUG_DLL - (Windows) Name of the PCRE2 debug DLL + +# Note that the "8" in "libpcre2-8" refers to "PCRE library version 2 with +# support for 8-bit code units". + +include( FindWSWinLibs ) +# PCRE2 is included with GLib2 +FindWSWinLibs( "vcpkg-export-.*" "PCRE2_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_search_module(PC_PCRE2 QUIET "libpcre2-8") +endif() + +find_path(PCRE2_INCLUDE_DIR + NAMES + pcre2.h + HINTS + ${PC_PCRE2_INCLUDE_DIRS} + ${PCRE2_HINTS}/include +) + +find_library(PCRE2_LIBRARY + NAMES + pcre2-8 + HINTS + ${PC_PCRE2_LIBRARY_DIRS} + ${PCRE2_HINTS}/lib +) + +if (USE_REPOSITORY) + find_library(PCRE2_DEBUG_LIBRARY + NAMES + pcre2-8d + HINTS + ${PCRE2_HINTS}/debug/lib + ) +else() + set (PCRE2_DEBUG_LIBRARY ${PCRE2_LIBRARY} CACHE FILEPATH "PCRE2 library") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE2 + REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR + VERSION_VAR PC_PCRE2_VERSION +) + +if(PCRE2_FOUND) + set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) + set(PCRE2_DEBUG_LIBRARIES ${PCRE2_DEBUG_LIBRARY}) + set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) + if (USE_REPOSITORY) + set (PCRE2_RELEASE_DLL_DIR "${PCRE2_HINTS}/bin" + CACHE PATH "Path to PCRE2 release DLL" + ) + file(GLOB _pcre2_release_dll RELATIVE "${PCRE2_RELEASE_DLL_DIR}" + "${PCRE2_RELEASE_DLL_DIR}/pcre2-8*.dll" + ) + set (PCRE2_RELEASE_DLL ${_pcre2_release_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "PCRE2 release DLL file name" + ) + file(GLOB _pcre2_release_pdb RELATIVE "${PCRE2_RELEASE_DLL_DIR}" + "${PCRE2_RELEASE_DLL_DIR}/pcre2-8*.pdb" + ) + set (PCRE2_RELEASE_PDB ${_pcre2_release_pdb} + CACHE FILEPATH "PCRE2 release PDB file name" + ) + + set (PCRE2_DEBUG_DLL_DIR "${PCRE2_HINTS}/debug/bin" + CACHE PATH "Path to PCRE2 debug DLL" + ) + file(GLOB _pcre2_debug_dll RELATIVE "${PCRE2_DEBUG_DLL_DIR}" + "${PCRE2_DEBUG_DLL_DIR}/pcre2-8d*.dll" + ) + set (PCRE2_DEBUG_DLL ${_pcre2_debug_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "PCRE2 debug DLL file name" + ) + file(GLOB _pcre2_debug_pdb RELATIVE "${PCRE2_DEBUG_DLL_DIR}" + "${PCRE2_DEBUG_DLL_DIR}/pcre2-8d*.pdb" + ) + set (PCRE2_DEBUG_PDB ${_pcre2_debug_pdb} + CACHE FILEPATH "PCRE2 debug PDB file name" + ) + mark_as_advanced(PCRE2_RELEASE_DLL_DIR PCRE2_RELEASE_DLL PCRE2_PDB PCRE2_DEBUG_DLL_DIR PCRE2_DEBUG_DLL) + endif() +else() + set(PCRE2_LIBRARIES) + set(PCRE2_INCLUDE_DIRS) +endif() + +mark_as_advanced(PCRE2_LIBRARIES PCRE2_INCLUDE_DIRS) diff --git a/cmake/modules/FindPortableApps.cmake b/cmake/modules/FindPortableApps.cmake new file mode 100644 index 0000000..17ee15a --- /dev/null +++ b/cmake/modules/FindPortableApps.cmake @@ -0,0 +1,26 @@ +# +# - Find PortableApps +# Find the PortableApps LauncherGenerator and Installer commands +# +# PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE - path to the PortableApps.comLauncherGenerator utility. +# PORTABLEAPPS_INSTALLER_EXECUTABLE - path to the PortableApps.comInstaller utility. + +# Find PortableApps.comLauncherGenerator +find_program(PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE PortableApps.comLauncherGenerator + PATH + "C:/PortableApps/PortableApps.comLauncher" + "$ENV{USERPROFILE}/PortableApps/PortableApps.comLauncher" + DOC "Path to the PortableApps.comLauncherGenerator utility." +) + +# Find PortableApps.comInstaller +find_program(PORTABLEAPPS_INSTALLER_EXECUTABLE PortableApps.comInstaller + PATH + "C:/PortableApps/PortableApps.comInstaller" + "$ENV{USERPROFILE}/PortableApps/PortableApps.comInstaller" + DOC "Path to the PortableApps.comInstaller utility." +) + +# Assume that FindNSIS has taken care of this for us. +# set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) +# include(InstallRequiredSystemLibraries) diff --git a/cmake/modules/FindPowerShell.cmake b/cmake/modules/FindPowerShell.cmake new file mode 100644 index 0000000..307d7e7 --- /dev/null +++ b/cmake/modules/FindPowerShell.cmake @@ -0,0 +1,32 @@ +# +# Find PowerShell +# This module looks for PowerShell and sets the following: +# POWERSHELL_EXECUTABLE - Path to PowerShell. +# POWERSHELL_COMMAND - Command suitable for running .ps1 scripts +# +# To do: +# - Add a version check +# + +find_program(POWERSHELL_EXECUTABLE + NAMES + powershell + pwsh + DOC "PowerShell command" +) + +INCLUDE(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PowerShell DEFAULT_MSG POWERSHELL_EXECUTABLE) + +set(_powershell_command "POWERSHELL_COMMAND-NOTFOUND") +if(POWERSHELL_FOUND) + # Calling a script using "-File" doesn't properly return exit codes. + # Use dot sourcing instead + # https://connect.microsoft.com/PowerShell/feedback/details/777375/powershell-exe-does-not-set-an-exit-code-when-file-is-used + set(_powershell_command "${POWERSHELL_EXECUTABLE}" -NoProfile -NonInteractive -executionpolicy bypass .) +endif() +set(POWERSHELL_COMMAND ${_powershell_command} + CACHE STRING "Command suitable for running PowerShell scripts." +) + +mark_as_advanced(POWERSHELL_EXECUTABLE POWERSHELL_COMMAND) diff --git a/cmake/modules/FindSBC.cmake b/cmake/modules/FindSBC.cmake new file mode 100644 index 0000000..e9b90d7 --- /dev/null +++ b/cmake/modules/FindSBC.cmake @@ -0,0 +1,51 @@ +# Find the native Bluetooth SBC Codec includes and library +# +# SBC_INCLUDE_DIRS - where to find sbc.h +# SBC_LIBRARIES - List of libraries when using SBC +# SBC_FOUND - True if SBC found +# SBC_DLL_DIR - (Windows) Path to the SBC DLL +# SBC_DLL - (Windows) Name of the SBC DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "sbc-.*" "SBC_HINTS" ) + +find_path( SBC_INCLUDE_DIR + NAMES + sbc/sbc.h + HINTS + "${SBC_HINTS}/include" +) + +find_library( SBC_LIBRARY + NAMES + sbc + libsbc-1 + HINTS + "${SBC_HINTS}/lib" +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( SBC DEFAULT_MSG SBC_LIBRARY SBC_INCLUDE_DIR ) + +if( SBC_FOUND ) + set( SBC_INCLUDE_DIRS ${SBC_INCLUDE_DIR} ) + set( SBC_LIBRARIES ${SBC_LIBRARY} ) + if (WIN32) + set ( SBC_DLL_DIR "${SBC_HINTS}/bin" + CACHE PATH "Path to SBC DLL" + ) + file( GLOB _sbc_dll RELATIVE "${SBC_DLL_DIR}" + "${SBC_DLL_DIR}/libsbc-*.dll" + ) + set ( SBC_DLL ${_sbc_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "SBC DLL file name" + ) + mark_as_advanced( SBC_DLL_DIR SBC_DLL ) + endif() +else() + set( SBC_INCLUDE_DIRS ) + set( SBC_LIBRARIES ) +endif() + +mark_as_advanced( SBC_LIBRARIES SBC_INCLUDE_DIRS ) diff --git a/cmake/modules/FindSETCAP.cmake b/cmake/modules/FindSETCAP.cmake new file mode 100644 index 0000000..1c468bd --- /dev/null +++ b/cmake/modules/FindSETCAP.cmake @@ -0,0 +1,19 @@ +# +# Look for the Linux setcap command (capabilities) +# + +find_program( SETCAP_EXECUTABLE + NAMES + setcap + PATHS + /bin + /usr/bin + /usr/local/bin + /sbin +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( SETCAP DEFAULT_MSG SETCAP_EXECUTABLE ) + +mark_as_advanced( SETCAP_EXECUTABLE ) + diff --git a/cmake/modules/FindSMI.cmake b/cmake/modules/FindSMI.cmake new file mode 100644 index 0000000..0fe3973 --- /dev/null +++ b/cmake/modules/FindSMI.cmake @@ -0,0 +1,72 @@ +# +# - Find smi +# Find the native SMI includes and library +# +# SMI_INCLUDE_DIRS - where to find smi.h, etc. +# SMI_LIBRARIES - List of libraries when using smi. +# SMI_FOUND - True if smi found. +# SMI_DLL_DIR - (Windows) Path to the SMI DLL. +# SMI_DLL - (Windows) Name of the SMI DLL. +# SMI_SHARE_DIR - (Windows) Path to the SMI MIBs. + + +IF (SMI_INCLUDE_DIR) + # Already in cache, be silent + SET(SMI_FIND_QUIETLY TRUE) +ENDIF (SMI_INCLUDE_DIR) + +INCLUDE(FindWSWinLibs) +FindWSWinLibs("libsmi-.*" "SMI_HINTS") + +FIND_PATH(SMI_INCLUDE_DIR smi.h HINTS "${SMI_HINTS}/include" ) + +IF(MSVC) + SET(SMI_NAMES libsmi-2) +ELSE() + SET(SMI_NAMES smi libsmi-2) +ENDIF() +FIND_LIBRARY(SMI_LIBRARY NAMES ${SMI_NAMES} HINTS "${SMI_HINTS}/lib" ) + +# handle the QUIETLY and REQUIRED arguments and set SMI_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SMI DEFAULT_MSG SMI_LIBRARY SMI_INCLUDE_DIR) + +IF(SMI_FOUND) + SET( SMI_LIBRARIES ${SMI_LIBRARY} ) + SET( SMI_INCLUDE_DIRS ${SMI_INCLUDE_DIR} ) + if (WIN32) + set ( SMI_DLL_DIR "${SMI_HINTS}/bin" + CACHE PATH "Path to the SMI DLL" + ) + set ( SMI_SHARE_DIR "${SMI_HINTS}/share" + CACHE PATH "Path to the SMI MIBs" + ) + file( GLOB _smi_dll RELATIVE "${SMI_DLL_DIR}" + "${SMI_DLL_DIR}/libsmi-*.dll" + ) + set ( SMI_DLL ${_smi_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "SMI DLL file name" + ) + mark_as_advanced( SMI_DLL_DIR SMI_DLL ) + endif() + + include(CheckSymbolExists) + cmake_push_check_state() + set(CMAKE_REQUIRED_INCLUDES ${SMI_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES ${SMI_LIBRARIES}) + # On Windows symbol visibility for global variables defaults to hidden + # and libsmi doesn't use any visibility decorators. + check_symbol_exists("smi_version_string" "smi.h" HAVE_SMI_VERSION_STRING) + cmake_pop_check_state() + +ELSE(SMI_FOUND) + SET( SMI_LIBRARIES ) + SET( SMI_INCLUDE_DIRS ) + SET( SMI_DLL_DIR ) + SET( SMI_SHARE_DIR ) + SET( SMI_DLL ) +ENDIF(SMI_FOUND) + +MARK_AS_ADVANCED( SMI_LIBRARIES SMI_INCLUDE_DIRS ) diff --git a/cmake/modules/FindSNAPPY.cmake b/cmake/modules/FindSNAPPY.cmake new file mode 100644 index 0000000..afcfc71 --- /dev/null +++ b/cmake/modules/FindSNAPPY.cmake @@ -0,0 +1,58 @@ +# +# - Find snappy +# Find Snappy includes and library +# +# SNAPPY_INCLUDE_DIRS - where to find snappy.h, etc. +# SNAPPY_LIBRARIES - List of libraries when using Snappy. +# SNAPPY_FOUND - True if Snappy found. +# SNAPPY_DLL_DIR - (Windows) Path to the Snappy DLL +# SNAPPY_DLL - (Windows) Name of the Snappy DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "snappy-.*" "SNAPPY_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig QUIET) + pkg_search_module(SNAPPY QUIET libsnappy) +endif() + +find_path(SNAPPY_INCLUDE_DIR + NAMES snappy.h + HINTS "${SNAPPY_INCLUDEDIR}" "${SNAPPY_HINTS}/include" + /usr/include + /usr/local/include +) + +find_library(SNAPPY_LIBRARY + NAMES snappy + HINTS "${SNAPPY_LIBDIR}" "${SNAPPY_HINTS}/lib" + PATHS + /usr/lib + /usr/local/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( SNAPPY DEFAULT_MSG SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR ) + +if( SNAPPY_FOUND ) + set( SNAPPY_INCLUDE_DIRS ${SNAPPY_INCLUDE_DIR} ) + set( SNAPPY_LIBRARIES ${SNAPPY_LIBRARY} ) + if (WIN32) + set ( SNAPPY_DLL_DIR "${SNAPPY_HINTS}/bin" + CACHE PATH "Path to Snappy DLL" + ) + file( GLOB _snappy_dll RELATIVE "${SNAPPY_DLL_DIR}" + "${SNAPPY_DLL_DIR}/snappy*.dll" + ) + set ( SNAPPY_DLL ${_snappy_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "Snappy DLL file name" + ) + mark_as_advanced( SNAPPY_DLL_DIR SNAPPY_DLL ) + endif() +else() + set( SNAPPY_INCLUDE_DIRS ) + set( SNAPPY_LIBRARIES ) +endif() + +mark_as_advanced( SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIRS ) diff --git a/cmake/modules/FindSPANDSP.cmake b/cmake/modules/FindSPANDSP.cmake new file mode 100644 index 0000000..d4b6de2 --- /dev/null +++ b/cmake/modules/FindSPANDSP.cmake @@ -0,0 +1,66 @@ +# Find the system's SpanDSP includes and library +# +# SPANDSP_INCLUDE_DIRS - where to find spandsp.h +# SPANDSP_LIBRARIES - List of libraries when using SpanDSP +# SPANDSP_FOUND - True if SpanDSP found +# SPANDSP_DLL_DIR - (Windows) Path to the SpanDSP DLL +# SPANDSP_DLL - (Windows) Name of the SpanDSP DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "spandsp-.*" "SPANDSP_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(SPANDSP spandsp) + + # spandsp.h might include tiffio.h. + find_package(TIFF QUIET) +endif() + + +find_path( SPANDSP_INCLUDE_DIR + NAMES spandsp.h + HINTS + "${SPANDSP_INCLUDEDIR}" + "${SPANDSP_HINTS}/include" + PATHS /usr/local/include /usr/include +) + +find_library( SPANDSP_LIBRARY + NAMES + spandsp + libspandsp-2 + HINTS + "${SPANDSP_LIBDIR}" + "${SPANDSP_HINTS}/lib" + PATHS /usr/local/lib /usr/lib +) + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( SPANDSP DEFAULT_MSG SPANDSP_LIBRARY SPANDSP_INCLUDE_DIR ) + +if( SPANDSP_FOUND ) + set( SPANDSP_INCLUDE_DIRS ${SPANDSP_INCLUDE_DIR} ) + if( TIFF_FOUND ) + list(APPEND SPANDSP_INCLUDE_DIRS ${TIFF_INCLUDE_DIR}) + endif() + set( SPANDSP_LIBRARIES ${SPANDSP_LIBRARY} ) + if (WIN32) + set ( SPANDSP_DLL_DIR "${SPANDSP_HINTS}/bin" + CACHE PATH "Path to SpanDSP DLL" + ) + file( GLOB _spandsp_dll RELATIVE "${SPANDSP_DLL_DIR}" + "${SPANDSP_DLL_DIR}/libspandsp-*.dll" + ) + set ( SPANDSP_DLL ${_spandsp_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "SpanDSP DLL file name" + ) + mark_as_advanced( SPANDSP_DLL_DIR SPANDSP_DLL ) + endif() +else() + set( SPANDSP_INCLUDE_DIRS ) + set( SPANDSP_LIBRARIES ) +endif() + +mark_as_advanced( SPANDSP_LIBRARIES SPANDSP_INCLUDE_DIRS ) diff --git a/cmake/modules/FindSinsp.cmake b/cmake/modules/FindSinsp.cmake new file mode 100644 index 0000000..9729b02 --- /dev/null +++ b/cmake/modules/FindSinsp.cmake @@ -0,0 +1,176 @@ +# +# - Find libsinsp and libscap +# Find libsinsp and libscap includes and libraries. +# Adapted from FindZSTD.cmake. +# +# This module will look for libsinsp and libscap using pkg-config. If that +# fails, it will search ${SINSP_INCLUDEDIR} and ${SINSP_HINTS}/include +# for the libsinsp and libscap include directory and ${SINSP_LIBDIR} and +# ${SINSP_HINTS}/lib for the libsinsp and libscap libraries. +# +# It will set the following variables: +# +# SINSP_FOUND - True if libsinsp found. +# SINSP_INCLUDE_DIRS - Where to find sinsp.h, scap.h, etc. +# SINSP_LINK_LIBRARIES - List of libraries when using libsinsp. + +# You must manually set the following variables: +# FALCO_PLUGINS - Paths to plugins built from https://github.com/falcosecurity/plugins/. + +# To do: +# SINSP_DLL_DIR - (Windows) Path to the libsinsp and libscap DLLs +# SINSP_DLL - (Windows) Name of the libsinsp and libscap DLLs + +include( FindWSWinLibs ) +FindWSWinLibs( "libsinsp-.*" "SINSP_HINTS" ) + +include(CMakeDependentOption) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_check_modules(SINSP libsinsp) +endif() + +if(NOT SINSP_FOUND) + # pkg_check_modules didn't work, so look for ourselves. + find_path(SINSP_INCLUDE_DIRS + NAMES sinsp.h + HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include" + PATH_SUFFIXES falcosecurity/userspace/libsinsp + /usr/include + /usr/local/include + ) + + find_path(_scap_include_dir + NAMES scap.h + HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include" + PATH_SUFFIXES falcosecurity/userspace/libscap + /usr/include + /usr/local/include + ) + if(_scap_include_dir) + list(APPEND SINSP_INCLUDE_DIRS _scap_include_dir) + endif() + unset(_scap_include_dir) + + find_library(SINSP_LINK_LIBRARIES + NAMES sinsp + HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" + PATHS falcosecurity + /usr/lib + /usr/local/lib + ) + + set(_scap_libs + scap + scap_engine_util + scap_event_schema + driver_event_schema + scap_engine_bpf + scap_engine_gvisor + scap_engine_kmod + scap_engine_nodriver + scap_engine_noop + scap_engine_savefile + scap_engine_source_plugin + scap_engine_udig + ) + + foreach(_scap_lib ${_scap_libs}) + find_library(_lib + NAMES ${_scap_lib} + HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" + PATHS falcosecurity + /usr/lib + /usr/local/lib + ) + if (_lib) + list(APPEND SINSP_LINK_LIBRARIES ${_lib}) + endif() + endforeach() + unset(_scap_libs) + unset(_scap_lib) + unset(_lib) + if(SINSP_INCLUDE_DIRS AND JSONCPP_LIBRARY) + set(SINSP_FOUND 1) + endif() + + find_path(JSONCPP_INCLUDE_DIR + NAMES json/json.h + HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include" + PATH_SUFFIXES jsoncpp + /usr/include + /usr/local/include + ) + if (JSON_INCLUDE_DIR) + list(APPEND SINSP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) + endif() + + find_library(JSONCPP_LIBRARY + NAMES jsoncpp + HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" + PATHS + /usr/lib + /usr/local/lib + ) + if (JSONCPP_LIBRARY) + list(APPEND JSONCPP_LIBRARY ${JSONCPP_LIBRARY}) + endif() + + find_path(TBB_INCLUDE_DIR + NAMES tbb/tbb.h + HINTS "${SINSP_INCLUDEDIR}" "${SINSP_HINTS}/include" + /usr/include + /usr/local/include + ) + if (TBB_INCLUDE_DIR) + list(APPEND SINSP_INCLUDE_DIRS ${TBB_INCLUDE_DIR}) + endif() + + find_library(TBB_LIBRARY + NAMES tbb + HINTS "${SINSP_LIBDIR}" "${SINSP_HINTS}/lib" + PATHS + /usr/lib + /usr/local/lib + ) + if (TBB_LIBRARY) + list(APPEND JSONCPP_LIBRARY ${TBB_LIBRARY}) + endif() +endif() + +# As https://cmake.org/cmake/help/latest/command/link_directories.html +# says, "Prefer to pass full absolute paths to libraries where possible, +# since this ensures the correct library will always be linked," so use +# SINSP_LINK_LIBRARIES instead of SINSP_LIBRARIES +# XXX SINSP_VERSION will require peeking for a #define or something similar. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Sinsp + REQUIRED_VARS + SINSP_INCLUDE_DIRS + SINSP_LINK_LIBRARIES + # VERSION_VAR SINSP_VERSION +) + +if(SINSP_FOUND) +# if (WIN32) +# set ( SINSP_DLL_DIR "${SINSP_HINTS}/bin" +# CACHE PATH "Path to sinsp DLL" +# ) +# file( GLOB _SINSP_dll RELATIVE "${SINSP_DLL_DIR}" +# "${SINSP_DLL_DIR}/sinsp*.dll" +# ) +# set ( SINSP_DLL ${_SINSP_dll} +# # We're storing filenames only. Should we use STRING instead? +# CACHE FILEPATH "sinsp DLL file name" +# ) +# mark_as_advanced( SINSP_DLL_DIR SINSP_DLL ) +# endif() +else() + set(SINSP_INCLUDE_DIRS) + set(SINSP_LINK_LIBRARIES) +endif() + +cmake_dependent_option(FALCO_PLUGINS "Paths to Falco plugins. Semicolon-separated" "" SINSP_FOUND "") + +mark_as_advanced(SINSP_INCLUDE_DIRS SINSP_LINK_LIBRARIES) diff --git a/cmake/modules/FindSparkle.cmake b/cmake/modules/FindSparkle.cmake new file mode 100644 index 0000000..1969c02 --- /dev/null +++ b/cmake/modules/FindSparkle.cmake @@ -0,0 +1,51 @@ +# +# Find the Sparkle framework +# +# This defines the following: +# SPARKLE_FOUND - True if we found Sparkle +# SPARKLE_INCLUDE_DIRS - Path to Sparkle.h, empty if not found +# SPARKLE_LIBRARIES - Path to Sparkle.framework, empty if not found +# SPARKLE_VERSION - Sparkle framework bundle version + +include(FindPackageHandleStandardArgs) + +file(GLOB USR_LOCAL_HINT "/usr/local/Sparkle-[2-9]*/") +file(GLOB HOMEBREW_HINT "/usr/local/Caskroom/sparkle/[2-9]*/") + +find_path(SPARKLE_INCLUDE_DIR Sparkle.h + HINTS ${USR_LOCAL_HINT} ${HOMEBREW_HINT} +) +find_library(SPARKLE_LIBRARY NAMES Sparkle + HINTS ${USR_LOCAL_HINT} ${HOMEBREW_HINT} +) + +# Sparkle doesn't appear to provide a version macro, and its Info.plist versions +# are all over the place. Check for SPUStandardUpdaterController.h, which was +# added in version 2. +set(SPARKLE_VERSION 1) + +find_file(_spustandardupdatercontroller_h SPUStandardUpdaterController.h + ${SPARKLE_LIBRARY}/Headers + NO_DEFAULT_PATH +) + +if(_spustandardupdatercontroller_h) + set(SPARKLE_VERSION 2) +endif() + +unset(_spustandardupdatercontroller_h CACHE) + +find_package_handle_standard_args(Sparkle + REQUIRED_VARS SPARKLE_INCLUDE_DIR SPARKLE_LIBRARY + VERSION_VAR SPARKLE_VERSION +) + +if(SPARKLE_FOUND) + set(SPARKLE_LIBRARIES ${SPARKLE_LIBRARY} ) + set(SPARKLE_INCLUDE_DIRS ${SPARKLE_INCLUDE_DIR} ) +else(SPARKLE_FOUND) + set(SPARKLE_LIBRARIES ) + set(SPARKLE_INCLUDE_DIRS ) +endif(SPARKLE_FOUND) + +mark_as_advanced(SPARKLE_INCLUDE_DIR SPARKLE_LIBRARY) diff --git a/cmake/modules/FindSpeexDSP.cmake b/cmake/modules/FindSpeexDSP.cmake new file mode 100644 index 0000000..2df717d --- /dev/null +++ b/cmake/modules/FindSpeexDSP.cmake @@ -0,0 +1,58 @@ +# Find the system's SpeexDSP includes and library +# +# SPEEXDSP_INCLUDE_DIRS - where to find SpeexDSP headers +# SPEEXDSP_LIBRARIES - List of libraries when using SpeexDSP +# SPEEXDSP_FOUND - True if SpeexDSP found +# SPEEXDSP_DLL_DIR - (Windows) Path to the SpeexDSP DLL +# SPEEXDSP_DLL - (Windows) Name of the SpeexDSP DLL + +include(FindWSWinLibs) +FindWSWinLibs("speexdsp-.*" "SPEEXDSP_HINTS") + +if(NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(PC_SPEEXDSP speexdsp) +endif() + + +find_path(SPEEXDSP_INCLUDE_DIR + NAMES + speex/speex_resampler.h + HINTS + ${PC_SPEEXDSP_INCLUDE_DIRS} + ${SPEEXDSP_HINTS}/include +) + +find_library(SPEEXDSP_LIBRARY + NAMES + speexdsp + HINTS + ${PC_SPEEXDSP_LIBRARY_DIRS} + ${SPEEXDSP_HINTS}/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SpeexDSP DEFAULT_MSG SPEEXDSP_LIBRARY SPEEXDSP_INCLUDE_DIR) + +if(SPEEXDSP_FOUND) + set(SPEEXDSP_LIBRARIES ${SPEEXDSP_LIBRARY}) + set(SPEEXDSP_INCLUDE_DIRS ${SPEEXDSP_INCLUDE_DIR}) + if(WIN32) + set(SPEEXDSP_DLL_DIR "${SPEEXDSP_HINTS}/bin" + CACHE PATH "Path to SpeexDSP DLL" + ) + file(GLOB _speexdsp_dll RELATIVE "${SPEEXDSP_DLL_DIR}" + "${SPEEXDSP_DLL_DIR}/libspeexdsp.dll" + ) + set(SPEEXDSP_DLL ${_speexdsp_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "SpeexDSP DLL file name" + ) + mark_as_advanced(SPEEXDSP_DLL_DIR SPEEXDSP_DLL) + endif() +else() + set(SPEEXDSP_LIBRARIES) + set(SPEEXDSP_INCLUDE_DIRS) +endif() + +mark_as_advanced(SPEEXDSP_LIBRARIES SPEEXDSP_INCLUDE_DIRS) diff --git a/cmake/modules/FindSystemd.cmake b/cmake/modules/FindSystemd.cmake new file mode 100644 index 0000000..2fa2724 --- /dev/null +++ b/cmake/modules/FindSystemd.cmake @@ -0,0 +1,37 @@ +# +# - Find systemd libraries +# +# SYSTEMD_INCLUDE_DIRS - where to find systemd/sd-journal.h, etc. +# SYSTEMD_LIBRARIES - List of libraries when using libsystemd. +# SYSTEMD_FOUND - True if libsystemd is found. + +pkg_search_module(PC_SYSTEMD QUIET libsystemd) + +find_path(SYSTEMD_INCLUDE_DIR + NAMES + systemd/sd-journal.h + HINTS + ${PC_SYSTEMD_INCLUDE_DIRS} +) + +find_library(SYSTEMD_LIBRARY + NAMES + systemd + HINTS + ${PC_SYSTEMD_LIBRARY_DIRS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Systemd + REQUIRED_VARS SYSTEMD_LIBRARY SYSTEMD_INCLUDE_DIR + VERSION_VAR PC_SYSTEMD_VERSION) + +if(SYSTEMD_FOUND) + set(SYSTEMD_LIBRARIES ${SYSTEMD_LIBRARY}) + set(SYSTEMD_INCLUDE_DIRS ${SYSTEMD_INCLUDE_DIR}) +else() + set(SYSTEMD_LIBRARIES) + set(SYSTEMD_INCLUDE_DIRS) +endif() + +mark_as_advanced(SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS) diff --git a/cmake/modules/FindVLD.cmake b/cmake/modules/FindVLD.cmake new file mode 100644 index 0000000..cc9cdd7 --- /dev/null +++ b/cmake/modules/FindVLD.cmake @@ -0,0 +1,62 @@ +# +# - Find Visual Leak Detector +# +# VLD_LINK_FLAGS - MSVC linker flags that enable VLD +# VLD_FILES - files that should be copied to dll output directory +# VLD_VALID - TRUE if Visual Leak Detector was found + +set(_PF86 "PROGRAMFILES(x86)") +set(_vld_arch Win64) +set(_vld_dll vld_x64.dll) +set(_vld_pdb vld_x64.pdb) +if(WIRESHARK_TARGET_PLATFORM MATCHES "win32") + set(_vld_arch Win32) + set(_vld_dll vld_x86.dll) + set(_vld_pdb vld_x86.pdb) +endif() + +find_library(VLD_LIBRARY + NAMES + vld + HINTS + "$ENV{PROGRAMFILES}/Visual Leak Detector/lib/${_vld_arch}" + "$ENV{${_PF86}}/Visual Leak Detector/lib/${_vld_arch}" + "$ENV{PROGRAMW6432}/Visual Leak Detector/lib/${_vld_arch}" +) + +function(find_vld_file _vld_file _filename) + find_file(${_vld_file} + NAMES + ${_filename} + HINTS + "$ENV{PROGRAMFILES}/Visual Leak Detector/bin/${_vld_arch}" + "$ENV{${_PF86}}/Visual Leak Detector/bin/${_vld_arch}" + "$ENV{PROGRAMW6432}/Visual Leak Detector/bin/${_vld_arch}" + ) + if(${${_vld_file}} STREQUAL "${_vld_file}-NOTFOUND") + set(${_vld_file} "" PARENT_SCOPE) + endif() +endfunction() + +find_vld_file(VLD_DLL ${_vld_dll}) +find_vld_file(VLD_DBGHELP_DLL "dbghelp.dll") +find_vld_file(VLD_MANIFEST "Microsoft.DTfW.DHL.manifest") +find_vld_file(VLD_PDB ${_vld_pdb}) + +#library, dlls and manifest are mandatory, while pdb is optional +IF(VLD_LIBRARY AND (EXISTS ${VLD_DLL}) AND (EXISTS ${VLD_DBGHELP_DLL}) AND (EXISTS ${VLD_MANIFEST})) + # Link against VLD library and force it to be linked by referencing symbol + # Adding VLD_LINK_FLAGS to linker flags enables Visual Leak Detector + set(VLD_LINK_FLAGS "\"${VLD_LIBRARY}\" /include:__imp_?g_vld@@3VVisualLeakDetector@@A") + file(GLOB VLD_FILES + "${VLD_DLL}" + "${VLD_DBGHELP_DLL}" + "${VLD_MANIFEST}" + "${VLD_PDB}" + ) + set(VLD_FOUND TRUE) +else() + set(VLD_LINK_FLAGS) + set(VLD_FILES) + set(VLD_FOUND FALSE) +endif() diff --git a/cmake/modules/FindWSLibrary.cmake b/cmake/modules/FindWSLibrary.cmake new file mode 100644 index 0000000..c5c06ec --- /dev/null +++ b/cmake/modules/FindWSLibrary.cmake @@ -0,0 +1,37 @@ +# +# - Find WS Library +# This function is a wrapper for find_library() that does handle vcpkg exported +# library directory structure + +function(FindWSLibrary OUTPUT_LIBRARY) + cmake_parse_arguments( + WS_LIB + "" + "WIN32_HINTS" + "NAMES;HINTS;PATHS" + ${ARGN} + ) + + if (WIN32) + find_library(${OUTPUT_LIBRARY}_DEBUG + NAMES ${WS_LIB_NAMES} + HINTS "${WS_LIB_WIN32_HINTS}/debug/lib" + PATHS ${WS_LIB_PATHS} + ) + find_library(${OUTPUT_LIBRARY}_RELEASE + NAMES ${WS_LIB_NAMES} + HINTS "${WS_LIB_WIN32_HINTS}/lib" + PATHS ${WS_LIB_PATHS} + ) + + if (${OUTPUT_LIBRARY}_DEBUG AND ${OUTPUT_LIBRARY}_RELEASE) + set(${OUTPUT_LIBRARY} debug ${${OUTPUT_LIBRARY}_DEBUG} optimized ${${OUTPUT_LIBRARY}_RELEASE} PARENT_SCOPE) + endif() + else() + find_library(${OUTPUT_LIBRARY} + NAMES ${WS_LIB_NAMES} + HINTS ${WS_LIB_HINTS} + PATHS ${WS_LIB_PATHS} + ) + endif() +endfunction() diff --git a/cmake/modules/FindWSWinLibs.cmake b/cmake/modules/FindWSWinLibs.cmake new file mode 100644 index 0000000..c266082 --- /dev/null +++ b/cmake/modules/FindWSWinLibs.cmake @@ -0,0 +1,101 @@ +# +# - Find WSWin Libs +# Due to the layout of the Wireshark Win support libs, +# CMake needs some support to find them +# +# The function is passed the directory name to search for and the variable +# to set in the callers scope. + +function( FindWSWinLibs _WS_LIB_SEARCH_PATH _LIB_HINT_VAR ) + if(USE_REPOSITORY) + if( ARGN ) + set( _PROJECT_LIB_DIR ${ARGN} ) + else() + if( DEFINED ENV{WIRESHARK_LIB_DIR} ) + # The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR. + file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR ) + else() + file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR ) + set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs-4.2" ) + endif() + endif() + + file( GLOB _SUBDIR "${_PROJECT_LIB_DIR}/*" ) + # We might be able to use $ENV{VSCMD_ARG_TGT_ARCH} here. + + foreach( _DIR ${_SUBDIR} ) + if( IS_DIRECTORY ${_DIR} ) + if( "${_DIR}" MATCHES ".*/${_WS_LIB_SEARCH_PATH}" ) + set(_vcpkg_dir "${_DIR}/installed/${WIRESHARK_TARGET_PLATFORM}-windows") + if( IS_DIRECTORY "${_vcpkg_dir}") + set( ${_LIB_HINT_VAR} ${_vcpkg_dir} PARENT_SCOPE ) + else() + set( ${_LIB_HINT_VAR} ${_DIR} PARENT_SCOPE ) + endif() + endif() + endif() + endforeach() + endif() +endfunction() + +# Add a single DLL +function(AddWSWinDLL _PKG_NAME _PKG_HINTS _DLL_GLOB) + if(USE_REPOSITORY AND ${_PKG_NAME}_FOUND) + string(TOUPPER ${_PKG_NAME} _PKG_VAR) + set ( ${_PKG_VAR}_DLL_DIR "${${_PKG_HINTS}}/bin" + CACHE PATH "Path to ${_PKG_NAME} DLL" + ) + file( GLOB _pkg_dll RELATIVE "${${_PKG_VAR}_DLL_DIR}" + "${${_PKG_VAR}_DLL_DIR}/${_DLL_GLOB}.dll" + ) + set ( ${_PKG_VAR}_DLL ${_pkg_dll} + CACHE STRING "${_PKG_NAME} DLL file name" + ) + file( GLOB _pkg_pdb RELATIVE "${${_PKG_VAR}_DLL_DIR}" + "${${_PKG_VAR}_DLL_DIR}/${_DLL_GLOB}.pdb" + ) + set ( ${_PKG_VAR}_PDB ${_pkg_pdb} + CACHE STRING "${_PKG_NAME} PDB file name" + ) + mark_as_advanced( ${_PKG_VAR}_DLL_DIR ${_PKG_VAR}_DLL ${_PKG_VAR}_PDB ) + else() + set( ${_PKG_VAR}_DLL_DIR ) + set( ${_PKG_VAR}_DLL ) + endif() +endfunction() + +# Add a list of DLLs +function(AddWSWinDLLS _PKG_NAME _PKG_HINTS) # ...DLL globs + if(USE_REPOSITORY AND ${_PKG_NAME}_FOUND) + string(TOUPPER ${_PKG_NAME} _PKG_VAR) + set ( ${_PKG_VAR}_DLL_DIR "${${_PKG_HINTS}}/bin" + CACHE PATH "Path to ${_PKG_NAME} DLLs" + ) + + set (_pkg_dlls) + set (_pkg_pdbs) + foreach(_dll_glob ${ARGN}) + file( GLOB _pkg_dll RELATIVE "${${_PKG_VAR}_DLL_DIR}" + "${${_PKG_VAR}_DLL_DIR}/${_dll_glob}.dll" + ) + list(APPEND _pkg_dlls "${_pkg_dll}") + file( GLOB _pkg_pdb RELATIVE "${${_PKG_VAR}_DLL_DIR}" + "${${_PKG_VAR}_DLL_DIR}/${_dll_glob}.pdb" + ) + list(APPEND _pkg_pdbs "${_pkg_pdb}") + endforeach() + + set ( ${_PKG_VAR}_DLLS ${_pkg_dlls} + CACHE FILEPATH "${_PKG_NAME} DLL list" + ) + set ( ${_PKG_VAR}_PDBS ${_pkg_pdbs} + CACHE FILEPATH "${_PKG_NAME} PDB list" + ) + + mark_as_advanced( ${_PKG_VAR}_DLL_DIR ${_PKG_VAR}_DLLS ${_PKG_VAR}_PDBS ) + else() + set( ${_PKG_VAR}_DLL_DIR ) + set( ${_PKG_VAR}_DLLS ) + set( ${_PKG_VAR}_PDBS ) + endif() +endfunction() diff --git a/cmake/modules/FindWiX.cmake b/cmake/modules/FindWiX.cmake new file mode 100644 index 0000000..ad8e576 --- /dev/null +++ b/cmake/modules/FindWiX.cmake @@ -0,0 +1,44 @@ +# +# - Find Wix executables +# Find the candle and light command +# +# MAKEWIX_EXECUTABLE - path to the candle utility. +# CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS - System runtime DLLs + +set(_PF86 "PROGRAMFILES(x86)") + +# According to +# https://stackoverflow.com/questions/2375322/variable-for-wix-bin-directory-path +# and +# https://weblogs.sqlteam.com/mladenp/2010/02/23/wix-3-tutorial-generating-filedirectory-fragments-with-heat.exe/ +# WiX binaries are in $ENV{WIX}/bin. + +# Find candle +find_program(WIX_CANDLE_EXECUTABLE candle + PATH + "$ENV{WIX}/bin" + "$ENV{PROGRAMFILES}/WiX Toolset v3.11/bin" + "$ENV{${_PF86}}/WiX Toolset v3.11/bin" + "$ENV{PROGRAMW6432}/WiX Toolset v3.11/bin" + DOC "Path to the WiX candle utility." +) + +# Find light +find_program(WIX_LIGHT_EXECUTABLE light + PATH + "$ENV{WIX}/bin" + "$ENV{PROGRAMFILES}/WiX Toolset v3.11/bin" + "$ENV{${_PF86}}/WiX Toolset v3.11/bin" + "$ENV{PROGRAMW6432}/WiX Toolset v3.11/bin" + DOC "Path to the WiX light utility." +) + +# Find heat +find_program(WIX_HEAT_EXECUTABLE heat + PATH + "$ENV{WIX}/bin" + "$ENV{PROGRAMFILES}/WiX Toolset v3.11/bin" + "$ENV{${_PF86}}/WiX Toolset v3.11/bin" + "$ENV{PROGRAMW6432}/WiX Toolset v3.11/bin" + DOC "Path to the WiX heat utility." +) diff --git a/cmake/modules/FindWinSparkle.cmake b/cmake/modules/FindWinSparkle.cmake new file mode 100644 index 0000000..7418cfb --- /dev/null +++ b/cmake/modules/FindWinSparkle.cmake @@ -0,0 +1,56 @@ +# +# - Find WinSparkle +# Find the native WinSparkle includes and library +# +# WINSPARKLE_INCLUDE_DIRS - where to find WinSparkle.h, etc. +# WINSPARKLE_LIBRARIES - List of libraries when using WinSparkle. +# WINSPARKLE_FOUND - True if WinSparkle found. +# WINSPARKLE_DLL_DIR - (Windows) Path to the WinSparkle DLL. +# WINSPARKLE_DLL - (Windows) Name of the WinSparkle DLL. + + +IF (WINSPARKLE_INCLUDE_DIRS) + # Already in cache, be silent + SET(WINSPARKLE_FIND_QUIETLY TRUE) +ENDIF (WINSPARKLE_INCLUDE_DIRS) + +INCLUDE(FindWSWinLibs) +FindWSWinLibs("WinSparkle.*" "WINSPARKLE_HINTS") + +set (_release_subdir "${WIRESHARK_TARGET_PLATFORM}/Release") + +FIND_PATH(WINSPARKLE_INCLUDE_DIR winsparkle.h HINTS "${WINSPARKLE_HINTS}/include" ) + +FIND_LIBRARY(WINSPARKLE_LIBRARY NAMES WinSparkle HINTS "${WINSPARKLE_HINTS}/${_release_subdir}" ) + +# handle the QUIETLY and REQUIRED arguments and set WINSPARKLE_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(WinSparkle DEFAULT_MSG WINSPARKLE_LIBRARY WINSPARKLE_INCLUDE_DIR) + +IF(WINSPARKLE_FOUND) + SET(WINSPARKLE_LIBRARIES ${WINSPARKLE_LIBRARY} ) + SET(WINSPARKLE_INCLUDE_DIRS ${WINSPARKLE_INCLUDE_DIR} ) + if (WIN32) + set (WINSPARKLE_DLL_DIR "${WINSPARKLE_HINTS}/${_release_subdir}" + CACHE PATH "Path to the WinSparkle DLL" + ) + file( GLOB _winsparkle_dll RELATIVE "${WINSPARKLE_DLL_DIR}" + "${WINSPARKLE_DLL_DIR}/WinSparkle.dll" + ) + set ( WINSPARKLE_DLL ${_winsparkle_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "WinSparkle DLL file name" + ) + mark_as_advanced( WINSPARKLE_DLL_DIR WINSPARKLE_DLL ) + endif() +ELSE(WINSPARKLE_FOUND) + SET(WINSPARKLE_LIBRARIES ) + SET(WINSPARKLE_INCLUDE_DIRS ) + SET(WINSPARKLE_DLL_DIR ) + SET(WINSPARKLE_DLL ) +ENDIF(WINSPARKLE_FOUND) + +unset(_release_subdir) + +MARK_AS_ADVANCED( WINSPARKLE_LIBRARIES WINSPARKLE_INCLUDE_DIRS ) diff --git a/cmake/modules/FindXSLTPROC.cmake b/cmake/modules/FindXSLTPROC.cmake new file mode 100644 index 0000000..b554622 --- /dev/null +++ b/cmake/modules/FindXSLTPROC.cmake @@ -0,0 +1,152 @@ +# +# - Find XSLTPROC +# This module looks for some usual Unix commands. +# + +include(FindChocolatey) + +# Strawberry Perl ships with xsltproc but no DocBook XML files, which +# is detrimental to our interests. Search for the Chocolatey +# versions first, and un-find xsltproc if needed. +find_program(XSLTPROC_EXECUTABLE + NAMES + xsltproc + HINTS + ${CHOCOLATEY_BIN_PATH} + PATHS + /usr/local/bin + /sbin +) + +string(TOLOWER ${XSLTPROC_EXECUTABLE} _xe_lower) +if(${_xe_lower} MATCHES "strawberry") + set(_ignore_reason "Strawberry xsltproc found at ${XSLTPROC_EXECUTABLE}. Ignoring.") + message(STATUS ${_ignore_reason}) + set(XSLTPROC_EXECUTABLE XSLTPROC_EXECUTABLE-NOTFOUND CACHE FILEPATH ${_ignore_reason} FORCE) +endif() + +# Handle the QUIETLY and REQUIRED arguments and set XSLTPROC_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(XSLTPROC DEFAULT_MSG XSLTPROC_EXECUTABLE) + +MARK_AS_ADVANCED(XSLTPROC_EXECUTABLE) + +set (_common_xsltproc_args + --stringparam use.id.as.filename 1 + --stringparam admon.graphics 1 + --stringparam admon.graphics.extension .svg + --stringparam section.autolabel 1 + --stringparam section.label.includes.component.label 1 + --stringparam html.stylesheet ws.css + ) + +set(_xsltproc_path "${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_BINARY_DIR}/wsluarm_src") + +# Workaround for parallel build issue with msbuild. +# https://gitlab.kitware.com/cmake/cmake/issues/16767 +if(CMAKE_GENERATOR MATCHES "Visual Studio") + # msbuild (as used by the Visual Studio generators) must not depend on the XML + # file (otherwise the XML file will be generated multiple times, possibly in + # parallel, breaking the build). Workaround: add one dependency to generate + # the XML file when outdated, depend on the -stamp file to ensure that the + # target is rebuilt when the XML file is regenerated. + function(get_docbook_xml_depends varname _dbk_source) + set(${varname} + "generate_${_dbk_source}" + "${CMAKE_CURRENT_BINARY_DIR}/${_dbk_source}-stamp" + PARENT_SCOPE + ) + endfunction() +else() + # Unix Makefiles, Ninja, etc: first dependency enforces that the XML file is + # rebuilt when outdated, the second dependency ensures that the target is + # rebuilt when the XML file has changed. + function(get_docbook_xml_depends varname _dbk_source) + set(${varname} + "generate_${_dbk_source}" + "${_dbk_source}" + PARENT_SCOPE + ) + endfunction() +endif() + +# Translate XML to HTML +#XML2HTML( +# wsug or wsdg +# single-page or chunked +# WSUG_FILES +# WSUG_GRAPHICS +#) +MACRO(XML2HTML _target_dep _dir_pfx _mode _dbk_source _gfx_sources) + # We depend on the docbook target to avoid parallel builds. + SET(_dbk_dep ${_target_dep}_docbook) + + # We can pass chunker.xxx parameters to customize the chunked output. + # We have to use a custom layer to customize the single-page output. + # Set the output encoding for both to UTF-8. Indent the single-page + # output because we sometimes need to copy and paste the release + # note contents. + IF(${_mode} STREQUAL "chunked") + SET(_basedir ${_dir_pfx}_html_chunked) + SET(_stylesheet "http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl") + SET(_modeparams --stringparam chunker.output.encoding UTF-8 --stringparam chunk.quietly 1) + ELSE() # single-page + SET(_basedir ${_dir_pfx}_html) + SET(_stylesheet ${CMAKE_SOURCE_DIR}/docbook/custom_layer_single_html.xsl) + SET(_modeparams --output ${_basedir}/index.html) + ENDIF() + + SET(_out_dir ${CMAKE_CURRENT_BINARY_DIR}/${_basedir}) + SET(_output ${_basedir}/index.html) + get_docbook_xml_depends(_dbk_xml_deps "${_dbk_source}") + + FOREACH(_tmpgfx ${${_gfx_sources}}) + set(_gfx_deps ${CMAKE_CURRENT_SOURCE_DIR}/${_tmpgfx}) + ENDFOREACH() + + SET(_gfx_src_dir ${_dir_pfx}_src/images) + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output} + COMMAND ${CMAKE_COMMAND} + -E make_directory ${_out_dir} + COMMAND ${CMAKE_COMMAND} + -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/${_gfx_src_dir} ${_out_dir}/images + COMMAND ${CMAKE_COMMAND} + -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ws.css ${_out_dir} + COMMAND ${XSLTPROC_EXECUTABLE} + --path "${_xsltproc_path}" + --stringparam base.dir ${_basedir}/ + ${_common_xsltproc_args} + --stringparam admon.graphics.path images/ + ${_modeparams} + --noout ${_stylesheet} + ${_dbk_source} + DEPENDS + ${_dbk_xml_deps} + ${_dbk_dep} + ${_gfx_deps} + custom_layer_single_html.xsl + ) + if(${_dir_pfx} STREQUAL wsug) + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output} + COMMAND ${CMAKE_COMMAND} + -E make_directory ${_out_dir}/images/toolbar + COMMAND ${CMAKE_COMMAND} + -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/${_gfx_src_dir}/toolbar ${_out_dir}/images/toolbar + APPEND + ) + endif() + IF(NOT WIN32) + ADD_CUSTOM_COMMAND( + OUTPUT + ${_output} + COMMAND chmod + -R og+rX ${_out_dir} + APPEND + ) + ENDIF() +ENDMACRO(XML2HTML) diff --git a/cmake/modules/FindZLIB.cmake b/cmake/modules/FindZLIB.cmake new file mode 100644 index 0000000..b6ac985 --- /dev/null +++ b/cmake/modules/FindZLIB.cmake @@ -0,0 +1,150 @@ +# - Find zlib +# +# Find the native ZLIB includes and library. +# Once done this will define +# +# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. +# ZLIB_LIBRARIES - List of libraries when using zlib. +# ZLIB_FOUND - True if zlib found. +# ZLIB_DLL_DIR - (Windows) Path to the zlib DLL. +# ZLIB_DLL - (Windows) Name of the zlib DLL. +# ZLIB_PDB - (Windows) Name of the zlib PDB. +# +# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) +# ZLIB_VERSION_MAJOR - The major version of zlib +# ZLIB_VERSION_MINOR - The minor version of zlib +# ZLIB_VERSION_PATCH - The patch version of zlib +# ZLIB_VERSION_TWEAK - The tweak version of zlib +# +# The following variable are provided for backward compatibility +# +# ZLIB_MAJOR_VERSION - The major version of zlib +# ZLIB_MINOR_VERSION - The minor version of zlib +# ZLIB_PATCH_VERSION - The patch version of zlib + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +include( FindWSWinLibs ) +# Zlib is included with GLib2 +FindWSWinLibs( "vcpkg-export-*" "ZLIB_HINTS" ) + +if(MSVC) + # else we'll find Strawberry Perl's version + set (_zlib_sys_env_option NO_SYSTEM_ENVIRONMENT_PATH) +endif() + +if (NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) + if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig + find_package(PkgConfig) + pkg_search_module(ZLIB zlib) + endif() + + FIND_PATH(ZLIB_INCLUDE_DIR + NAMES + zlib.h + HINTS + "${ZLIB_INCLUDEDIR}" + ${ZLIB_HINTS}/include + ${ZLIB_HINTS} + PATHS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include" + ${_zlib_sys_env_option} + ) + + SET(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) + FIND_LIBRARY(ZLIB_LIBRARY + NAMES + ${ZLIB_NAMES} + HINTS + "${ZLIB_LIBDIR}" + ${ZLIB_HINTS}/lib + ${ZLIB_HINTS} + PATHS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/lib" + ${_zlib_sys_env_option} + ) +endif() +unset(_zlib_sys_env_option) +MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) + +# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR + VERSION_VAR ZLIB_VERSION_STRING) + +if(ZLIB_FOUND) + IF(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") + FILE(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") + + STRING(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") + STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") + STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") + SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") + + # only append a TWEAK version if it exists: + SET(ZLIB_VERSION_TWEAK "") + IF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") + SET(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") + SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") + ENDIF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") + + SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") + SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") + SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") + ENDIF() + + # + # inflatePrime was added in zlib 1.2.2.4 in 2005. We're guaranteed + # to have it on Windows. + # + IF(WIN32) + SET(HAVE_INFLATEPRIME ON) + ELSE() + INCLUDE(CMakePushCheckState) + INCLUDE(CheckFunctionExists) + CMAKE_PUSH_CHECK_STATE() + set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY}) + # + # Check for inflate() in zlib, to make sure the zlib library is + # usable. + # + # For example, on at least some versions of Fedora, if you have a + # 64-bit machine, have both the 32-bit and 64-bit versions of the + # run-time zlib package installed, and have only the *32-bit* + # version of the zlib development package installed, it'll find the + # header, and think it can use zlib, and will use it in subsequent + # tests, but it'll try and link 64-bit test programs with the 32-bit + # library, causing those tests to falsely fail. Hilarity ensues. + # + CHECK_FUNCTION_EXISTS("inflate" HAVE_INFLATE) + IF(NOT HAVE_INFLATE) + MESSAGE(FATAL_ERROR "zlib.h found but linking with -lz failed to find inflate(); do you have the right developer package installed (32-bit vs. 64-bit)?") + ENDIF() + CHECK_FUNCTION_EXISTS("inflatePrime" HAVE_INFLATEPRIME) + # reset + CMAKE_POP_CHECK_STATE() + ENDIF() + + AddWSWinDLL(ZLIB ZLIB_HINTS "zlib*") + SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) +ELSE() + SET(ZLIB_INCLUDE_DIRS ) + SET(ZLIB_LIBRARIES ) + SET(ZLIB_DLL_DIR ) + SET(ZLIB_DLL ) + SET(ZLIB_PDB ) +ENDIF() diff --git a/cmake/modules/FindZSTD.cmake b/cmake/modules/FindZSTD.cmake new file mode 100644 index 0000000..5107d6a --- /dev/null +++ b/cmake/modules/FindZSTD.cmake @@ -0,0 +1,73 @@ +# +# - Find zstd +# Find Zstd includes and library +# +# ZSTD_INCLUDE_DIRS - where to find zstd.h, etc. +# ZSTD_LIBRARIES - List of libraries when using Zstd. +# ZSTD_FOUND - True if Zstd found. +# ZSTD_DLL_DIR - (Windows) Path to the Zstd DLL +# ZSTD_DLL - (Windows) Name of the Zstd DLL + +include( FindWSWinLibs ) +FindWSWinLibs( "zstd-.*" "ZSTD_HINTS" ) + +if( NOT USE_REPOSITORY) + find_package(PkgConfig) + pkg_search_module(ZSTD libzstd) +endif() + +find_path(ZSTD_INCLUDE_DIR + NAMES zstd.h + HINTS "${ZSTD_INCLUDEDIR}" "${ZSTD_HINTS}/include" + /usr/include + /usr/local/include +) + +find_library(ZSTD_LIBRARY + NAMES zstd + HINTS "${ZSTD_LIBDIR}" "${ZSTD_HINTS}/lib" + PATHS + /usr/lib + /usr/local/lib +) + +if( ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY ) + file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MAJOR + REGEX "#define[ ]+ZSTD_VERSION_MAJOR[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" ZSTD_VERSION_MAJOR ${ZSTD_VERSION_MAJOR}) + file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MINOR + REGEX "#define[ ]+ZSTD_VERSION_MINOR[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" ZSTD_VERSION_MINOR ${ZSTD_VERSION_MINOR}) + file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_RELEASE + REGEX "#define[ ]+ZSTD_VERSION_RELEASE[ ]+[0-9]+") + string(REGEX MATCH "[0-9]+" ZSTD_VERSION_RELEASE ${ZSTD_VERSION_RELEASE}) + set(ZSTD_VERSION ${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_RELEASE}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ZSTD + REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR + VERSION_VAR ZSTD_VERSION) + +if( ZSTD_FOUND ) + set( ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR} ) + set( ZSTD_LIBRARIES ${ZSTD_LIBRARY} ) + if (WIN32) + set ( ZSTD_DLL_DIR "${ZSTD_HINTS}/bin" + CACHE PATH "Path to Zstd DLL" + ) + file( GLOB _zstd_dll RELATIVE "${ZSTD_DLL_DIR}" + "${ZSTD_DLL_DIR}/zstd*.dll" + ) + set ( ZSTD_DLL ${_zstd_dll} + # We're storing filenames only. Should we use STRING instead? + CACHE FILEPATH "Zstd DLL file name" + ) + mark_as_advanced( ZSTD_DLL_DIR ZSTD_DLL ) + endif() +else() + set( ZSTD_INCLUDE_DIRS ) + set( ZSTD_LIBRARIES ) +endif() + +mark_as_advanced( ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS ) diff --git a/cmake/modules/LICENSE.txt b/cmake/modules/LICENSE.txt new file mode 100644 index 0000000..1aa0f76 --- /dev/null +++ b/cmake/modules/LICENSE.txt @@ -0,0 +1,57 @@ +All files in this directory are dual licensed by the licenses +included below, unless the individual license of a file says +otherwise. + +################################################################### +# +# Copyright (c) .... +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +################################################################### +# +# Copyright (c) ... +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# * Neither the name of the nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# diff --git a/cmake/modules/UseAsn2Wrs.cmake b/cmake/modules/UseAsn2Wrs.cmake new file mode 100644 index 0000000..271126c --- /dev/null +++ b/cmake/modules/UseAsn2Wrs.cmake @@ -0,0 +1,89 @@ +# - Convert ASN.1 file into C source and header files that can be used to create a wireshark dissector +# +# A2W_OUTPUT_DIR - directory where the generated packet-${PROTOCOL_NAME}.c is +# saved. The default location is meant for the Wireshark +# source tree. For external dissectors, set it to the +# absolute path (e.g. "${CMAKE_CURRENT_SOURCE_DIR}"). + +function(ASN2WRS) + if(NOT PROTO_OPT) + set(PROTO_OPT -p ${PROTOCOL_NAME}) + elseif(PROTO_OPT STREQUAL "_EMPTY_") + set(PROTO_OPT) + endif() + + if(NOT A2W_OUTPUT_DIR) + set(A2W_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/epan/dissectors") + endif() + + set(DISSECTOR "${A2W_OUTPUT_DIR}/packet-${PROTOCOL_NAME}.c") + + # Besides the file dependency (for timestamp comparison), add a target such + # that other directories can request it to be built (ordering dependency). + foreach(_v EXTRA_CNF EXPORT_DEPENDS) + set(${_v}_targets) + foreach(entry IN LISTS ${_v}) + string(REGEX MATCH "[^/]+-exp\\.cnf$" _exp_cnf_filename "${entry}") + if(_exp_cnf_filename) + list(APPEND ${_v}_targets generate-${_exp_cnf_filename}) + endif() + endforeach() + endforeach() + + if(NOT ENABLE_DEBUG_A2W) + set(A2W_FLAGS ${A2W_FLAGS} -L) + endif() + + # Creates a dissector in the source directory and store the timestamp. + add_custom_command( + OUTPUT packet-${PROTOCOL_NAME}-stamp + COMMAND "${Python3_EXECUTABLE}" + ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py + ${A2W_FLAGS} + ${PROTO_OPT} + -c "${CMAKE_CURRENT_SOURCE_DIR}/${PROTOCOL_NAME}.cnf" + -s "${CMAKE_CURRENT_SOURCE_DIR}/packet-${PROTOCOL_NAME}-template" + -D "${CMAKE_CURRENT_SOURCE_DIR}" + -O "${A2W_OUTPUT_DIR}" + ${EXT_ASN_FILE_LIST} ${ASN_FILE_LIST} ${EXT_ASN_FILE_LIST_LATE} + COMMAND + "${Python3_EXECUTABLE}" -c + "import shutil, sys; x,s,d=sys.argv; open(d, 'w'); shutil.copystat(s, d)" + "${A2W_OUTPUT_DIR}/packet-${PROTOCOL_NAME}.c" + packet-${PROTOCOL_NAME}-stamp + DEPENDS + ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py + ${SRC_FILES} + ${EXTRA_CNF_targets} + ${EXTRA_CNF} + VERBATIM + ) + + add_custom_target(generate_dissector-${PROTOCOL_NAME} ALL + DEPENDS packet-${PROTOCOL_NAME}-stamp + ) + + foreach(_asn2wrs_export_file IN LISTS EXPORT_FILES) + add_custom_command( + OUTPUT ${_asn2wrs_export_file} + COMMAND "${Python3_EXECUTABLE}" + ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py + -E + ${A2W_FLAGS} + ${PROTO_OPT} + -c "${CMAKE_CURRENT_SOURCE_DIR}/${PROTOCOL_NAME}.cnf" + -D "${CMAKE_CURRENT_SOURCE_DIR}" + ${EXT_ASN_FILE_LIST} ${ASN_FILE_LIST} ${EXT_ASN_FILE_LIST_LATE} + DEPENDS + ${CMAKE_SOURCE_DIR}/tools/asn2wrs.py + ${SRC_FILES} + ${EXPORT_DEPENDS_targets} + ${EXPORT_DEPENDS} + ) + # This target enables other dissectors to trigger the -exp cnf build + add_custom_target(generate-${_asn2wrs_export_file} + DEPENDS ${_asn2wrs_export_file} + ) + endforeach() + +endfunction() diff --git a/cmake/modules/UseCheckAPI.cmake b/cmake/modules/UseCheckAPI.cmake new file mode 100644 index 0000000..1518fb4 --- /dev/null +++ b/cmake/modules/UseCheckAPI.cmake @@ -0,0 +1,41 @@ +# Add a target to call checkAPIs.pl on the specified source files +# The target is excluded from the ALL targte so must be manually +# specified in a build command. +# The target is added to the top-level checkAPIs target +# +# Parameters: +# NAME: The name of the target, must be unique +# SWITCHES: Switches to be supplied to the script +# SOURCES: The sources to be checked + +include(CMakeParseArguments) + +macro( CHECKAPI ) + cmake_parse_arguments(CHECKAPI "DEBUG" "" "NAME;SWITCHES;SOURCES" ${ARGN} ) + + if (CHECKAPI_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "CHECKAPIS Unknown argument: ${CHECKAPI_UNPARSED_ARGUMENTS}") + endif() + + if( CHECKAPI_DEBUG ) + set (CHECKAPI_SWITCHES ${CHECKAPI_SWITCHES --debug) + endif() + + set(TARGET_NAME checkAPI_${CHECKAPI_NAME}) + add_custom_target(${TARGET_NAME} + COMMAND ${PERL_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/tools/checkAPIs.pl + ${CHECKAPI_SWITCHES} + ${CHECKAPI_SOURCES} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT + "Running ${TARGET_NAME}" + ) + add_dependencies(checkAPI ${TARGET_NAME}) + set_target_properties(${TARGET_NAME} + PROPERTIES FOLDER "Auxiliary/CheckAPIs" + EXCLUDE_FROM_ALL True + EXCLUDE_FROM_DEFAULT_BUILD True + ) +ENDMACRO() diff --git a/cmake/modules/UseCustomIncludes.cmake b/cmake/modules/UseCustomIncludes.cmake new file mode 100644 index 0000000..be01303 --- /dev/null +++ b/cmake/modules/UseCustomIncludes.cmake @@ -0,0 +1,18 @@ +# +# - Include a custom CMake file relative to the current source directory. +# - If no filename is provided, CMakeListsCustom.txt is used. +# +macro( ADD_CUSTOM_CMAKE_INCLUDE ) + if( ${ARGN} ) + set( _file_list ${ARGN} ) + else() + set( _file_list CMakeListsCustom.txt ) + endif() + foreach (_include ${_file_list}) + set( _include_file ${CMAKE_CURRENT_SOURCE_DIR}/${_include} ) + if( EXISTS ${_include_file} ) + message ( STATUS "Custom file found, including: ${_include_file}" ) + include( ${_include_file} ) + endif() + endforeach() +endmacro() diff --git a/cmake/modules/UseExecutableResources.cmake b/cmake/modules/UseExecutableResources.cmake new file mode 100644 index 0000000..8eeb4a7 --- /dev/null +++ b/cmake/modules/UseExecutableResources.cmake @@ -0,0 +1,26 @@ +# Sets RC information on Windows. +# UNIQUE_RC - Use if the program has its own .rc.in file. Otherwise cli_template.rc.in will be used. +# EXE_NAME - The lowercase executable base name. +# PROGRAM_NAME - The program's proper, capitalized name. +# COPYRIGHT_INFO - Year followed by copyright holder names if different from default. +function(set_executable_resources EXE_NAME PROGRAM_NAME) + if (WIN32) + set(options UNIQUE_RC) + set(one_value_args COPYRIGHT_INFO) + cmake_parse_arguments(EXE_RC "${options}" "${one_value_args}" "" ${ARGN} ) + if (EXE_RC_COPYRIGHT_INFO) + set(COPYRIGHT_INFO "${EXE_RC_COPYRIGHT_INFO}") + else() + # Use the original Wireshark / TShark .rc copyright. + set(COPYRIGHT_INFO "2000 Gerald Combs , Gilbert Ramirez and many others") + endif() + set(${EXE_NAME}_FILES ${${EXE_NAME}_FILES} ${CMAKE_BINARY_DIR}/resources/${EXE_NAME}.rc PARENT_SCOPE) + if (EXE_RC_UNIQUE_RC) + set (_in_file ${EXE_NAME}) + else() + set (_in_file "cli_template") + endif() + set(ICON_PATH "${CMAKE_SOURCE_DIR}/resources/icons/") + configure_file( ${CMAKE_SOURCE_DIR}/resources/${_in_file}.rc.in ${CMAKE_BINARY_DIR}/resources/${EXE_NAME}.rc @ONLY ) + endif() +endfunction() diff --git a/cmake/modules/UseLemon.cmake b/cmake/modules/UseLemon.cmake new file mode 100644 index 0000000..e419de1 --- /dev/null +++ b/cmake/modules/UseLemon.cmake @@ -0,0 +1,65 @@ +# + +find_program(LEMON_EXECUTABLE lemon) + +if(LEMON_EXECUTABLE) + # Use system lemon + macro(generate_lemon_file _out _in) + add_custom_command( + OUTPUT + ${_out}.c + # These files are generated as side-effect + ${_out}.h + ${_out}.out + COMMAND ${LEMON_EXECUTABLE} + -T/usr/share/lemon/lempar.c + -d. + ${_in} + DEPENDS + ${_in} + ) + endmacro() + add_custom_target(lemon) +else() + # Compile bundled lemon + macro(generate_lemon_file _out _in) + add_custom_command( + OUTPUT + ${_out}.c + # These files are generated as side-effect + ${_out}.h + ${_out}.out + COMMAND $ + -T${CMAKE_SOURCE_DIR}/tools/lemon/lempar.c + -d. + ${_in} + DEPENDS + ${_in} + lemon + ${CMAKE_SOURCE_DIR}/tools/lemon/lempar.c + ) + endmacro() +endif() + +macro(ADD_LEMON_FILES _source _generated) + + foreach (_current_FILE ${ARGN}) + get_filename_component(_in ${_current_FILE} ABSOLUTE) + get_filename_component(_basename ${_current_FILE} NAME_WE) + + set(_out ${CMAKE_CURRENT_BINARY_DIR}/${_basename}) + + generate_lemon_file(${_out} ${_in}) + + list(APPEND ${_source} ${_in}) + list(APPEND ${_generated} ${_out}.c) + + if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + set_source_files_properties(${_out}.c PROPERTIES COMPILE_OPTIONS "/w") + elseif(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + set_source_files_properties(${_out}.c PROPERTIES COMPILE_OPTIONS "-Wno-unused-parameter") + else() + # Build with some warnings for lemon generated code + endif() + endforeach(_current_FILE) +endmacro(ADD_LEMON_FILES) diff --git a/cmake/modules/UseMakePluginReg.cmake b/cmake/modules/UseMakePluginReg.cmake new file mode 100644 index 0000000..0c7198d --- /dev/null +++ b/cmake/modules/UseMakePluginReg.cmake @@ -0,0 +1,17 @@ +# +function(register_plugin_files _outputfile _registertype) + file(RELATIVE_PATH output "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${_outputfile}") + add_custom_command( + OUTPUT + ${_outputfile} + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/tools/make-plugin-reg.py + ${CMAKE_CURRENT_SOURCE_DIR} + ${_registertype} + ${ARGN} + COMMENT "Generating ${output}" + DEPENDS + ${ARGN} + ${CMAKE_SOURCE_DIR}/tools/make-plugin-reg.py + ) +endfunction() diff --git a/cmake/modules/UseMakeTaps.cmake b/cmake/modules/UseMakeTaps.cmake new file mode 100644 index 0000000..56fd628 --- /dev/null +++ b/cmake/modules/UseMakeTaps.cmake @@ -0,0 +1,15 @@ +# +MACRO(REGISTER_TAP_FILES _outputfile) + set(_sources ${ARGN}) + ADD_CUSTOM_COMMAND( + OUTPUT + ${_outputfile} + COMMAND + ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/make-regs.py taps ${_outputfile} ${_sources} + DEPENDS + ${CMAKE_SOURCE_DIR}/tools/make-regs.py + ${_sources} + COMMENT + "Making ${_outputfile}" +) +ENDMACRO(REGISTER_TAP_FILES) diff --git a/cmake/modules/WiresharkPlugin.cmake b/cmake/modules/WiresharkPlugin.cmake new file mode 100644 index 0000000..76277e2 --- /dev/null +++ b/cmake/modules/WiresharkPlugin.cmake @@ -0,0 +1,75 @@ +# Plugin convenience macros. + +# Set information +macro(SET_MODULE_INFO _plugin _ver_major _ver_minor _ver_micro _ver_extra) + if(WIN32) + # Create the Windows .rc file for the plugin. + set(MODULE_NAME ${_plugin}) + set(MODULE_VERSION_MAJOR ${_ver_major}) + set(MODULE_VERSION_MINOR ${_ver_minor}) + set(MODULE_VERSION_MICRO ${_ver_micro}) + set(MODULE_VERSION_EXTRA ${_ver_extra}) + set(MODULE_VERSION "${MODULE_VERSION_MAJOR}.${MODULE_VERSION_MINOR}.${MODULE_VERSION_MICRO}.${MODULE_VERSION_EXTRA}") + set(RC_MODULE_VERSION "${MODULE_VERSION_MAJOR},${MODULE_VERSION_MINOR},${MODULE_VERSION_MICRO},${MODULE_VERSION_EXTRA}") + + set(MSVC_VARIANT "${CMAKE_GENERATOR}") + + # Create the plugin.rc file from the template + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/plugin.rc.in) + set(_plugin_rc_in ${CMAKE_CURRENT_SOURCE_DIR}/plugin.rc.in) + else() + set(_plugin_rc_in ${CMAKE_SOURCE_DIR}/plugins/plugin.rc.in) + endif() + configure_file(${_plugin_rc_in} plugin.rc @ONLY) + set(PLUGIN_RC_FILE ${CMAKE_CURRENT_BINARY_DIR}/plugin.rc) + endif() + + set(PLUGIN_VERSION "${_ver_major}.${_ver_minor}.${_ver_micro}") + add_definitions(-DPLUGIN_VERSION=\"${PLUGIN_VERSION}\") +endmacro() + +macro(ADD_WIRESHARK_PLUGIN_LIBRARY _plugin _subfolder) + add_library(${_plugin} MODULE + ${PLUGIN_FILES} + ${PLUGIN_RC_FILE} + ) + + target_include_directories(${_plugin} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + + set_target_properties(${_plugin} PROPERTIES + PREFIX "" + LINK_FLAGS "${WS_LINK_FLAGS}" + FOLDER "Plugins" + ) + if(MSVC) + set_target_properties(${_plugin} PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}") + endif() + + set_target_properties(${_plugin} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_DIR}/${_subfolder} + INSTALL_RPATH "" + ) + + add_dependencies(plugins ${_plugin}) +endmacro() + +macro(ADD_PLUGIN_LIBRARY _plugin _subfolder) + message(WARNING "${CMAKE_PARENT_LIST_FILE}: add_plugin_library is deprecated. Use add_wireshark_plugin_library instead.") + ADD_WIRESHARK_PLUGIN_LIBRARY(${_plugin} ${_subfolder}) +endmacro() + +macro(ADD_LOGRAY_PLUGIN_LIBRARY _plugin _subfolder) + ADD_WIRESHARK_PLUGIN_LIBRARY(${_plugin} ${_subfolder}) + + set_target_properties(${_plugin} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${LOGRAY_PLUGIN_DIR}/${_subfolder} + ) +endmacro() + +macro(INSTALL_PLUGIN _plugin _subfolder) + install(TARGETS ${_plugin} + LIBRARY DESTINATION ${PLUGIN_INSTALL_VERSION_LIBDIR}/${_subfolder} NAMELINK_SKIP + RUNTIME DESTINATION ${PLUGIN_INSTALL_VERSION_LIBDIR} + ARCHIVE DESTINATION ${PLUGIN_INSTALL_VERSION_LIBDIR} +) +endmacro() diff --git a/cmake/modules/readme.txt b/cmake/modules/readme.txt new file mode 100644 index 0000000..e0d4568 --- /dev/null +++ b/cmake/modules/readme.txt @@ -0,0 +1,3 @@ +The following modules have been copied from CMake trunk _without_ modifications: + +* FindZLIB.cmake -- cgit v1.2.3