uchardet/src/tools/CMakeLists.txt
Pedro López-Cabanillas d7dad549bd cmake exported targets
The minimum required cmake version is raised to 3.1,
because the exported targets started at that version.

The build system creates the exported targets:
- The executable uchardet::uchardet
- The library uchardet::libuchardet
- The static library uchardet::libuchardet_static

A downstream project using CMake can find and link the library target
directly with cmake (without needing pkg-config) this way:

~~~
project(sample LANGUAGES C)
find_package ( uchardet )
if (uchardet_FOUND)
  add_executable( sample sample.c )
  target_link_libraries ( sample PRIVATE uchardet::libuchardet )
endif ()
~~~

After installing uchardet in a prefix like "$HOME/uchardet/":
cmake -DCMAKE_PREFIX_PATH="$HOME/uchardet/;..."

Instead installing, the build directory can be used directly, for
instance:

cmake -Duchardet_DIR="$HOME/uchardet-0.1.0/build/" ...
2021-11-09 09:52:15 +00:00

43 lines
977 B
CMake

set(
UCHARDET_SOURCES
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(
${UCHARDET_BINARY}
${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}
)
install(
TARGETS
${UCHARDET_BINARY}
EXPORT
UchardetTargets
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
)