2019-04-25 17:14:28 +03:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
2019-03-31 23:04:45 +03:00
|
|
|
|
2019-04-25 17:14:28 +03:00
|
|
|
project(FLAC VERSION 1.3.2) # HOMEPAGE_URL "https://www.xiph.org/flac/")
|
2019-03-31 23:04:45 +03:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
|
|
|
option(BUILD_CXXLIBS "Build libFLAC++" ON)
|
|
|
|
option(BUILD_EXAMPLES "Build and install examples" ON)
|
2019-04-07 12:37:56 +03:00
|
|
|
option(WITH_OGG "ogg support (default: test for libogg)" ON)
|
|
|
|
|
|
|
|
if(WITH_OGG)
|
|
|
|
find_package(OGG REQUIRED)
|
|
|
|
endif()
|
2019-03-31 23:04:45 +03:00
|
|
|
|
|
|
|
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")
|
2019-04-29 12:48:24 +03:00
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -funroll-loops")
|
2019-03-31 23:04:45 +03:00
|
|
|
|
|
|
|
option(ENABLE_SSP "Enable GNU GCC stack smash protection" OFF)
|
|
|
|
endif()
|
2019-04-07 12:37:56 +03:00
|
|
|
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()
|
2019-03-31 23:04:45 +03:00
|
|
|
|
|
|
|
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)
|
2019-04-25 17:14:28 +03:00
|
|
|
check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN)
|
2019-03-31 23:04:45 +03:00
|
|
|
|
2019-04-25 10:28:56 +03:00
|
|
|
check_function_exists(fseeko HAVE_FSEEKO)
|
|
|
|
|
2019-03-31 23:04:45 +03:00
|
|
|
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_options(
|
|
|
|
$<$<BOOL:${MSVC}>:/wd4267>
|
|
|
|
$<$<BOOL:${MSVC}>:/wd4996>
|
|
|
|
$<$<BOOL:${ENABLE_WERROR}>:-Werror>
|
|
|
|
$<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:-fstack-protector>
|
|
|
|
$<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:--param>
|
2019-04-09 13:21:07 +03:00
|
|
|
$<$<AND:$<BOOL:${HAVE_SSP_FLAG}>,$<BOOL:${ENABLE_SSP}>>:ssp-buffer-size=4>
|
2019-04-12 23:11:06 +03:00
|
|
|
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${HAVE_WEFFCXX_FLAG}>>:-Weffc++>
|
|
|
|
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>)
|
2019-03-31 23:04:45 +03:00
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG)
|
|
|
|
add_compile_options(-mstackrealign)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include_directories("include")
|
|
|
|
|
2019-04-25 17:14:28 +03:00
|
|
|
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()
|
|
|
|
|
2019-03-31 23:04:45 +03:00
|
|
|
add_subdirectory("doc")
|
|
|
|
add_subdirectory("src")
|
|
|
|
add_subdirectory("microbench")
|
|
|
|
if(BUILD_EXAMPLES)
|
|
|
|
add_subdirectory("examples")
|
|
|
|
endif()
|
2019-04-08 07:36:05 +03:00
|
|
|
if(BUILD_TESTING)
|
|
|
|
add_subdirectory("test")
|
2019-03-31 23:04:45 +03:00
|
|
|
endif()
|
|
|
|
|
2019-04-25 17:14:28 +03:00
|
|
|
configure_file(config.cmake.h.in config.h)
|
|
|
|
|
2019-03-31 23:04:45 +03:00
|
|
|
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"
|
2019-04-07 12:37:56 +03:00
|
|
|
"cmake/FindOGG.cmake"
|
2019-03-31 23:04:45 +03:00
|
|
|
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
|
|
|
|
|
|
|
|
file(GLOB FLAC_HEADERS "include/FLAC/*.h")
|
2019-04-14 11:17:08 +03:00
|
|
|
file(GLOB FLAC++_HEADERS "include/FLAC++/*.h")
|
2019-03-31 23:04:45 +03:00
|
|
|
install(FILES ${FLAC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC")
|
2019-04-14 11:17:08 +03:00
|
|
|
install(FILES ${FLAC++_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/FLAC++")
|
2019-03-31 23:04:45 +03:00
|
|
|
install(FILES "man/flac.1" "man/metaflac.1" DESTINATION "${CMAKE_INSTALL_MANDIR}")
|