Use of BUILD_SHARED_LIBS added

This commit is contained in:
Vitaliy Kirsanov 2019-04-29 12:48:24 +03:00 committed by Erik de Castro Lopo
parent 1cb968a7d4
commit 573dbc12ae
23 changed files with 68 additions and 97 deletions

View File

@ -14,10 +14,7 @@ endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") 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 "${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")
if(CMAKE_BULD_TYPE STREQUAL Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -funroll-loops")
endif()
option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF) option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF)
endif() endif()

View File

@ -9,31 +9,18 @@ find_library(OGG_LIBRARY
NAMES ogg libogg NAMES ogg libogg
HINTS ${_OGG_LIBRARY_DIRS}) HINTS ${_OGG_LIBRARY_DIRS})
find_library(OGG_LIBRARY_STATIC
NAMES libogg.a libogg_static
HINTS ${_OGG_LIBRARY_DIRS})
mark_as_advanced( mark_as_advanced(
OGG_INCLUDE_DIR OGG_INCLUDE_DIR
OGG_LIBRARY OGG_LIBRARY)
OGG_LIBRARY_DIRS)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OGG find_package_handle_standard_args(OGG
REQUIRED_VARS OGG_INCLUDE_DIR OGG_LIBRARY REQUIRED_VARS OGG_INCLUDE_DIR OGG_LIBRARY
VERSION_VAR _OGG_VERSION) VERSION_VAR _OGG_VERSION)
if(OGG_FOUND) if(OGG_FOUND AND NOT TARGET Ogg::Ogg)
if(NOT Ogg::Ogg) add_library(Ogg::Ogg UNKNOWN IMPORTED)
add_library(Ogg::Ogg UNKNOWN IMPORTED) set_target_properties(Ogg::Ogg PROPERTIES
set_target_properties(Ogg::Ogg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}" IMPORTED_LOCATION "${OGG_LIBRARY}")
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()
endif() endif()

View File

@ -64,7 +64,6 @@ check_c_source_compiles("
add_definitions( add_definitions(
-D_DARWIN_C_SOURCE -D_DARWIN_C_SOURCE
-D_POSIX_PTHREAD_SEMANTICS -D_POSIX_PTHREAD_SEMANTICS
-D__STDC_WANT_IEC_60559_ATTRIBS_EXT__
-D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_BFP_EXT__
-D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__
-D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__

View File

@ -199,9 +199,6 @@
#endif #endif
/* Version number of package */
#cmakedefine VERSION
/* Target processor is big endian. */ /* Target processor is big endian. */
#define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN #define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN
@ -211,10 +208,14 @@
#endif #endif
/* Number of bits in a file offset, on hosts where this is settable. */ /* 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). */ /* 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. */ /* Define for large files, on AIX-style hosts. */
#cmakedefine _LARGE_FILES #cmakedefine _LARGE_FILES
@ -229,11 +230,5 @@
/* Define to 1 if you need to in order for `stat' and other things to work. */ /* Define to 1 if you need to in order for `stat' and other things to work. */
#cmakedefine _POSIX_SOURCE #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. */ /* Define to __typeof__ if your compiler spells it that way. */
#cmakedefine typeof #cmakedefine typeof

View File

@ -1,2 +1,2 @@
add_executable(decode_file main.c) add_executable(decode_file main.c)
target_link_libraries(decode_file FLAC-static) target_link_libraries(decode_file FLAC)

View File

@ -1,2 +1,2 @@
add_executable(encode_file main.c) add_executable(encode_file main.c)
target_link_libraries(encode_file FLAC-static) target_link_libraries(encode_file FLAC)

View File

@ -1,2 +1,2 @@
add_executable(decode_file_cxx main.cpp) add_executable(decode_file_cxx main.cpp)
target_link_libraries(decode_file_cxx FLAC++-static) target_link_libraries(decode_file_cxx FLAC++)

View File

@ -1,2 +1,2 @@
add_executable(encode_file_cxx main.cpp) add_executable(encode_file_cxx main.cpp)
target_link_libraries(encode_file_cxx FLAC++-static) target_link_libraries(encode_file_cxx FLAC++)

View File

@ -11,7 +11,7 @@ endif()
add_executable(benchmark_residual benchmark_residual.c util.c) add_executable(benchmark_residual benchmark_residual.c util.c)
target_include_directories(benchmark_residual PRIVATE target_include_directories(benchmark_residual PRIVATE
"$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include") "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
target_link_libraries(benchmark_residual target_link_libraries(benchmark_residual
FLAC-static FLAC
$<$<BOOL:${HAVE_CLOCK_GETTIME}>:rt>) $<$<BOOL:${HAVE_CLOCK_GETTIME}>:rt>)

View File

@ -11,7 +11,7 @@ add_executable(flac
utils.c utils.c
vorbiscomment.c) vorbiscomment.c)
target_link_libraries(flac target_link_libraries(flac
FLAC-static FLAC
getopt getopt
replaygain_synthesis replaygain_synthesis
utf8) utf8)

View File

@ -18,30 +18,26 @@ check_cxx_source_compiles("
#endif" #endif"
HAVE_CXX_VARARRAYS) HAVE_CXX_VARARRAYS)
set(SOURCES add_library(FLAC++
metadata.cpp metadata.cpp
stream_decoder.cpp stream_decoder.cpp
stream_encoder.cpp) stream_encoder.cpp)
target_compile_definitions(FLAC++
add_library(FLAC++-static STATIC ${SOURCES}) PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLACPP_API_EXPORTS>
target_compile_definitions(FLAC++-static PUBLIC FLAC__NO_DLL) PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
target_include_directories(FLAC++-static INTERFACE PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FLAC__NO_DLL>)
"$<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_include_directories(FLAC++ INTERFACE target_include_directories(FLAC++ INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>") "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(FLAC++ PRIVATE FLAC) target_link_libraries(FLAC++ PUBLIC FLAC)
set_target_properties(FLAC++ PROPERTIES if(BUILD_SHARED_LIBS)
CXX_VISIBILITY_PRESET hidden set_target_properties(FLAC++ PROPERTIES
VERSION 6.3.0 CXX_VISIBILITY_PRESET hidden
SOVERSION 6) VERSION 6.3.0
SOVERSION 6)
endif()
install(TARGETS FLAC++ FLAC++-static EXPORT targets install(TARGETS FLAC++ EXPORT targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/") RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")

View File

@ -54,7 +54,9 @@ set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
configure_file(flac.pc.in flac.pc @ONLY) configure_file(flac.pc.in flac.pc @ONLY)
set(SOURCES include_directories("include")
add_library(FLAC
bitmath.c bitmath.c
bitreader.c bitreader.c
bitwriter.c bitwriter.c
@ -88,38 +90,28 @@ set(SOURCES
$<$<BOOL:${OGG_FOUND}>:ogg_mapping.c> $<$<BOOL:${OGG_FOUND}>:ogg_mapping.c>
$<$<BOOL:${WIN32}>:windows_unicode_filenames.c>) $<$<BOOL:${WIN32}>:windows_unicode_filenames.c>)
if(TARGET FLAC-asm) if(TARGET FLAC-asm)
list(APPEND SOURCES $<TARGET_OBJECTS:FLAC-asm>) target_sources(FLAC PRIVATE $<TARGET_OBJECTS:FLAC-asm>)
endif() endif()
include_directories("include") target_compile_definitions(FLAC
PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC_API_EXPORTS>
add_library(FLAC-static STATIC ${SOURCES}) PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLAC__USE_VISIBILITY_ATTR>
target_compile_definitions(FLAC-static PUBLIC FLAC__NO_DLL) PUBLIC $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>: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)
endif()
add_library(FLAC SHARED ${SOURCES})
target_compile_definitions(FLAC PRIVATE FLAC_API_EXPORTS FLAC__USE_VISIBILITY_ATTR)
target_include_directories(FLAC INTERFACE target_include_directories(FLAC INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>") "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>) target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>)
if(TARGET Ogg::Ogg) if(TARGET Ogg::Ogg)
target_link_libraries(FLAC PUBLIC Ogg::Ogg) target_link_libraries(FLAC PUBLIC Ogg::Ogg)
endif() endif()
set_target_properties(FLAC PROPERTIES if(BUILD_SHARED_LIBS)
C_VISIBILITY_PRESET hidden set_target_properties(FLAC PROPERTIES
VERSION 8.3.0 C_VISIBILITY_PRESET hidden
SOVERSION 8) VERSION 8.3.0
SOVERSION 8)
endif()
install(TARGETS FLAC FLAC-static EXPORT targets install(TARGETS FLAC EXPORT targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/") RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/")

View File

@ -9,7 +9,7 @@ add_executable(metaflac
options.c options.c
usage.c usage.c
utils.c) utils.c)
target_link_libraries(metaflac FLAC-static getopt utf8) target_link_libraries(metaflac FLAC getopt utf8)
if(TARGET win_utf8_io) if(TARGET win_utf8_io)
target_link_libraries(metaflac win_utf8_io) target_link_libraries(metaflac win_utf8_io)
endif() endif()

View File

@ -7,7 +7,7 @@ add_library(grabbag STATIC
seektable.c seektable.c
snprintf.c) snprintf.c)
target_link_libraries(grabbag PUBLIC target_link_libraries(grabbag PUBLIC
FLAC-static FLAC
replaygain_analysis) replaygain_analysis)
if(TARGET win_utf8_io) if(TARGET win_utf8_io)
target_link_libraries(grabbag PUBLIC win_utf8_io) target_link_libraries(grabbag PUBLIC win_utf8_io)

View File

@ -1,2 +1,2 @@
add_executable(test_cuesheet main.c) add_executable(test_cuesheet main.c)
target_link_libraries(test_cuesheet FLAC-static grabbag) target_link_libraries(test_cuesheet FLAC grabbag)

View File

@ -1,2 +1,2 @@
add_executable(test_picture main.c) add_executable(test_picture main.c)
target_link_libraries(test_picture FLAC-static grabbag) target_link_libraries(test_picture FLAC grabbag)

View File

@ -5,4 +5,4 @@ add_executable(test_libFLAC++
metadata.cpp metadata.cpp
metadata_manip.cpp metadata_manip.cpp
metadata_object.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)

View File

@ -10,9 +10,14 @@ add_executable(test_libFLAC
metadata.c metadata.c
metadata_manip.c metadata_manip.c
metadata_object.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 target_compile_definitions(test_libFLAC PRIVATE
$<$<BOOL:${ENABLE_64_BIT_WORDS}>:ENABLE_64_BIT_WORDS>) $<$<BOOL:${ENABLE_64_BIT_WORDS}>:ENABLE_64_BIT_WORDS>)
target_include_directories(test_libFLAC PRIVATE "$<TARGET_PROPERTY:FLAC-static,SOURCE_DIR>/include") target_include_directories(test_libFLAC PRIVATE
target_link_libraries(test_libFLAC FLAC-static grabbag test_libs_common) "$<TARGET_PROPERTY:FLAC,SOURCE_DIR>/include")
target_link_libraries(test_libFLAC FLAC grabbag test_libs_common)

View File

@ -1,4 +1,4 @@
add_library(test_libs_common STATIC add_library(test_libs_common STATIC
file_utils_flac.c file_utils_flac.c
metadata_utils.c) metadata_utils.c)
target_link_libraries(test_libs_common PUBLIC FLAC-static) target_link_libraries(test_libs_common PUBLIC FLAC)

View File

@ -1,2 +1,2 @@
add_executable(test_seeking main.c) add_executable(test_seeking main.c)
target_link_libraries(test_seeking FLAC-static) target_link_libraries(test_seeking FLAC)

View File

@ -1,2 +1,2 @@
add_executable(test_streams main.c) add_executable(test_streams main.c)
target_link_libraries(test_streams FLAC-static grabbag) target_link_libraries(test_streams FLAC grabbag)

View File

@ -1,5 +1,5 @@
add_executable(flacdiff main.cpp) add_executable(flacdiff main.cpp)
target_link_libraries(flacdiff FLAC++-static) target_link_libraries(flacdiff FLAC++)
if(TARGET win_utf8_io) if(TARGET win_utf8_io)
target_link_libraries(flacdiff win_utf8_io) target_link_libraries(flacdiff win_utf8_io)
endif() endif()

View File

@ -1,2 +1,2 @@
add_executable(flactimer main.cpp) add_executable(flactimer main.cpp)
target_link_libraries(flactimer FLAC++-static) target_link_libraries(flactimer FLAC++)