]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1474 in SNORT/snort3 from ~MIALTIZE/snort3:libiconv to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Thu, 20 Dec 2018 19:53:31 +0000 (14:53 -0500)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Thu, 20 Dec 2018 19:53:31 +0000 (14:53 -0500)
Squashed commit of the following:

commit a8eb059f7fff6a3c91c5741dcc40a9404af864cd
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Dec 20 11:53:23 2018 -0500

    build: Add better support for libiconv on systems with iconv-providing libc

cmake/FindICONV.cmake
cmake/sanity_checks.cmake
configure_cmake.sh

index c53d865e844fefe118528024c02426755be37cb4..574dafad63ca9faabe7f1feb3cb9308f23e62710 100644 (file)
-# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-# file Copyright.txt or https://cmake.org/licensing for details.
-
-#[=======================================================================[.rst:
-FindIconv
----------
-
-This module finds the ``iconv()`` POSIX.1 functions on the system.
-These functions might be provided in the regular C library or externally
-in the form of an additional library.
-
-The following variables are provided to indicate iconv support:
-
-.. variable:: ICONV_FOUND
-
-  Variable indicating if the iconv support was found.
-
-.. variable:: Iconv_INCLUDE_DIRS
-
-  The directories containing the iconv headers.
-
-.. variable:: Iconv_LIBRARIES
-
-  The iconv libraries to be linked.
-
-.. variable:: Iconv_IS_BUILT_IN
-
-  A variable indicating whether iconv support is stemming from the
-  C library or not. Even if the C library provides `iconv()`, the presence of
-  an external `libiconv` implementation might lead to this being false.
-
-The following cache variables may also be set:
-
-.. variable:: ICONV_INCLUDE_DIR
-
-  The directory containing the iconv headers.
-
-.. variable:: ICONV_LIBRARY
-
-  The iconv library (if not implicitly given in the C library).
-
-.. note::
-  On POSIX platforms, iconv might be part of the C library and the cache
-  variables ``ICONV_INCLUDE_DIR`` and ``ICONV_LIBRARY`` might be empty.
-
-#]=======================================================================]
-#
-# This file was modified to work in Snort build environment
-#
-
-include(CMakePushCheckState)
-if(CMAKE_C_COMPILER_LOADED)
-  include(CheckCSourceCompiles)
-elseif(CMAKE_CXX_COMPILER_LOADED)
-  include(CheckCXXSourceCompiles)
-else()
-  # If neither C nor CXX are loaded, implicit iconv makes no sense.
-  set(Iconv_IS_BUILT_IN FALSE)
-endif()
-
-# iconv can only be provided in libc on a POSIX system.
-# If any cache variable is already set, we'll skip this test.
-if(NOT DEFINED Iconv_IS_BUILT_IN)
-  if(UNIX AND NOT DEFINED ICONV_INCLUDE_DIR AND NOT DEFINED ICONV_LIBRARY)
-    cmake_push_check_state(RESET)
-    # We always suppress the message here: Otherwise on supported systems
-    # not having iconv in their C library (e.g. those using libiconv)
-    # would always display a confusing "Looking for iconv - not found" message
-    set(CMAKE_FIND_QUIETLY TRUE)
-    # The following code will not work, but it's sufficient to see if it compiles.
-    # Note: libiconv will define the iconv functions as macros, so CheckSymbolExists
-    # will not yield correct results.
-    set(Iconv_IMPLICIT_TEST_CODE
-      "
-      #include <stddef.h>
-      #include <iconv.h>
-      int main() {
-        char *a, *b;
-        size_t i, j;
-        iconv_t ic;
-        ic = iconv_open(\"to\", \"from\");
-        iconv(ic, &a, &i, &b, &j);
-        iconv_close(ic);
-      }
-      "
-    )
-    if(CMAKE_C_COMPILER_LOADED)
-      check_c_source_compiles("${Iconv_IMPLICIT_TEST_CODE}" Iconv_IS_BUILT_IN)
-    else()
-      check_cxx_source_compiles("${Iconv_IMPLICIT_TEST_CODE}" Iconv_IS_BUILT_IN)
+# Find the headers and library required for iconv functions.
+# Libc-based iconv test lifted from the upstream CMake FindIconv.cmake module.
+
+# First, try to find the iconv header, looking in the hinted directory first.
+find_path(ICONV_INCLUDE_DIR
+    NAMES iconv.h
+    HINTS ${ICONV_INCLUDE_DIR_HINT}
+)
+
+if (ICONV_INCLUDE_DIR)
+    # Test to see if iconv is available from libc and matches the header we found.
+    # Assume that an explicit include dir or library dir hint means we're not going
+    # to be using a libc implementation.
+    if (UNIX AND NOT ICONV_INCLUDE_DIR_HINT AND NOT ICONV_LIBRARIES_DIR_HINT)
+        include(CMakePushCheckState)
+        cmake_push_check_state(RESET)
+        # Make sure we're using the iconv.h we found above
+        set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
+        # We always suppress the message here: Otherwise on supported systems
+        # not having iconv in their C library (e.g. those using libiconv)
+        # would always display a confusing "Looking for iconv - not found" message
+        set(CMAKE_FIND_QUIETLY TRUE)
+        # The following code will not work, but it's sufficient to see if it compiles.
+        # Note: libiconv will define the iconv functions as macros, so CheckSymbolExists
+        # will not yield correct results.
+        set(ICONV_IMPLICIT_TEST_CODE
+            "
+            #include <stddef.h>
+            #include <iconv.h>
+            int main() {
+                char *a, *b;
+                size_t i, j;
+                iconv_t ic;
+                ic = iconv_open(\"to\", \"from\");
+                iconv(ic, &a, &i, &b, &j);
+                iconv_close(ic);
+            }
+            "
+        )
+        if (CMAKE_C_COMPILER_LOADED)
+            include(CheckCSourceCompiles)
+            check_c_source_compiles("${ICONV_IMPLICIT_TEST_CODE}" ICONV_IS_BUILT_IN)
+        elseif (CMAKE_CXX_COMPILER_LOADED)
+            include(CheckCXXSourceCompiles)
+            check_cxx_source_compiles("${ICONV_IMPLICIT_TEST_CODE}" ICONV_IS_BUILT_IN)
+        endif()
+        cmake_pop_check_state()
     endif()
-    cmake_pop_check_state()
-  else()
-    set(Iconv_IS_BUILT_IN FALSE)
-  endif()
-endif()
 
-if(NOT Iconv_IS_BUILT_IN)
-  find_path(ICONV_INCLUDE_DIR
-    NAMES "iconv.h"
-    DOC "iconv include directory")
-  set(Iconv_LIBRARY_NAMES "iconv" "libiconv")
+    if (NOT ICONV_IS_BUILT_IN)
+        find_library(ICONV_LIBRARY
+            NAMES iconv libiconv
+            HINTS ${ICONV_LIBRARIES_DIR_HINT}
+        )
+    endif()
 else()
-  set(ICONV_INCLUDE_DIR "" CACHE FILEPATH "iconv include directory")
-  set(Iconv_LIBRARY_NAMES "c")
+    unset(ICONV_INCLUDE_DIR)
 endif()
 
-find_library(ICONV_LIBRARY
-  NAMES ${Iconv_LIBRARY_NAMES}
-  DOC "iconv library (potentially the C library)")
-
-mark_as_advanced(ICONV_INCLUDE_DIR)
-mark_as_advanced(ICONV_LIBRARY)
-
 include(FindPackageHandleStandardArgs)
-if(NOT Iconv_IS_BUILT_IN)
+if (NOT ICONV_IS_BUILT_IN)
   find_package_handle_standard_args(ICONV REQUIRED_VARS ICONV_LIBRARY ICONV_INCLUDE_DIR)
 else()
-  find_package_handle_standard_args(ICONV REQUIRED_VARS ICONV_LIBRARY)
+  find_package_handle_standard_args(ICONV REQUIRED_VARS ICONV_INCLUDE_DIR)
 endif()
 
-if(ICONV_FOUND)
-  set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
-  set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
-endif()
\ No newline at end of file
+mark_as_advanced(ICONV_INCLUDE_DIR)
+mark_as_advanced(ICONV_LIBRARY)
+
index f2b501e6086e8e7de3f635d72de86abe497f6ded..4d9822f70a75fb059267d3326d2b6b2728e7f1b2 100644 (file)
@@ -4,6 +4,7 @@ include(CheckFunctionExists)
 include(CheckLibraryExists)
 include(CheckSymbolExists)
 include(CheckTypeSize)
+include(CMakePushCheckState)
 
 include (TestBigEndian)
 test_big_endian(WORDS_BIGENDIAN)
index a1b64e556f19a83f3c2e0e41bfc9e15a37d00a67..54df54850bdc82ac08a6df0fab313bfaa40cdd0a 100755 (executable)
@@ -105,6 +105,10 @@ Optional Packages:
                             flatbuffers include directory
     --with-flatbuffers-libraries=DIR
                             flatbuffers library directory
+    --with-iconv-includes=DIR
+                            libiconv include directory
+    --with-iconv-libraries=DIR
+                            libiconv library directory
     --with-uuid-includes=DIR
                             libuuid include directory
     --with-uuid-libraries=DIR
@@ -395,6 +399,12 @@ while [ $# -ne 0 ]; do
         --with-flatbuffers-libraries=*)
             append_cache_entry FLATBUFFERS_LIBRARIES_DIR_HINT PATH $optarg
             ;;
+        --with-iconv-includes=*)
+            append_cache_entry ICONV_INCLUDE_DIR_HINT PATH $optarg
+            ;;
+        --with-iconv-libraries=*)
+            append_cache_entry ICONV_LIBRARIES_DIR_HINT PATH $optarg
+            ;;
         --with-uuid-includes=*)
             append_cache_entry UUID_INCLUDE_DIR_HINT PATH $optarg
             ;;