From a82a014cf14cb58280b20106a2e919ba1c48e0e6 Mon Sep 17 00:00:00 2001 From: Vitaly Kirsanov Date: Thu, 25 Apr 2019 14:14:28 +0000 Subject: [PATCH] CMake minimum required lowered to 3.1 --- CMakeLists.txt | 33 ++--- cmake/UseSystemExtensions.cmake | 29 ++-- config.cmake.h.in | 239 ++++++++++++++++++++++++++++++++ doc/CMakeLists.txt | 1 + microbench/CMakeLists.txt | 6 +- src/CMakeLists.txt | 11 +- src/flac/CMakeLists.txt | 6 - src/libFLAC++/CMakeLists.txt | 2 - src/libFLAC/CMakeLists.txt | 47 +++---- src/share/getopt/CMakeLists.txt | 10 +- 10 files changed, 296 insertions(+), 88 deletions(-) create mode 100644 config.cmake.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 38f6132a..886e9f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.0) -project(FLAC VERSION 1.3.2 HOMEPAGE_URL "https://www.xiph.org/flac/") +project(FLAC VERSION 1.3.2) # HOMEPAGE_URL "https://www.xiph.org/flac/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -45,7 +45,7 @@ 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" HAVE_X86INTRIN_H) +check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN) check_function_exists(fseeko HAVE_FSEEKO) @@ -64,19 +64,6 @@ if(HAVE_WERROR_FLAG) option(ENABLE_WERROR "Enable -Werror in all Makefiles" OFF) endif() -add_compile_definitions( - PACKAGE_VERSION="${PROJECT_VERSION}" - $<$:HAVE_BYTESWAP_H> - $<$:HAVE_INTTYPES_H> - $<$:HAVE_STDINT_H> - $<$:HAVE_FSEEKO> - $<$:_CRT_SECURE_NO_WARNINGS> - CPU_IS_BIG_ENDIAN=$ - CPU_IS_LITTLE_ENDIAN=$> - FLAC__HAS_X86INTRIN=$ - HAVE_BSWAP16=$ - HAVE_BSWAP32=$) - add_compile_options( $<$:/wd4267> $<$:/wd4996> @@ -93,6 +80,18 @@ endif() include_directories("include") +include_directories("${CMAKE_CURRENT_BINARY_DIR}") +add_definitions(-DHAVE_CONFIG_H) + +if(MSVC) + add_definitions( + -D_CRT_SECURE_NO_WARNINGS + -D_USE_MATH_DEFINES) +endif() +if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + add_definitions(-DFLAC__OVERFLOW_DETECT) +endif() + add_subdirectory("doc") add_subdirectory("src") add_subdirectory("microbench") @@ -103,6 +102,8 @@ if(BUILD_TESTING) add_subdirectory("test") endif() +configure_file(config.cmake.h.in config.h) + install( EXPORT targets DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake" diff --git a/cmake/UseSystemExtensions.cmake b/cmake/UseSystemExtensions.cmake index 4a33fd4b..5ef9b470 100644 --- a/cmake/UseSystemExtensions.cmake +++ b/cmake/UseSystemExtensions.cmake @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.12) - include(CheckCSourceCompiles) check_c_source_compiles(" @@ -63,19 +61,14 @@ check_c_source_compiles(" int main() { return 0; }" DODEFINE_EXTENSIONS) -add_compile_definitions( - _ALL_SOURCE - _DARWIN_C_SOURCE - _GNU_SOURCE - _POSIX_PTHREAD_SEMANTICS - __STDC_WANT_IEC_60559_ATTRIBS_EXT__ - __STDC_WANT_IEC_60559_BFP_EXT__ - __STDC_WANT_IEC_60559_DFP_EXT__ - __STDC_WANT_IEC_60559_FUNCS_EXT__ - __STDC_WANT_IEC_60559_TYPES_EXT__ - __STDC_WANT_LIB_EXT2__ - __STDC_WANT_MATH_SPEC_FUNCS__ - _TANDEM_SOURCE - $<$,$,$>>:_FORTIFY_SOURCE=2> - $<$:_XOPEN_SOURCE=500> - $<$:__EXTENSIONS__>) +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__ + -D__STDC_WANT_IEC_60559_TYPES_EXT__ + -D__STDC_WANT_LIB_EXT2__ + -D__STDC_WANT_MATH_SPEC_FUNCS__ + -D_TANDEM_SOURCE) diff --git a/config.cmake.h.in b/config.cmake.h.in new file mode 100644 index 00000000..b6c18774 --- /dev/null +++ b/config.cmake.h.in @@ -0,0 +1,239 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#cmakedefine AC_APPLE_UNIVERSAL_BUILD + +/* Target processor is big endian. */ +#cmakedefine01 CPU_IS_BIG_ENDIAN + +/* Target processor is little endian. */ +#cmakedefine01 CPU_IS_LITTLE_ENDIAN + +/* Set FLAC__BYTES_PER_WORD to 8 (4 is the default) */ +#cmakedefine01 ENABLE_64_BIT_WORDS + +/* define to align allocated memory on 32-byte boundaries */ +#cmakedefine FLAC__ALIGN_MALLOC_DATA + +/* define if you have docbook-to-man or docbook2man */ +#cmakedefine FLAC__HAS_DOCBOOK_TO_MAN + +/* define if you are compiling for x86 and have the NASM assembler */ +#cmakedefine FLAC__HAS_NASM + +/* define if you have the ogg library */ +#cmakedefine01 OGG_FOUND +#define FLAC__HAS_OGG OGG_FOUND + +/* define if compiler has __attribute__((target("cpu=power8"))) support */ +#cmakedefine FLAC__HAS_TARGET_POWER8 + +/* define if compiler has __attribute__((target("cpu=power9"))) support */ +#cmakedefine FLAC__HAS_TARGET_POWER9 + +/* Set to 1 if is available. */ +#cmakedefine01 FLAC__HAS_X86INTRIN + +/* define if building for Darwin / MacOS X */ +#cmakedefine FLAC__SYS_DARWIN + +/* define if building for Linux */ +#cmakedefine FLAC__SYS_LINUX + +/* define to enable use of Altivec instructions */ +#cmakedefine FLAC__USE_ALTIVEC + +/* define to enable use of AVX instructions */ +#cmakedefine01 WITH_AVX +#define FLAC__USE_AVX WITH_AVX + +/* define to enable use of VSX instructions */ +#cmakedefine FLAC__USE_VSX + +/* Compiler has the __builtin_bswap16 intrinsic */ +#cmakedefine01 HAVE_BSWAP16 + +/* Compiler has the __builtin_bswap32 intrinsic */ +#cmakedefine01 HAVE_BSWAP32 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BYTESWAP_H + +/* define if you have clock_gettime */ +#cmakedefine HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_CPUID_H + +/* Define to 1 if C++ supports variable-length arrays. */ +#cmakedefine HAVE_CXX_VARARRAYS + +/* Define to 1 if C supports variable-length arrays. */ +#cmakedefine HAVE_C_VARARRAYS + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#cmakedefine HAVE_FSEEKO + +/* Define to 1 if you have the `getopt_long' function. */ +#cmakedefine HAVE_GETOPT_LONG + +/* Define if you have the iconv() function and it works. */ +#cmakedefine HAVE_ICONV + +/* Define to 1 if you have the header file. */ +#cmakedefine01 HAVE_INTTYPES_H + +/* Define if you have and nl_langinfo(CODESET). */ +#cmakedefine HAVE_LANGINFO_CODESET + +/* lround support */ +#cmakedefine01 HAVE_LROUND + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if the system has the type `socklen_t'. */ +#cmakedefine HAVE_SOCKLEN_T + +/* Define to 1 if you have the header file. */ +#cmakedefine01 HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TERMIOS_H + +/* Define to 1 if typeof works with your compiler. */ +#cmakedefine HAVE_TYPEOF + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_X86INTRIN_H + +/* Define as const if the declaration of iconv() needs const. */ +#cmakedefine ICONV_CONST + +/* Define if debugging is disabled */ +#cmakedefine NDEBUG + +/* Name of package */ +#cmakedefine PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "@PROJECT_VERSION@" + +/* The size of `off_t', as computed by sizeof. */ +#cmakedefine SIZEOF_OFF_T + +/* The size of `void*', as computed by sizeof. */ +#cmakedefine SIZEOF_VOIDP + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +#define _ALL_SOURCE +#endif + +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#ifndef _FORTIFY_SOURCE +#cmakedefine DODEFINE_FORTIFY_SOURCE 2 +#define _FORTIFY_SOURCE DODEFINE_FORTIFY_SOURCE +#endif + +#ifndef _XOPEN_SOURCE +#cmakedefine DODEFINE_XOPEN_SOURCE 500 +#define _XOPEN_SOURCE DODEFINE_XOPEN_SOURCE +#endif + +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +#cmakedefine _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +#cmakedefine _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +#cmakedefine DODEFINE_EXTENSIONS +#define __EXTENSIONS__ DODEFINE_EXTENSIONS +#endif + + +/* Version number of package */ +#cmakedefine VERSION + +/* Target processor is big endian. */ +#define WORDS_BIGENDIAN CPU_IS_BIG_ENDIAN + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#cmakedefine _FILE_OFFSET_BITS + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#cmakedefine _LARGEFILE_SOURCE + +/* Define for large files, on AIX-style hosts. */ +#cmakedefine _LARGE_FILES + +/* Define to 1 if on MINIX. */ +#cmakedefine _MINIX + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#cmakedefine _POSIX_1_SOURCE + +/* 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/doc/CMakeLists.txt b/doc/CMakeLists.txt index a4e38ef9..66fa843e 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 3.1) find_package(Doxygen) if (NOT DOXYGEN_FOUND) diff --git a/microbench/CMakeLists.txt b/microbench/CMakeLists.txt index 64042059..c43814fd 100644 --- a/microbench/CMakeLists.txt +++ b/microbench/CMakeLists.txt @@ -5,9 +5,9 @@ endif() set(CMAKE_REQUIRED_LIBRARIES rt) check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) -add_compile_definitions( - $<$:HAVE_CLOCK_GETTIME> - $<$:FLAC__SYS_DARWIN>) +if(APPLE) + add_definitions(-DFLAC__SYS_DARWIN) +endif() add_executable(benchmark_residual benchmark_residual.c util.c) target_include_directories(benchmark_residual PRIVATE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6577467..da556d89 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,9 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.0) 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_H) - -add_compile_definitions( - ENABLE_64_BIT_WORDS=$ - FLAC__HAS_OGG=$ - WORDS_BIGENDIAN=$ - $<$:HAVE_ICONV> - $<$:HAVE_SYS_PARAM_H>) +check_include_file("iconv.h" HAVE_ICONV) add_subdirectory("libFLAC") if(BUILD_CXXLIBS) diff --git a/src/flac/CMakeLists.txt b/src/flac/CMakeLists.txt index 3fb2e2f7..6275aca2 100644 --- a/src/flac/CMakeLists.txt +++ b/src/flac/CMakeLists.txt @@ -1,12 +1,6 @@ -cmake_minimum_required(VERSION 3.12) - check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) check_include_file("termios.h" HAVE_TERMIOS_H) -add_compile_definitions( - $<$:HAVE_SYS_IOCTL_H> - $<$:HAVE_TERMIOS_H>) - add_executable(flac analyze.c decode.c diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt index e73ffcb1..71c9629b 100644 --- a/src/libFLAC++/CMakeLists.txt +++ b/src/libFLAC++/CMakeLists.txt @@ -18,8 +18,6 @@ check_cxx_source_compiles(" #endif" HAVE_CXX_VARARRAYS) -add_compile_definitions($<$:HAVE_CXX_VARARRAYS>) - set(SOURCES metadata.cpp stream_decoder.cpp diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt index 17d940bd..b6d59ae3 100644 --- a/src/libFLAC/CMakeLists.txt +++ b/src/libFLAC/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.0) if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86(_64)?|(AMD|amd)64|i[346]86") option(WITH_AVX "Enable AVX, AVX2 optimizations" ON) @@ -12,36 +12,25 @@ check_include_file("sys/param.h" HAVE_SYS_PARAM_H) set(CMAKE_REQUIRED_LIBRARIES m) check_function_exists(lround HAVE_LROUND) -add_compile_definitions( - $<$:_USE_MATH_DEFINES> - FLAC__USE_AVX=$ - HAVE_LROUND=$ - $<$:HAVE_CPUID_H> - $<$,$>:FLAC__OVERFLOW_DETECT>) - if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86_64|(AMD|amd)64") if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(IA32 TRUE) endif() - add_compile_definitions( - FLAC__CPU_X86_64 - FLAC__ALIGN_MALLOC_DATA) + add_definitions(-DFLAC__CPU_X86_64 -DFLAC__ALIGN_MALLOC_DATA) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "([xX]|i[346])86") set(IA32 TRUE) - add_compile_definitions( - FLAC__CPU_IA32 - FLAC__ALIGN_MALLOC_DATA) + add_definitions(-DFLAC__CPU_IA32 -DFLAC__ALIGN_MALLOC_DATA) endif() include(CheckLanguage) check_language(ASM_NASM) if(CMAKE_ASM_NASM_COMPILER) enable_language(ASM_NASM) - add_compile_definitions(FLAC__HAS_NASM) + add_definitions(-DFLAC__HAS_NASM) endif() if(NOT WITH_ASM) - add_compile_definitions(FLAC__NO_ASM) + add_definitions(-DFLAC__NO_ASM) endif() if(IA32) @@ -106,10 +95,13 @@ target_compile_definitions(FLAC-static PUBLIC FLAC__NO_DLL) target_include_directories(FLAC-static INTERFACE "$" "$") -target_link_libraries(FLAC-static PUBLIC - $ - $ - $<$:m>) +target_link_libraries(FLAC-static PUBLIC $<$:m>) +if(TARGET FLAC-asm) + target_link_libraries(FLAC-static PUBLIC FLAC-asm>) +endif() +if(TARGET win_utf8_io) + target_link_libraries(FLAC-static PUBLIC win_utf8_io>) +endif() if(TARGET Ogg::Ogg-static) target_link_libraries(FLAC-static PUBLIC Ogg::Ogg-static) elseif(TARGET Ogg::Ogg) @@ -121,11 +113,16 @@ target_compile_definitions(FLAC PRIVATE FLAC_API_EXPORTS FLAC__USE_VISIBILITY_AT target_include_directories(FLAC INTERFACE "$" "$") -target_link_libraries(FLAC PRIVATE - $ - $ - $ - $<$:m>) +target_link_libraries(FLAC PRIVATE $<$:m>) +if(TARGET FLAC-asm) + target_link_libraries(FLAC PUBLIC FLAC-asm>) +endif() +if(TARGET win_utf8_io) + target_link_libraries(FLAC PUBLIC win_utf8_io>) +endif() +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 diff --git a/src/share/getopt/CMakeLists.txt b/src/share/getopt/CMakeLists.txt index a247336c..1e5f5162 100644 --- a/src/share/getopt/CMakeLists.txt +++ b/src/share/getopt/CMakeLists.txt @@ -1,12 +1,4 @@ -cmake_minimum_required(VERSION 3.12) - check_include_file("libintl.h" HAVE_LIBINTL_H) check_include_file("string.h" HAVE_STRING_H) -add_compile_definitions( - $<$:HAVE_LIBINTL_H> - $<$:HAVE_STRING_H>) - -add_library(getopt STATIC - getopt.c - getopt1.c) +add_library(getopt STATIC getopt.c getopt1.c)