From e0b62a61a7b65aef187b038454925a34fa315125 Mon Sep 17 00:00:00 2001 From: evpobr Date: Sat, 2 May 2020 10:54:28 +0500 Subject: [PATCH] Bunch of CMake fixes * Add more Git ignore patterns * Fix Ogg dependency handling (closes #203) * Remove unneeded compiler flag (closes #204) * Fix Visual Studio DLL build error error C2491: 'flac_internal_rename_utf8': definition of dllimport function not allowed (closes #205) * Add alias targets * Reduce number of CMake files * Improve CMake intrinsics detection --- .gitignore | 15 ++++++++++++++ CMakeLists.txt | 12 ++++++------ Makefile.am | 2 +- cmake/{FindOGG.cmake => FindOgg.cmake} | 2 +- doc/CMakeLists.txt | 25 ++++++++++++++++++++++-- doc/html/CMakeLists.txt | 22 --------------------- doc/html/Makefile.am | 2 +- doc/html/images/CMakeLists.txt | 4 ---- doc/html/images/Makefile.am | 2 +- examples/CMakeLists.txt | 7 +++++-- examples/c/CMakeLists.txt | 2 -- examples/c/Makefile.am | 2 -- examples/cpp/CMakeLists.txt | 2 -- examples/cpp/Makefile.am | 2 -- flac-config.cmake.in | 7 ++----- src/CMakeLists.txt | 14 +++++++++++-- src/flac/CMakeLists.txt | 7 +++---- src/libFLAC++/CMakeLists.txt | 2 ++ src/libFLAC/CMakeLists.txt | 7 ++++--- src/metaflac/CMakeLists.txt | 7 +++---- src/share/CMakeLists.txt | 8 -------- src/share/Makefile.am | 2 -- src/share/win_utf8_io/CMakeLists.txt | 1 - src/test_grabbag/cuesheet/CMakeLists.txt | 5 ++++- src/test_grabbag/picture/CMakeLists.txt | 5 ++++- src/test_libFLAC++/CMakeLists.txt | 4 +++- src/test_libFLAC/CMakeLists.txt | 4 +++- src/test_seeking/CMakeLists.txt | 5 ++++- src/utils/CMakeLists.txt | 6 ------ src/utils/Makefile.am | 2 -- src/utils/flacdiff/CMakeLists.txt | 8 ++++---- 31 files changed, 101 insertions(+), 94 deletions(-) rename cmake/{FindOGG.cmake => FindOgg.cmake} (94%) delete mode 100644 doc/html/CMakeLists.txt delete mode 100644 doc/html/images/CMakeLists.txt delete mode 100644 examples/c/CMakeLists.txt delete mode 100644 examples/cpp/CMakeLists.txt delete mode 100644 src/share/CMakeLists.txt delete mode 100644 src/share/win_utf8_io/CMakeLists.txt delete mode 100644 src/utils/CMakeLists.txt diff --git a/.gitignore b/.gitignore index c38747c3..88d097c2 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,18 @@ test/picture.log microbench/benchmark_residual oss-fuzz/fuzz-decoder oss-fuzz/fuzz-encoder + +/*[Bb]uild*/ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +/.vs*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c26b0b7..c83dd83e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ option(INSTALL_CMAKE_CONFIG_MODULE "Install CMake package-config module" ON) option(WITH_OGG "ogg support (default: test for libogg)" ON) if(WITH_OGG) - find_package(OGG REQUIRED) + find_package(Ogg REQUIRED) endif() find_package(Iconv) @@ -36,9 +36,6 @@ endif() if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wsign-promo -Wundef") endif() -if(CMAKE_C_COMPILER_ID MATCHES "GNU") - set(CMAKE_EXE_LINKER_FLAGS -no-pie) -endif() include(CMakePackageConfigHelpers) include(CPack) @@ -57,7 +54,11 @@ include(TestBigEndian) check_include_file("byteswap.h" HAVE_BYTESWAP_H) check_include_file("inttypes.h" HAVE_INTTYPES_H) check_include_file("stdint.h" HAVE_STDINT_H) -check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN) +if(MSVC) + check_include_file("intrin.h" FLAC__HAS_X86INTRIN) +else() + check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN) +endif() check_function_exists(fseeko HAVE_FSEEKO) @@ -140,7 +141,6 @@ if(INSTALL_CMAKE_CONFIG_MODULE) FILES "${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake" - "cmake/FindOGG.cmake" DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") endif() diff --git a/Makefile.am b/Makefile.am index ce4519f9..33bc679e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,7 @@ EXTRA_DIST = \ CMakeLists.txt \ config.cmake.h.in \ flac-config.cmake.in \ - cmake/FindOGG.cmake \ + cmake/FindOgg.cmake \ cmake/UseSystemExtensions.cmake \ COPYING.FDL \ COPYING.GPL \ diff --git a/cmake/FindOGG.cmake b/cmake/FindOgg.cmake similarity index 94% rename from cmake/FindOGG.cmake rename to cmake/FindOgg.cmake index 7f424126..b60c3526 100644 --- a/cmake/FindOGG.cmake +++ b/cmake/FindOgg.cmake @@ -14,7 +14,7 @@ mark_as_advanced( OGG_LIBRARY) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(OGG +find_package_handle_standard_args(Ogg REQUIRED_VARS OGG_INCLUDE_DIR OGG_LIBRARY VERSION_VAR _OGG_VERSION) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index c7b075b1..9af88e4e 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -19,7 +19,28 @@ doxygen_add_docs(FLAC-doxygen "${PROJECT_SOURCE_DIR}/include/FLAC" "${PROJECT_SOURCE_DIR}/include/FLAC++") -add_subdirectory(html) - install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/api") + +install(FILES + html/images/logo.svg + html/images/logo130.gif + html/changelog.html + html/developers.html + html/documentation.html + html/documentation_bugs.html + html/documentation_example_code.html + html/documentation_format_overview.html + html/documentation_tools.html + html/documentation_tools_flac.html + html/documentation_tools_metaflac.html + html/faq.html + html/favicon.ico + html/features.html + html/flac.css + html/format.html + html/id.html + html/index.html + html/license.html + html/ogg_mapping.html +DESTINATION "${CMAKE_INSTALL_DOCDIR}/html") diff --git a/doc/html/CMakeLists.txt b/doc/html/CMakeLists.txt deleted file mode 100644 index 6ac1e116..00000000 --- a/doc/html/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -add_subdirectory(images) - -install(FILES - changelog.html - developers.html - documentation.html - documentation_bugs.html - documentation_example_code.html - documentation_format_overview.html - documentation_tools.html - documentation_tools_flac.html - documentation_tools_metaflac.html - faq.html - favicon.ico - features.html - flac.css - format.html - id.html - index.html - license.html - ogg_mapping.html -DESTINATION "${CMAKE_INSTALL_DOCDIR}/html") diff --git a/doc/html/Makefile.am b/doc/html/Makefile.am index 3a274ef5..2c73fdbb 100644 --- a/doc/html/Makefile.am +++ b/doc/html/Makefile.am @@ -38,7 +38,7 @@ html_DATA = \ license.html \ ogg_mapping.html -EXTRA_DIST = $(html_DATA) api CMakeLists.txt +EXTRA_DIST = $(html_DATA) api if FLaC__HAS_DOXYGEN # The install targets don't copy whole directories so we have to diff --git a/doc/html/images/CMakeLists.txt b/doc/html/images/CMakeLists.txt deleted file mode 100644 index 922d305c..00000000 --- a/doc/html/images/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -install(FILES - logo.svg - logo130.gif -DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/images") diff --git a/doc/html/images/Makefile.am b/doc/html/images/Makefile.am index 04ad59aa..467651cd 100644 --- a/doc/html/images/Makefile.am +++ b/doc/html/images/Makefile.am @@ -22,4 +22,4 @@ logos_DATA = \ logo.svg \ logo130.gif -EXTRA_DIST = $(logos_DATA) CMakeLists.txt +EXTRA_DIST = $(logos_DATA) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 96298fd7..ed18e3b1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,7 @@ -add_subdirectory("c") +add_subdirectory("c/decode/file") +add_subdirectory("c/encode/file") + if(BUILD_CXXLIBS) - add_subdirectory("cpp") + add_subdirectory("cpp/decode/file") + add_subdirectory("cpp/encode/file") endif() diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt deleted file mode 100644 index 41153417..00000000 --- a/examples/c/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory("decode/file") -add_subdirectory("encode/file") diff --git a/examples/c/Makefile.am b/examples/c/Makefile.am index b3f58bb3..e44ad017 100644 --- a/examples/c/Makefile.am +++ b/examples/c/Makefile.am @@ -17,5 +17,3 @@ # distribution. SUBDIRS = decode encode - -EXTRA_DIST = CMakeLists.txt diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt deleted file mode 100644 index 41153417..00000000 --- a/examples/cpp/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory("decode/file") -add_subdirectory("encode/file") diff --git a/examples/cpp/Makefile.am b/examples/cpp/Makefile.am index b3f58bb3..e44ad017 100644 --- a/examples/cpp/Makefile.am +++ b/examples/cpp/Makefile.am @@ -17,5 +17,3 @@ # distribution. SUBDIRS = decode encode - -EXTRA_DIST = CMakeLists.txt diff --git a/flac-config.cmake.in b/flac-config.cmake.in index 8d6ba5a5..f44133c5 100644 --- a/flac-config.cmake.in +++ b/flac-config.cmake.in @@ -1,10 +1,7 @@ @PACKAGE_INIT@ -if(@OGG_FOUND@) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - include(CMakeFindDependencyMacro) - find_dependency(OGG) -endif() +include(CMakeFindDependencyMacro) +find_dependency(Ogg) include("${CMAKE_CURRENT_LIST_DIR}/targets.cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5579fa88..b3c9fcf5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,12 +7,22 @@ add_subdirectory("libFLAC") if(BUILD_CXXLIBS) add_subdirectory("libFLAC++") endif() -add_subdirectory("share") +add_subdirectory("share/replaygain_analysis") +add_subdirectory("share/replaygain_synthesis") +add_subdirectory("share/getopt") +add_subdirectory("share/utf8") +add_subdirectory("share/grabbag") + if(BUILD_PROGRAMS) add_subdirectory("flac") add_subdirectory("metaflac") endif() -add_subdirectory("utils") +if(BUILD_CXXLIBS) + add_subdirectory(utils/flacdiff) + if(WIN32) + add_subdirectory(utils/flactimer) + endif() +endif() if(WITH_XMMS) add_subdirectory("plugin_common") diff --git a/src/flac/CMakeLists.txt b/src/flac/CMakeLists.txt index ea4f6873..c227cd87 100644 --- a/src/flac/CMakeLists.txt +++ b/src/flac/CMakeLists.txt @@ -9,16 +9,15 @@ add_executable(flacapp main.c local_string_utils.c utils.c - vorbiscomment.c) + vorbiscomment.c + $<$:../../include/share/win_utf8_io.h> + $<$:../share/win_utf8_io/win_utf8_io.c>) set_property(TARGET flacapp PROPERTY RUNTIME_OUTPUT_NAME flac) target_link_libraries(flacapp FLAC getopt replaygain_synthesis utf8) -if(TARGET win_utf8_io) - target_link_libraries(flacapp win_utf8_io) -endif() install(TARGETS flacapp EXPORT targets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt index 9b453007..ec27835c 100644 --- a/src/libFLAC++/CMakeLists.txt +++ b/src/libFLAC++/CMakeLists.txt @@ -35,6 +35,8 @@ if(BUILD_SHARED_LIBS) endif() endif() +add_library(FLAC::FLAC++ ALIAS FLAC++) + install(TARGETS FLAC++ EXPORT targets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/" diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt index 84f9ab83..cb5b2a63 100644 --- a/src/libFLAC/CMakeLists.txt +++ b/src/libFLAC/CMakeLists.txt @@ -75,6 +75,8 @@ add_library(FLAC stream_encoder_intrin_avx2.c stream_encoder_framing.c window.c + $<$:../../include/share/windows_unicode_filenames.h> + $<$:windows_unicode_filenames.c> $<$:ogg_decoder_aspect.c> $<$:ogg_encoder_aspect.c> $<$:ogg_helper.c> @@ -82,9 +84,6 @@ add_library(FLAC if(TARGET FLAC-asm) target_sources(FLAC PRIVATE $) endif() -if(WIN32) - target_sources(FLAC PUBLIC $) -endif() target_compile_definitions(FLAC PRIVATE $<$:FLAC_API_EXPORTS> @@ -108,6 +107,8 @@ if(BUILD_SHARED_LIBS) endif() endif() +add_library(FLAC::FLAC ALIAS FLAC) + install(TARGETS FLAC EXPORT targets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" diff --git a/src/metaflac/CMakeLists.txt b/src/metaflac/CMakeLists.txt index 77eafbdb..677ab1a5 100644 --- a/src/metaflac/CMakeLists.txt +++ b/src/metaflac/CMakeLists.txt @@ -8,11 +8,10 @@ add_executable(metaflac operations_shorthand_vorbiscomment.c options.c usage.c - utils.c) + utils.c + $<$:../../include/share/win_utf8_io.h> + $<$:../share/win_utf8_io/win_utf8_io.c>) target_link_libraries(metaflac FLAC getopt utf8) -if(TARGET win_utf8_io) - target_link_libraries(metaflac win_utf8_io) -endif() install(TARGETS metaflac EXPORT targets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/src/share/CMakeLists.txt b/src/share/CMakeLists.txt deleted file mode 100644 index b3c5a712..00000000 --- a/src/share/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -add_subdirectory("replaygain_analysis") -add_subdirectory("replaygain_synthesis") -add_subdirectory("getopt") -add_subdirectory("utf8") -if(WIN32) - add_subdirectory("win_utf8_io") -endif() -add_subdirectory("grabbag") diff --git a/src/share/Makefile.am b/src/share/Makefile.am index 00724ec5..9ee826b4 100644 --- a/src/share/Makefile.am +++ b/src/share/Makefile.am @@ -21,7 +21,6 @@ AUTOMAKE_OPTIONS = subdir-objects AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include EXTRA_DIST = \ - CMakeLists.txt \ Makefile.lite \ README \ getopt/CMakeLists.txt \ @@ -52,7 +51,6 @@ EXTRA_DIST = \ utf8/utf8_static.vcproj \ utf8/utf8_static.vcxproj \ utf8/utf8_static.vcxproj.filters \ - win_utf8_io/CMakeLists.txt \ win_utf8_io/Makefile.lite \ win_utf8_io/win_utf8_io_static.vcproj \ win_utf8_io/win_utf8_io_static.vcxproj \ diff --git a/src/share/win_utf8_io/CMakeLists.txt b/src/share/win_utf8_io/CMakeLists.txt deleted file mode 100644 index 797e728b..00000000 --- a/src/share/win_utf8_io/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_library(win_utf8_io STATIC win_utf8_io.c) diff --git a/src/test_grabbag/cuesheet/CMakeLists.txt b/src/test_grabbag/cuesheet/CMakeLists.txt index dbe3a1a6..5f9a646c 100644 --- a/src/test_grabbag/cuesheet/CMakeLists.txt +++ b/src/test_grabbag/cuesheet/CMakeLists.txt @@ -1,2 +1,5 @@ -add_executable(test_cuesheet main.c) +add_executable(test_cuesheet + main.c + $<$:../../../include/share/win_utf8_io.h> + $<$:../../share/win_utf8_io/win_utf8_io.c>) target_link_libraries(test_cuesheet FLAC grabbag) diff --git a/src/test_grabbag/picture/CMakeLists.txt b/src/test_grabbag/picture/CMakeLists.txt index a51f7db8..77f1a388 100644 --- a/src/test_grabbag/picture/CMakeLists.txt +++ b/src/test_grabbag/picture/CMakeLists.txt @@ -1,2 +1,5 @@ -add_executable(test_picture main.c) +add_executable(test_picture + main.c + $<$:../../../include/share/win_utf8_io.h> + $<$:../../share/win_utf8_io/win_utf8_io.c>) target_link_libraries(test_picture FLAC grabbag) diff --git a/src/test_libFLAC++/CMakeLists.txt b/src/test_libFLAC++/CMakeLists.txt index 11c0052c..2fa7b1e7 100644 --- a/src/test_libFLAC++/CMakeLists.txt +++ b/src/test_libFLAC++/CMakeLists.txt @@ -4,5 +4,7 @@ add_executable(test_libFLAC++ main.cpp metadata.cpp metadata_manip.cpp - metadata_object.cpp) + metadata_object.cpp + $<$:../../include/share/win_utf8_io.h> + $<$:../share/win_utf8_io/win_utf8_io.c>) 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 4bbadb9c..36a58200 100644 --- a/src/test_libFLAC/CMakeLists.txt +++ b/src/test_libFLAC/CMakeLists.txt @@ -14,7 +14,9 @@ add_executable(test_libFLAC "$/bitreader.c" "$/bitwriter.c" "$/crc.c" - "$/md5.c") + "$/md5.c" + $<$:../../include/share/win_utf8_io.h> + $<$:../share/win_utf8_io/win_utf8_io.c>) target_compile_definitions(test_libFLAC PRIVATE $<$:ENABLE_64_BIT_WORDS>) diff --git a/src/test_seeking/CMakeLists.txt b/src/test_seeking/CMakeLists.txt index dc7ae799..51442916 100644 --- a/src/test_seeking/CMakeLists.txt +++ b/src/test_seeking/CMakeLists.txt @@ -1,2 +1,5 @@ -add_executable(test_seeking main.c) +add_executable(test_seeking + main.c + $<$:../../include/share/win_utf8_io.h> + $<$:../share/win_utf8_io/win_utf8_io.c>) target_link_libraries(test_seeking FLAC) diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt deleted file mode 100644 index cd7b060f..00000000 --- a/src/utils/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -if(BUILD_CXXLIBS) - add_subdirectory(flacdiff) - if(WIN32) - add_subdirectory(flactimer) - endif() -endif() diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 9ea289be..7696a6cd 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -17,5 +17,3 @@ # distribution. SUBDIRS = flacdiff flactimer - -EXTRA_DIST = CMakeLists.txt diff --git a/src/utils/flacdiff/CMakeLists.txt b/src/utils/flacdiff/CMakeLists.txt index e6d08a63..ec9f771c 100644 --- a/src/utils/flacdiff/CMakeLists.txt +++ b/src/utils/flacdiff/CMakeLists.txt @@ -1,5 +1,5 @@ -add_executable(flacdiff main.cpp) +add_executable(flacdiff + main.cpp + $<$:../../../include/share/win_utf8_io.h> + $<$:../../share/win_utf8_io/win_utf8_io.c>) target_link_libraries(flacdiff FLAC++) -if(TARGET win_utf8_io) - target_link_libraries(flacdiff win_utf8_io) -endif()