CMake: Handier way to find Iconv
authorVitaliy Kirsanov <krokoziabla@yandex-team.ru>
Sat, 21 Dec 2019 09:41:53 +0000 (12:41 +0300)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sun, 22 Dec 2019 11:09:03 +0000 (22:09 +1100)
CMakeLists.txt
src/CMakeLists.txt
src/libFLAC++/CMakeLists.txt
src/libFLAC/CMakeLists.txt
src/plugin_common/CMakeLists.txt
src/share/utf8/CMakeLists.txt

index ad0a665..560bb40 100644 (file)
@@ -22,6 +22,9 @@ if(WITH_OGG)
     find_package(OGG REQUIRED)
 endif()
 
+find_package(Iconv)
+set(HAVE_ICONV ${Iconv_FOUND})
+
 if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wnested-externs -Wshadow -Wundef -Wmissing-declarations -Winline")
     set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops")
index b64c578..1e8a5de 100644 (file)
@@ -1,8 +1,8 @@
+cmake_minimum_required(VERSION 3.11)
+
 option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
 option(WITH_XMMS "Build XMMS plugin" OFF)
 
-check_include_file("iconv.h" HAVE_ICONV)
-
 add_subdirectory("libFLAC")
 if(BUILD_CXXLIBS)
     add_subdirectory("libFLAC++")
index b94b1a3..04b721f 100644 (file)
@@ -26,9 +26,7 @@ target_compile_definitions(FLAC++
     PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLACPP_API_EXPORTS>
     PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
 if(NOT WIN32)
-target_compile_definitions(FLAC++
-    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
-)
+    target_compile_definitions(FLAC++ PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>)
 endif()
 target_include_directories(FLAC++ INTERFACE
     "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
@@ -38,11 +36,9 @@ if(BUILD_SHARED_LIBS)
     set_target_properties(FLAC++ PROPERTIES
         VERSION 6.3.0
         SOVERSION 6)
-if(NOT WIN32)
-    set_target_properties(FLAC++ PROPERTIES
-        CXX_VISIBILITY_PRESET hidden
-    )
-endif()
+    if(NOT WIN32)
+        set_target_properties(FLAC++ PROPERTIES CXX_VISIBILITY_PRESET hidden)
+    endif()
 endif()
 
 install(TARGETS FLAC++ EXPORT targets
index f22cc39..ad9405e 100644 (file)
@@ -97,9 +97,7 @@ target_compile_definitions(FLAC
     PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC_API_EXPORTS>
     PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
 if(NOT WIN32)
-target_compile_definitions(FLAC
-    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
-)
+    target_compile_definitions(FLAC PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>)
 endif()
 target_include_directories(FLAC INTERFACE
     "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
@@ -112,11 +110,9 @@ if(BUILD_SHARED_LIBS)
     set_target_properties(FLAC PROPERTIES
         VERSION 8.3.0
         SOVERSION 8)
-if(NOT WIN32)
-    set_target_properties(FLAC PROPERTIES
-        C_VISIBILITY_PRESET hidden
-    )
-endif()
+    if(NOT WIN32)
+        set_target_properties(FLAC PROPERTIES C_VISIBILITY_PRESET hidden)
+    endif()
 endif()
 
 
index b5c72c9..e5e6d84 100644 (file)
@@ -1,5 +1,8 @@
+cmake_minimum_required(VERSION 3.12)
+
 add_library(plugin_common STATIC
     charset.c
     dither.c
     replaygain.c
     tags.c)
+target_link_libraries(plugin_common PUBLIC $<TARGET_NAME_IF_EXISTS:Iconv::Iconv>)
index 2e2b3c6..389b09e 100644 (file)
@@ -1,9 +1,8 @@
-set(CMAKE_REQUIRED_LIBRARIES iconv)
-check_symbol_exists(iconv "iconv.h" HAVE_ICONV_LIB)
+cmake_minimum_required(VERSION 3.12)
 
 add_library(utf8 STATIC
     charset.c
     iconvert.c
     utf8.c)
 
-target_link_libraries(utf8 PUBLIC grabbag $<$<BOOL:${HAVE_ICONV_LIB}>:iconv>)
+target_link_libraries(utf8 PUBLIC grabbag $<TARGET_NAME_IF_EXISTS:Iconv::Iconv>)