From 8681fc060ea07f646434cd2d324e4a5aa7c495c4 Mon Sep 17 00:00:00 2001 From: myd7349 Date: Sat, 25 Apr 2020 18:43:02 +0800 Subject: [PATCH] build: Add uchardet CLI tool building support for MSVC --- src/tools/CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index fa15eb2..bee2e51 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -3,6 +3,18 @@ set( uchardet.cpp ) +include(CheckSymbolExists) + +check_symbol_exists(getopt_long "getopt.h" HAVE_GETOPT_LONG) + +# On Windows with MSVC, `getopt_long` is not available by default. +# But some third-party libraries can be used. For example, in `vcpkg`, +# we can find a port named `getopt-win32`. +if (NOT HAVE_GETOPT_LONG) + find_path(GETOPT_INCLUDE_DIR NAMES getopt.h) + find_library(GETOPT_LIBRARY NAMES getopt) +endif (NOT HAVE_GETOPT_LONG) + set(UCHARDET_BINARY uchardet) add_executable( @@ -10,6 +22,11 @@ add_executable( ${UCHARDET_SOURCES} ) +if (GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY) + target_include_directories(${UCHARDET_BINARY} PRIVATE ${GETOPT_INCLUDE_DIR}) + target_link_libraries(${UCHARDET_BINARY} PRIVATE ${GETOPT_LIBRARY}) +endif (GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY) + target_link_libraries( ${UCHARDET_BINARY} ${UCHARDET_LIBRARY}