From 573dbc12ae3fc68e8edea08842f5864c553cd311 Mon Sep 17 00:00:00 2001 From: Vitaliy Kirsanov Date: Mon, 29 Apr 2019 12:48:24 +0300 Subject: [PATCH] Use of BUILD_SHARED_LIBS added --- CMakeLists.txt | 5 +-- cmake/FindOGG.cmake | 25 ++++----------- cmake/UseSystemExtensions.cmake | 1 - config.cmake.h.in | 17 ++++------ examples/c/decode/file/CMakeLists.txt | 2 +- examples/c/encode/file/CMakeLists.txt | 2 +- examples/cpp/decode/file/CMakeLists.txt | 2 +- examples/cpp/encode/file/CMakeLists.txt | 2 +- microbench/CMakeLists.txt | 4 +-- src/flac/CMakeLists.txt | 2 +- src/libFLAC++/CMakeLists.txt | 32 +++++++++---------- src/libFLAC/CMakeLists.txt | 40 ++++++++++-------------- src/metaflac/CMakeLists.txt | 2 +- src/share/grabbag/CMakeLists.txt | 2 +- src/test_grabbag/cuesheet/CMakeLists.txt | 2 +- src/test_grabbag/picture/CMakeLists.txt | 2 +- src/test_libFLAC++/CMakeLists.txt | 2 +- src/test_libFLAC/CMakeLists.txt | 11 +++++-- src/test_libs_common/CMakeLists.txt | 2 +- src/test_seeking/CMakeLists.txt | 2 +- src/test_streams/CMakeLists.txt | 2 +- src/utils/flacdiff/CMakeLists.txt | 2 +- src/utils/flactimer/CMakeLists.txt | 2 +- 23 files changed, 68 insertions(+), 97 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 886e9f58..6d3666b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/FindOGG.cmake b/cmake/FindOGG.cmake index 4b08040d..f9843455 100644 --- a/cmake/FindOGG.cmake +++ b/cmake/FindOGG.cmake @@ -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() diff --git a/cmake/UseSystemExtensions.cmake b/cmake/UseSystemExtensions.cmake index 5ef9b470..f3c9490f 100644 --- a/cmake/UseSystemExtensions.cmake +++ b/cmake/UseSystemExtensions.cmake @@ -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__ diff --git a/config.cmake.h.in b/config.cmake.h.in index b6c18774..1d96f426 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -199,9 +199,6 @@ #endif -/* Version number of package */ -#cmakedefine VERSION - /* Target processor is big endian. */ #define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN @@ -211,10 +208,14 @@ #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 @@ -229,11 +230,5 @@ /* 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 diff --git a/examples/c/decode/file/CMakeLists.txt b/examples/c/decode/file/CMakeLists.txt index 60dc18e0..53a29918 100644 --- a/examples/c/decode/file/CMakeLists.txt +++ b/examples/c/decode/file/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(decode_file main.c) -target_link_libraries(decode_file FLAC-static) +target_link_libraries(decode_file FLAC) diff --git a/examples/c/encode/file/CMakeLists.txt b/examples/c/encode/file/CMakeLists.txt index c9c8e802..4b7d4c2c 100644 --- a/examples/c/encode/file/CMakeLists.txt +++ b/examples/c/encode/file/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(encode_file main.c) -target_link_libraries(encode_file FLAC-static) +target_link_libraries(encode_file FLAC) diff --git a/examples/cpp/decode/file/CMakeLists.txt b/examples/cpp/decode/file/CMakeLists.txt index 46ab401e..2ce420d7 100644 --- a/examples/cpp/decode/file/CMakeLists.txt +++ b/examples/cpp/decode/file/CMakeLists.txt @@ -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++) diff --git a/examples/cpp/encode/file/CMakeLists.txt b/examples/cpp/encode/file/CMakeLists.txt index cc117215..26178763 100644 --- a/examples/cpp/encode/file/CMakeLists.txt +++ b/examples/cpp/encode/file/CMakeLists.txt @@ -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++) diff --git a/microbench/CMakeLists.txt b/microbench/CMakeLists.txt index c43814fd..639915b6 100644 --- a/microbench/CMakeLists.txt +++ b/microbench/CMakeLists.txt @@ -11,7 +11,7 @@ endif() add_executable(benchmark_residual benchmark_residual.c util.c) target_include_directories(benchmark_residual PRIVATE - "$/include") + "$/include") target_link_libraries(benchmark_residual - FLAC-static + FLAC $<$:rt>) diff --git a/src/flac/CMakeLists.txt b/src/flac/CMakeLists.txt index c347c9a4..97903577 100644 --- a/src/flac/CMakeLists.txt +++ b/src/flac/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(flac utils.c vorbiscomment.c) target_link_libraries(flac - FLAC-static + FLAC getopt replaygain_synthesis utf8) diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt index 35d145c4..d6e3dfd6 100644 --- a/src/libFLAC++/CMakeLists.txt +++ b/src/libFLAC++/CMakeLists.txt @@ -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 - "$" - "$") -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 $<$:FLACPP_API_EXPORTS> + PRIVATE $<$:FLAC__USE_VISIBILITY_ATTR> + PUBLIC $<$>:FLAC__NO_DLL>) target_include_directories(FLAC++ INTERFACE "$" - "$") -target_link_libraries(FLAC++ PRIVATE FLAC) -set_target_properties(FLAC++ PROPERTIES - CXX_VISIBILITY_PRESET hidden - VERSION 6.3.0 - SOVERSION 6) + "$") +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}/") diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt index 16afbe73..0f287e0b 100644 --- a/src/libFLAC/CMakeLists.txt +++ b/src/libFLAC/CMakeLists.txt @@ -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 $<$:ogg_mapping.c> $<$:windows_unicode_filenames.c>) if(TARGET FLAC-asm) - list(APPEND SOURCES $) + target_sources(FLAC PRIVATE $) 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 - "$" - "$") -target_link_libraries(FLAC-static PUBLIC $<$: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) -endif() - -add_library(FLAC SHARED ${SOURCES}) -target_compile_definitions(FLAC PRIVATE FLAC_API_EXPORTS FLAC__USE_VISIBILITY_ATTR) +target_compile_definitions(FLAC + PRIVATE $<$:FLAC_API_EXPORTS> + PRIVATE $<$:FLAC__USE_VISIBILITY_ATTR> + PUBLIC $<$>:FLAC__NO_DLL>) target_include_directories(FLAC INTERFACE "$" - "$") + "$") target_link_libraries(FLAC PRIVATE $<$: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}/") diff --git a/src/metaflac/CMakeLists.txt b/src/metaflac/CMakeLists.txt index 93f1ec6e..77eafbdb 100644 --- a/src/metaflac/CMakeLists.txt +++ b/src/metaflac/CMakeLists.txt @@ -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() diff --git a/src/share/grabbag/CMakeLists.txt b/src/share/grabbag/CMakeLists.txt index 8332fb49..203ae3f4 100644 --- a/src/share/grabbag/CMakeLists.txt +++ b/src/share/grabbag/CMakeLists.txt @@ -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) diff --git a/src/test_grabbag/cuesheet/CMakeLists.txt b/src/test_grabbag/cuesheet/CMakeLists.txt index 35c1987d..dbe3a1a6 100644 --- a/src/test_grabbag/cuesheet/CMakeLists.txt +++ b/src/test_grabbag/cuesheet/CMakeLists.txt @@ -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) diff --git a/src/test_grabbag/picture/CMakeLists.txt b/src/test_grabbag/picture/CMakeLists.txt index 0ae66449..a51f7db8 100644 --- a/src/test_grabbag/picture/CMakeLists.txt +++ b/src/test_grabbag/picture/CMakeLists.txt @@ -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) diff --git a/src/test_libFLAC++/CMakeLists.txt b/src/test_libFLAC++/CMakeLists.txt index 91d2a173..11c0052c 100644 --- a/src/test_libFLAC++/CMakeLists.txt +++ b/src/test_libFLAC++/CMakeLists.txt @@ -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) diff --git a/src/test_libFLAC/CMakeLists.txt b/src/test_libFLAC/CMakeLists.txt index 5679cf25..4bbadb9c 100644 --- a/src/test_libFLAC/CMakeLists.txt +++ b/src/test_libFLAC/CMakeLists.txt @@ -10,9 +10,14 @@ add_executable(test_libFLAC metadata.c metadata_manip.c metadata_object.c - md5.c) + md5.c + "$/bitreader.c" + "$/bitwriter.c" + "$/crc.c" + "$/md5.c") target_compile_definitions(test_libFLAC PRIVATE $<$:ENABLE_64_BIT_WORDS>) -target_include_directories(test_libFLAC PRIVATE "$/include") -target_link_libraries(test_libFLAC FLAC-static grabbag test_libs_common) +target_include_directories(test_libFLAC PRIVATE + "$/include") +target_link_libraries(test_libFLAC FLAC grabbag test_libs_common) diff --git a/src/test_libs_common/CMakeLists.txt b/src/test_libs_common/CMakeLists.txt index 806f3530..8a0c8712 100644 --- a/src/test_libs_common/CMakeLists.txt +++ b/src/test_libs_common/CMakeLists.txt @@ -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) diff --git a/src/test_seeking/CMakeLists.txt b/src/test_seeking/CMakeLists.txt index 1c2a2f4b..dc7ae799 100644 --- a/src/test_seeking/CMakeLists.txt +++ b/src/test_seeking/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(test_seeking main.c) -target_link_libraries(test_seeking FLAC-static) +target_link_libraries(test_seeking FLAC) diff --git a/src/test_streams/CMakeLists.txt b/src/test_streams/CMakeLists.txt index 13e30234..f9fafb9d 100644 --- a/src/test_streams/CMakeLists.txt +++ b/src/test_streams/CMakeLists.txt @@ -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) diff --git a/src/utils/flacdiff/CMakeLists.txt b/src/utils/flacdiff/CMakeLists.txt index f212b0ea..e6d08a63 100644 --- a/src/utils/flacdiff/CMakeLists.txt +++ b/src/utils/flacdiff/CMakeLists.txt @@ -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() diff --git a/src/utils/flactimer/CMakeLists.txt b/src/utils/flactimer/CMakeLists.txt index 40db1cf1..47bf1e5f 100644 --- a/src/utils/flactimer/CMakeLists.txt +++ b/src/utils/flactimer/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(flactimer main.cpp) -target_link_libraries(flactimer FLAC++-static) +target_link_libraries(flactimer FLAC++)