blob: c83dd83e01f3d34d966e7d7438968b5e7e3f0577 [file] [log] [blame]
sezerocdcf0d52019-11-14 01:10:02 +03001# 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()
5cmake_minimum_required(VERSION 3.5)
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +03006
Vitaliy Kirsanov26cbd972019-04-30 14:46:12 +03007if(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 Kirsanov1794b0c2019-04-30 13:20:23 +03009endif()
10
Ralph Giles88ddb5b2019-08-15 08:53:09 -070011project(FLAC VERSION 1.3.3) # HOMEPAGE_URL "https://www.xiph.org/flac/")
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030012
13list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
14
15option(BUILD_CXXLIBS "Build libFLAC++" ON)
evpobracadefd2019-05-29 16:17:53 +050016option(BUILD_PROGRAMS "Build and install programs" ON)
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030017option(BUILD_EXAMPLES "Build and install examples" ON)
sezerocdcf0d52019-11-14 01:10:02 +030018option(BUILD_DOCS "Build and install doxygen documents" ON)
NotTsunamif706f282019-11-19 16:28:22 -050019option(WITH_STACK_PROTECTOR "Enable GNU GCC stack smash protection" ON)
evpobracadefd2019-05-29 16:17:53 +050020option(INSTALL_MANPAGES "Install MAN pages" ON)
21option(INSTALL_PKGCONFIG_MODULES "Install PkgConfig modules" ON)
22option(INSTALL_CMAKE_CONFIG_MODULE "Install CMake package-config module" ON)
Vitaliy Kirsanov6cd2b6c2019-04-07 12:37:56 +030023option(WITH_OGG "ogg support (default: test for libogg)" ON)
24
25if(WITH_OGG)
evpobre0b62a62020-05-02 10:54:28 +050026 find_package(Ogg REQUIRED)
Vitaliy Kirsanov6cd2b6c2019-04-07 12:37:56 +030027endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030028
Vitaliy Kirsanov0dfe2352019-12-21 12:41:53 +030029find_package(Iconv)
30set(HAVE_ICONV ${Iconv_FOUND})
31
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030032if(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 Kirsanov573dbc12019-04-29 12:48:24 +030034 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops")
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030035endif()
Vitaliy Kirsanov6cd2b6c2019-04-07 12:37:56 +030036if(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")
38endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030039
40include(CMakePackageConfigHelpers)
41include(CPack)
42include(CTest)
43include(CheckCCompilerFlag)
44include(CheckCXXCompilerFlag)
45include(CheckSymbolExists)
46include(CheckFunctionExists)
47include(CheckIncludeFile)
48include(CheckCSourceCompiles)
49include(CheckCXXSourceCompiles)
50include(GNUInstallDirs)
51include(UseSystemExtensions)
52include(TestBigEndian)
53
54check_include_file("byteswap.h" HAVE_BYTESWAP_H)
55check_include_file("inttypes.h" HAVE_INTTYPES_H)
56check_include_file("stdint.h" HAVE_STDINT_H)
evpobre0b62a62020-05-02 10:54:28 +050057if(MSVC)
58 check_include_file("intrin.h" FLAC__HAS_X86INTRIN)
59else()
60 check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN)
61endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030062
evpobrd38b8672019-04-25 12:28:56 +050063check_function_exists(fseeko HAVE_FSEEKO)
64
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030065check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16)
66check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32)
67
68test_big_endian(CPU_IS_BIG_ENDIAN)
69
70check_c_compiler_flag(-Werror HAVE_WERROR_FLAG)
71check_c_compiler_flag(-Wdeclaration-after-statement HAVE_DECL_AFTER_STMT_FLAG)
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030072check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG)
73check_cxx_compiler_flag(-Weffc++ HAVE_WEFFCXX_FLAG)
74
NotTsunamif706f282019-11-19 16:28:22 -050075if(WITH_STACK_PROTECTOR)
76 if(NOT MSVC)
77 check_c_compiler_flag("-fstack-protector-strong" HAVE_STACK_PROTECTOR_FLAG)
78 endif()
79endif()
80
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030081if(HAVE_WERROR_FLAG)
82 option(ENABLE_WERROR "Enable -Werror in all Makefiles" OFF)
83endif()
84
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030085add_compile_options(
86 $<$<BOOL:${MSVC}>:/wd4267>
87 $<$<BOOL:${MSVC}>:/wd4996>
88 $<$<BOOL:${ENABLE_WERROR}>:-Werror>
Vitaly Kirsanov8610c3a2019-04-12 23:11:06 +030089 $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${HAVE_WEFFCXX_FLAG}>>:-Weffc++>
90 $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>)
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030091
NotTsunamif706f282019-11-19 16:28:22 -050092if(HAVE_STACK_PROTECTOR_FLAG)
93 add_compile_options(-fstack-protector-strong)
94endif()
95
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +030096if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG)
97 add_compile_options(-mstackrealign)
98endif()
99
100include_directories("include")
101
Vitaly Kirsanova82a0142019-04-25 14:14:28 +0000102include_directories("${CMAKE_CURRENT_BINARY_DIR}")
103add_definitions(-DHAVE_CONFIG_H)
104
105if(MSVC)
106 add_definitions(
107 -D_CRT_SECURE_NO_WARNINGS
108 -D_USE_MATH_DEFINES)
109endif()
110if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
111 add_definitions(-DFLAC__OVERFLOW_DETECT)
112endif()
113
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300114add_subdirectory("src")
115add_subdirectory("microbench")
sezerocdcf0d52019-11-14 01:10:02 +0300116if(BUILD_DOCS)
117 add_subdirectory("doc")
118endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300119if(BUILD_EXAMPLES)
120 add_subdirectory("examples")
121endif()
Vitaliy Kirsanov5435f152019-04-08 07:36:05 +0300122if(BUILD_TESTING)
123 add_subdirectory("test")
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300124endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300125
Vitaly Kirsanova82a0142019-04-25 14:14:28 +0000126configure_file(config.cmake.h.in config.h)
127
evpobracadefd2019-05-29 16:17:53 +0500128if(INSTALL_CMAKE_CONFIG_MODULE)
129 install(
130 EXPORT targets
131 DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
132 NAMESPACE FLAC::)
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300133
evpobracadefd2019-05-29 16:17:53 +0500134 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 Kirsanovc39718d2019-03-31 23:04:45 +0300139
evpobracadefd2019-05-29 16:17:53 +0500140 install(
141 FILES
142 "${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake"
143 "${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake"
evpobracadefd2019-05-29 16:17:53 +0500144 DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
145endif()
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300146
147file(GLOB FLAC_HEADERS "include/FLAC/*.h")
Vitaliy Kirsanov23595632019-04-14 11:17:08 +0300148file(GLOB FLAC++_HEADERS "include/FLAC++/*.h")
Vitaliy Kirsanovc39718d2019-03-31 23:04:45 +0300149install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC")
Vitaliy Kirsanov23595632019-04-14 11:17:08 +0300150install(FILES ${FLAC++_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++")
evpobracadefd2019-05-29 16:17:53 +0500151if(INSTALL_MANPAGES)
152 install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}")
153endif()