Use of BUILD_SHARED_LIBS added
authorVitaliy Kirsanov <krokoziabla@yandex-team.ru>
Mon, 29 Apr 2019 09:48:24 +0000 (12:48 +0300)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 4 May 2019 01:41:48 +0000 (11:41 +1000)
23 files changed:
CMakeLists.txt
cmake/FindOGG.cmake
cmake/UseSystemExtensions.cmake
config.cmake.h.in
examples/c/decode/file/CMakeLists.txt
examples/c/encode/file/CMakeLists.txt
examples/cpp/decode/file/CMakeLists.txt
examples/cpp/encode/file/CMakeLists.txt
microbench/CMakeLists.txt
src/flac/CMakeLists.txt
src/libFLAC++/CMakeLists.txt
src/libFLAC/CMakeLists.txt
src/metaflac/CMakeLists.txt
src/share/grabbag/CMakeLists.txt
src/test_grabbag/cuesheet/CMakeLists.txt
src/test_grabbag/picture/CMakeLists.txt
src/test_libFLAC++/CMakeLists.txt
src/test_libFLAC/CMakeLists.txt
src/test_libs_common/CMakeLists.txt
src/test_seeking/CMakeLists.txt
src/test_streams/CMakeLists.txt
src/utils/flacdiff/CMakeLists.txt
src/utils/flactimer/CMakeLists.txt

index 886e9f5..6d3666b 100644 (file)
@@ -14,10 +14,7 @@ endif()
 
 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")
-
-    if(CMAKE_BULD_TYPE STREQUAL Release)
-        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -funroll-loops")
-    endif()
+    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops")
 
     option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF)
 endif()
index 4b08040..f984345 100644 (file)
@@ -9,31 +9,18 @@ find_library(OGG_LIBRARY
     NAMES ogg libogg
     HINTS ${_OGG_LIBRARY_DIRS})
 
-find_library(OGG_LIBRARY_STATIC
-    NAMES libogg.a libogg_static
-    HINTS ${_OGG_LIBRARY_DIRS})
-
 mark_as_advanced(
     OGG_INCLUDE_DIR
-    OGG_LIBRARY
-    OGG_LIBRARY_DIRS)
+    OGG_LIBRARY)
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(OGG
     REQUIRED_VARS OGG_INCLUDE_DIR OGG_LIBRARY
     VERSION_VAR _OGG_VERSION)
 
-if(OGG_FOUND)
-    if(NOT Ogg::Ogg)
-        add_library(Ogg::Ogg UNKNOWN IMPORTED)
-        set_target_properties(Ogg::Ogg PROPERTIES
-            INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
-            IMPORTED_LOCATION "${OGG_LIBRARY}")
-    endif()
-    if(NOT Ogg::Ogg-static AND _OGG_LIBRARY_STATIC)
-        add_library(Ogg::Ogg-static STATIC IMPORTED)
-        set_target_properties(Ogg::Ogg-static PROPERTIES
-            INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
-            IMPORTED_LOCATION "${OGG_LIBRARY_STATIC}")
-    endif()
+if(OGG_FOUND AND NOT TARGET Ogg::Ogg)
+    add_library(Ogg::Ogg UNKNOWN IMPORTED)
+    set_target_properties(Ogg::Ogg PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
+        IMPORTED_LOCATION "${OGG_LIBRARY}")
 endif()
index 5ef9b47..f3c9490 100644 (file)
@@ -64,7 +64,6 @@ check_c_source_compiles("
 add_definitions(
     -D_DARWIN_C_SOURCE
     -D_POSIX_PTHREAD_SEMANTICS
-    -D__STDC_WANT_IEC_60559_ATTRIBS_EXT__
     -D__STDC_WANT_IEC_60559_BFP_EXT__
     -D__STDC_WANT_IEC_60559_DFP_EXT__
     -D__STDC_WANT_IEC_60559_FUNCS_EXT__
index b6c1877..1d96f42 100644 (file)
 #endif
 
 
-/* Version number of package */
-#cmakedefine VERSION
-
 /* Target processor is big endian. */
 #define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN
 
 #endif
 
 /* Number of bits in a file offset, on hosts where this is settable. */
-#cmakedefine _FILE_OFFSET_BITS
+#ifndef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 64
+#endif
 
 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
-#cmakedefine _LARGEFILE_SOURCE
+#ifndef _LARGEFILE_SOURCE
+# define _LARGEFILE_SOURCE
+#endif
 
 /* Define for large files, on AIX-style hosts. */
 #cmakedefine _LARGE_FILES
 /* Define to 1 if you need to in order for `stat' and other things to work. */
 #cmakedefine _POSIX_SOURCE
 
-/* Define to `__inline__' or `__inline' if that's what the C compiler
-   calls it, or to nothing if 'inline' is not supported under any name.  */
-#ifndef __cplusplus
-#cmakedefine inline
-#endif
-
 /* Define to __typeof__ if your compiler spells it that way. */
 #cmakedefine typeof
index 60dc18e..53a2991 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(decode_file main.c)
-target_link_libraries(decode_file FLAC-static)
+target_link_libraries(decode_file FLAC)
index c9c8e80..4b7d4c2 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(encode_file main.c)
-target_link_libraries(encode_file FLAC-static)
+target_link_libraries(encode_file FLAC)
index 46ab401..2ce420d 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(decode_file_cxx main.cpp)
-target_link_libraries(decode_file_cxx FLAC++-static)
+target_link_libraries(decode_file_cxx FLAC++)
index cc11721..2617876 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(encode_file_cxx main.cpp)
-target_link_libraries(encode_file_cxx FLAC++-static)
+target_link_libraries(encode_file_cxx FLAC++)
index c43814f..639915b 100644 (file)
@@ -11,7 +11,7 @@ endif()
 
 add_executable(benchmark_residual benchmark_residual.c util.c)
 target_include_directories(benchmark_residual PRIVATE
-    "$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include")
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
 target_link_libraries(benchmark_residual
-    FLAC-static
+    FLAC
     $<$<BOOL:${HAVE_CLOCK_GETTIME}>:rt>)
index c347c9a..9790357 100644 (file)
@@ -11,7 +11,7 @@ add_executable(flac
     utils.c
     vorbiscomment.c)
 target_link_libraries(flac
-    FLAC-static
+    FLAC
     getopt
     replaygain_synthesis
     utf8)
index 35d145c..d6e3dfd 100644 (file)
@@ -18,30 +18,26 @@ check_cxx_source_compiles("
     #endif"
     HAVE_CXX_VARARRAYS)
 
-set(SOURCES
+add_library(FLAC++
     metadata.cpp
     stream_decoder.cpp
     stream_encoder.cpp)
-
-add_library(FLAC++-static STATIC ${SOURCES})
-target_compile_definitions(FLAC++-static PUBLIC FLAC__NO_DLL)
-target_include_directories(FLAC++-static INTERFACE
-    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
-    "$<INSTALL_INTERFACE:include>")
-target_link_libraries(FLAC++-static PUBLIC FLAC-static)
-
-add_library(FLAC++ SHARED ${SOURCES})
-target_compile_definitions(FLAC++ PRIVATE FLACPP_API_EXPORTS FLAC__USE_VISIBILITY_ATTR)
+target_compile_definitions(FLAC++
+    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLACPP_API_EXPORTS>
+    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
+    PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
 target_include_directories(FLAC++ INTERFACE
     "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
-    "$<INSTALL_INTERFACE:include>")
-target_link_libraries(FLAC++ PRIVATE FLAC)
-set_target_properties(FLAC++ PROPERTIES
-    CXX_VISIBILITY_PRESET hidden
-    VERSION 6.3.0
-    SOVERSION 6)
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+target_link_libraries(FLAC++ PUBLIC FLAC)
+if(BUILD_SHARED_LIBS)
+    set_target_properties(FLAC++ PROPERTIES
+        CXX_VISIBILITY_PRESET hidden
+        VERSION 6.3.0
+        SOVERSION 6)
+endif()
 
-install(TARGETS FLAC++ FLAC++-static EXPORT targets
+install(TARGETS FLAC++ EXPORT targets
     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")
index 16afbe7..0f287e0 100644 (file)
@@ -54,7 +54,9 @@ set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
 configure_file(flac.pc.in flac.pc @ONLY)
 
-set(SOURCES
+include_directories("include")
+
+add_library(FLAC
     bitmath.c
     bitreader.c
     bitwriter.c
@@ -88,38 +90,28 @@ set(SOURCES
     $<$<BOOL:${OGG_FOUND}>:ogg_mapping.c>
     $<$<BOOL:${WIN32}>:windows_unicode_filenames.c>)
 if(TARGET FLAC-asm)
-    list(APPEND SOURCES $<TARGET_OBJECTS:FLAC-asm>)
-endif()
-
-include_directories("include")
-
-add_library(FLAC-static STATIC ${SOURCES})
-target_compile_definitions(FLAC-static PUBLIC FLAC__NO_DLL)
-target_include_directories(FLAC-static INTERFACE
-    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
-    "$<INSTALL_INTERFACE:include>")
-target_link_libraries(FLAC-static PUBLIC $<$<BOOL:${HAVE_LROUND}>:m>)
-if(TARGET Ogg::Ogg-static)
-    target_link_libraries(FLAC-static PUBLIC Ogg::Ogg-static)
-elseif(TARGET Ogg::Ogg)
-    target_link_libraries(FLAC-static PUBLIC Ogg::Ogg)
+    target_sources(FLAC PRIVATE $<TARGET_OBJECTS:FLAC-asm>)
 endif()
 
-add_library(FLAC SHARED ${SOURCES})
-target_compile_definitions(FLAC PRIVATE FLAC_API_EXPORTS FLAC__USE_VISIBILITY_ATTR)
+target_compile_definitions(FLAC
+    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC_API_EXPORTS>
+    PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
+    PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
 target_include_directories(FLAC INTERFACE
     "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
-    "$<INSTALL_INTERFACE:include>")
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
 target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>)
 if(TARGET Ogg::Ogg)
     target_link_libraries(FLAC PUBLIC Ogg::Ogg)
 endif()
-set_target_properties(FLAC PROPERTIES
-    C_VISIBILITY_PRESET hidden
-    VERSION 8.3.0
-    SOVERSION 8)
+if(BUILD_SHARED_LIBS)
+    set_target_properties(FLAC PROPERTIES
+        C_VISIBILITY_PRESET hidden
+        VERSION 8.3.0
+        SOVERSION 8)
+endif()
 
-install(TARGETS FLAC FLAC-static EXPORT targets
+install(TARGETS FLAC EXPORT targets
     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")
index 93f1ec6..77eafbd 100644 (file)
@@ -9,7 +9,7 @@ add_executable(metaflac
     options.c
     usage.c
     utils.c)
-target_link_libraries(metaflac FLAC-static getopt utf8)
+target_link_libraries(metaflac FLAC getopt utf8)
 if(TARGET win_utf8_io)
     target_link_libraries(metaflac win_utf8_io)
 endif()
index 8332fb4..203ae3f 100644 (file)
@@ -7,7 +7,7 @@ add_library(grabbag STATIC
     seektable.c
     snprintf.c)
 target_link_libraries(grabbag PUBLIC
-    FLAC-static
+    FLAC
     replaygain_analysis)
 if(TARGET win_utf8_io)
     target_link_libraries(grabbag PUBLIC win_utf8_io)
index 35c1987..dbe3a1a 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(test_cuesheet main.c)
-target_link_libraries(test_cuesheet FLAC-static grabbag)
+target_link_libraries(test_cuesheet FLAC grabbag)
index 0ae6644..a51f7db 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(test_picture main.c)
-target_link_libraries(test_picture FLAC-static grabbag)
+target_link_libraries(test_picture FLAC grabbag)
index 91d2a17..11c0052 100644 (file)
@@ -5,4 +5,4 @@ add_executable(test_libFLAC++
     metadata.cpp
     metadata_manip.cpp
     metadata_object.cpp)
-target_link_libraries(test_libFLAC++ FLAC++-static test_libs_common grabbag)
+target_link_libraries(test_libFLAC++ FLAC++ test_libs_common grabbag)
index 5679cf2..4bbadb9 100644 (file)
@@ -10,9 +10,14 @@ add_executable(test_libFLAC
     metadata.c
     metadata_manip.c
     metadata_object.c
-    md5.c)
+    md5.c
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/bitreader.c"
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/bitwriter.c"
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/crc.c"
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/md5.c")
 
 target_compile_definitions(test_libFLAC PRIVATE
     $<$<BOOL:${ENABLE_64_BIT_WORDS}>:ENABLE_64_BIT_WORDS>)
-target_include_directories(test_libFLAC PRIVATE "$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include")
-target_link_libraries(test_libFLAC FLAC-static grabbag test_libs_common)
+target_include_directories(test_libFLAC PRIVATE
+    "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
+target_link_libraries(test_libFLAC FLAC grabbag test_libs_common)
index 806f353..8a0c871 100644 (file)
@@ -1,4 +1,4 @@
 add_library(test_libs_common STATIC
     file_utils_flac.c
     metadata_utils.c)
-target_link_libraries(test_libs_common PUBLIC FLAC-static)
+target_link_libraries(test_libs_common PUBLIC FLAC)
index 1c2a2f4..dc7ae79 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(test_seeking main.c)
-target_link_libraries(test_seeking FLAC-static)
+target_link_libraries(test_seeking FLAC)
index 13e3023..f9fafb9 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(test_streams main.c)
-target_link_libraries(test_streams FLAC-static grabbag)
+target_link_libraries(test_streams FLAC grabbag)
index f212b0e..e6d08a6 100644 (file)
@@ -1,5 +1,5 @@
 add_executable(flacdiff main.cpp)
-target_link_libraries(flacdiff FLAC++-static)
+target_link_libraries(flacdiff FLAC++)
 if(TARGET win_utf8_io)
     target_link_libraries(flacdiff win_utf8_io)
 endif()
index 40db1cf..47bf1e5 100644 (file)
@@ -1,2 +1,2 @@
 add_executable(flactimer main.cpp)
-target_link_libraries(flactimer FLAC++-static)
+target_link_libraries(flactimer FLAC++)