sezero | cdcf0d5 | 2019-11-14 01:10:02 +0300 | [diff] [blame] | 1 | # 3.1 is OK for most parts. However: |
| 2 | # 3.3 is needed in src/libFLAC |
| 3 | # 3.5 is needed in src/libFLAC/ia32 |
| 4 | # 3.9 is needed in 'doc' because of doxygen_add_docs() |
| 5 | cmake_minimum_required(VERSION 3.5) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 6 | |
Vitaliy Kirsanov | 26cbd97 | 2019-04-30 14:46:12 +0300 | [diff] [blame] | 7 | if(NOT (CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES OR DEFINED ENV{CFLAGS} OR DEFINED ENV{CXXFLAGS})) |
| 8 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo") |
Vitaliy Kirsanov | 1794b0c | 2019-04-30 13:20:23 +0300 | [diff] [blame] | 9 | endif() |
| 10 | |
Ralph Giles | 88ddb5b | 2019-08-15 08:53:09 -0700 | [diff] [blame] | 11 | project(FLAC VERSION 1.3.3) # HOMEPAGE_URL "https://www.xiph.org/flac/") |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 12 | |
| 13 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 14 | |
| 15 | option(BUILD_CXXLIBS "Build libFLAC++" ON) |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 16 | option(BUILD_PROGRAMS "Build and install programs" ON) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 17 | option(BUILD_EXAMPLES "Build and install examples" ON) |
sezero | cdcf0d5 | 2019-11-14 01:10:02 +0300 | [diff] [blame] | 18 | option(BUILD_DOCS "Build and install doxygen documents" ON) |
NotTsunami | f706f28 | 2019-11-19 16:28:22 -0500 | [diff] [blame] | 19 | option(WITH_STACK_PROTECTOR "Enable GNU GCC stack smash protection" ON) |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 20 | option(INSTALL_MANPAGES "Install MAN pages" ON) |
| 21 | option(INSTALL_PKGCONFIG_MODULES "Install PkgConfig modules" ON) |
| 22 | option(INSTALL_CMAKE_CONFIG_MODULE "Install CMake package-config module" ON) |
Vitaliy Kirsanov | 6cd2b6c | 2019-04-07 12:37:56 +0300 | [diff] [blame] | 23 | option(WITH_OGG "ogg support (default: test for libogg)" ON) |
| 24 | |
| 25 | if(WITH_OGG) |
evpobr | e0b62a6 | 2020-05-02 10:54:28 +0500 | [diff] [blame^] | 26 | find_package(Ogg REQUIRED) |
Vitaliy Kirsanov | 6cd2b6c | 2019-04-07 12:37:56 +0300 | [diff] [blame] | 27 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 28 | |
Vitaliy Kirsanov | 0dfe235 | 2019-12-21 12:41:53 +0300 | [diff] [blame] | 29 | find_package(Iconv) |
| 30 | set(HAVE_ICONV ${Iconv_FOUND}) |
| 31 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 32 | if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") |
| 33 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wnested-externs -Wshadow -Wundef -Wmissing-declarations -Winline") |
Vitaliy Kirsanov | 573dbc1 | 2019-04-29 12:48:24 +0300 | [diff] [blame] | 34 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops") |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 35 | endif() |
Vitaliy Kirsanov | 6cd2b6c | 2019-04-07 12:37:56 +0300 | [diff] [blame] | 36 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") |
| 37 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wsign-promo -Wundef") |
| 38 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 39 | |
| 40 | include(CMakePackageConfigHelpers) |
| 41 | include(CPack) |
| 42 | include(CTest) |
| 43 | include(CheckCCompilerFlag) |
| 44 | include(CheckCXXCompilerFlag) |
| 45 | include(CheckSymbolExists) |
| 46 | include(CheckFunctionExists) |
| 47 | include(CheckIncludeFile) |
| 48 | include(CheckCSourceCompiles) |
| 49 | include(CheckCXXSourceCompiles) |
| 50 | include(GNUInstallDirs) |
| 51 | include(UseSystemExtensions) |
| 52 | include(TestBigEndian) |
| 53 | |
| 54 | check_include_file("byteswap.h" HAVE_BYTESWAP_H) |
| 55 | check_include_file("inttypes.h" HAVE_INTTYPES_H) |
| 56 | check_include_file("stdint.h" HAVE_STDINT_H) |
evpobr | e0b62a6 | 2020-05-02 10:54:28 +0500 | [diff] [blame^] | 57 | if(MSVC) |
| 58 | check_include_file("intrin.h" FLAC__HAS_X86INTRIN) |
| 59 | else() |
| 60 | check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN) |
| 61 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 62 | |
evpobr | d38b867 | 2019-04-25 12:28:56 +0500 | [diff] [blame] | 63 | check_function_exists(fseeko HAVE_FSEEKO) |
| 64 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 65 | check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16) |
| 66 | check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32) |
| 67 | |
| 68 | test_big_endian(CPU_IS_BIG_ENDIAN) |
| 69 | |
| 70 | check_c_compiler_flag(-Werror HAVE_WERROR_FLAG) |
| 71 | check_c_compiler_flag(-Wdeclaration-after-statement HAVE_DECL_AFTER_STMT_FLAG) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 72 | check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG) |
| 73 | check_cxx_compiler_flag(-Weffc++ HAVE_WEFFCXX_FLAG) |
| 74 | |
NotTsunami | f706f28 | 2019-11-19 16:28:22 -0500 | [diff] [blame] | 75 | if(WITH_STACK_PROTECTOR) |
| 76 | if(NOT MSVC) |
| 77 | check_c_compiler_flag("-fstack-protector-strong" HAVE_STACK_PROTECTOR_FLAG) |
| 78 | endif() |
| 79 | endif() |
| 80 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 81 | if(HAVE_WERROR_FLAG) |
| 82 | option(ENABLE_WERROR "Enable -Werror in all Makefiles" OFF) |
| 83 | endif() |
| 84 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 85 | add_compile_options( |
| 86 | $<$<BOOL:${MSVC}>:/wd4267> |
| 87 | $<$<BOOL:${MSVC}>:/wd4996> |
| 88 | $<$<BOOL:${ENABLE_WERROR}>:-Werror> |
Vitaly Kirsanov | 8610c3a | 2019-04-12 23:11:06 +0300 | [diff] [blame] | 89 | $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${HAVE_WEFFCXX_FLAG}>>:-Weffc++> |
| 90 | $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 91 | |
NotTsunami | f706f28 | 2019-11-19 16:28:22 -0500 | [diff] [blame] | 92 | if(HAVE_STACK_PROTECTOR_FLAG) |
| 93 | add_compile_options(-fstack-protector-strong) |
| 94 | endif() |
| 95 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 96 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG) |
| 97 | add_compile_options(-mstackrealign) |
| 98 | endif() |
| 99 | |
| 100 | include_directories("include") |
| 101 | |
Vitaly Kirsanov | a82a014 | 2019-04-25 14:14:28 +0000 | [diff] [blame] | 102 | include_directories("${CMAKE_CURRENT_BINARY_DIR}") |
| 103 | add_definitions(-DHAVE_CONFIG_H) |
| 104 | |
| 105 | if(MSVC) |
| 106 | add_definitions( |
| 107 | -D_CRT_SECURE_NO_WARNINGS |
| 108 | -D_USE_MATH_DEFINES) |
| 109 | endif() |
| 110 | if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) |
| 111 | add_definitions(-DFLAC__OVERFLOW_DETECT) |
| 112 | endif() |
| 113 | |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 114 | add_subdirectory("src") |
| 115 | add_subdirectory("microbench") |
sezero | cdcf0d5 | 2019-11-14 01:10:02 +0300 | [diff] [blame] | 116 | if(BUILD_DOCS) |
| 117 | add_subdirectory("doc") |
| 118 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 119 | if(BUILD_EXAMPLES) |
| 120 | add_subdirectory("examples") |
| 121 | endif() |
Vitaliy Kirsanov | 5435f15 | 2019-04-08 07:36:05 +0300 | [diff] [blame] | 122 | if(BUILD_TESTING) |
| 123 | add_subdirectory("test") |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 124 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 125 | |
Vitaly Kirsanov | a82a014 | 2019-04-25 14:14:28 +0000 | [diff] [blame] | 126 | configure_file(config.cmake.h.in config.h) |
| 127 | |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 128 | if(INSTALL_CMAKE_CONFIG_MODULE) |
| 129 | install( |
| 130 | EXPORT targets |
| 131 | DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake" |
| 132 | NAMESPACE FLAC::) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 133 | |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 134 | configure_package_config_file( |
| 135 | flac-config.cmake.in flac-config.cmake |
| 136 | INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") |
| 137 | write_basic_package_version_file( |
| 138 | flac-config-version.cmake COMPATIBILITY AnyNewerVersion) |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 139 | |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 140 | install( |
| 141 | FILES |
| 142 | "${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake" |
| 143 | "${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake" |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 144 | DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake") |
| 145 | endif() |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 146 | |
| 147 | file(GLOB FLAC_HEADERS "include/FLAC/*.h") |
Vitaliy Kirsanov | 2359563 | 2019-04-14 11:17:08 +0300 | [diff] [blame] | 148 | file(GLOB FLAC++_HEADERS "include/FLAC++/*.h") |
Vitaliy Kirsanov | c39718d | 2019-03-31 23:04:45 +0300 | [diff] [blame] | 149 | install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC") |
Vitaliy Kirsanov | 2359563 | 2019-04-14 11:17:08 +0300 | [diff] [blame] | 150 | install(FILES ${FLAC++_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++") |
evpobr | acadefd | 2019-05-29 16:17:53 +0500 | [diff] [blame] | 151 | if(INSTALL_MANPAGES) |
| 152 | install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}") |
| 153 | endif() |