From c39718d7a36405114f9ed0b1a7acaef64ea88131 Mon Sep 17 00:00:00 2001 From: Vitaliy Kirsanov Date: Sun, 31 Mar 2019 23:04:45 +0300 Subject: CMake support added --- CMakeLists.txt | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 CMakeLists.txt (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a4870fe5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,123 @@ +cmake_minimum_required(VERSION 3.12) + +project(FLAC VERSION 1.3.2 HOMEPAGE_URL "https://www.xiph.org/flac/") + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +option(BUILD_CXXLIBS "Build libFLAC++" ON) +option(BUILD_EXAMPLES "Build and install examples" ON) + +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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wsign-promo -Wundef") + + 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) +endif() + +include(CMakePackageConfigHelpers) +include(CPack) +include(CTest) +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) +include(CheckSymbolExists) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) +include(GNUInstallDirs) +include(UseSystemExtensions) +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_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16) +check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32) + +test_big_endian(CPU_IS_BIG_ENDIAN) + +check_c_compiler_flag(-Werror HAVE_WERROR_FLAG) +check_c_compiler_flag(-Wdeclaration-after-statement HAVE_DECL_AFTER_STMT_FLAG) +check_c_compiler_flag("-fstack-protector --param ssp-buffer-size=4" HAVE_SSP_FLAG) +check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG) +check_cxx_compiler_flag(-Weffc++ HAVE_WEFFCXX_FLAG) + +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> + $<$:_CRT_SECURE_NO_WARNINGS> + CPU_IS_BIG_ENDIAN=$ + CPU_IS_LITTLE_ENDIAN=$> + FLAC__HAS_X86INTRIN=$ + HAVE_BSWAP16=$ + HAVE_BSWAP32=$) + +add_compile_options( + $<$:/wd4267> + $<$:/wd4996> + $<$:-Werror> + $<$,$>:-fstack-protector> + $<$,$>:--param> + $<$,$>:ssp-buffer-size=4>) + +if(HAVE_WEFFCXX_FLAG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") +endif() +if(HAVE_DECL_AFTER_STMT_FLAG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdeclaration-after-statement") +endif() + +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG) + add_compile_options(-mstackrealign) +endif() + +include_directories("include") + +add_subdirectory("doc") +add_subdirectory("src") +add_subdirectory("microbench") +if(BUILD_EXAMPLES) + add_subdirectory("examples") +endif() + +if(WIN32) + set(EXEEXT .exe) +endif() +set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}") +set(top_builddir "${CMAKE_CURRENT_BINARY_DIR}") +configure_file(test/common.sh.in test/common.sh @ONLY) + +install( + EXPORT targets + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake" + NAMESPACE FLAC::) + +configure_package_config_file( + flac-config.cmake.in flac-config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") +write_basic_package_version_file( + flac-config-version.cmake COMPATIBILITY AnyNewerVersion) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") + +file(GLOB FLAC_HEADERS "include/FLAC/*.h") +file(GLOB FLACXX_HEADERS "include/FLAC++/*.h") +install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC") +install(FILES ${FLACXX_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++") +install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}") -- cgit v1.2.1