CMake polishing

* Improve CPU features detection

  CMAKE_SYSTEM_PROCESSOR is pretty useless (e.g. when compiling with
  MSVC ARM64 toolchain and Ninja still returns system processor).

* Don't build src/utils targets by default

  Fix compilation for UWP platform.

* Add more Visual studio Git ignore patterns
* Autogenerate Doxygen docs
This commit is contained in:
evpobr 2020-05-08 14:20:35 +05:00 committed by Erik de Castro Lopo
parent 37e675b777
commit ce6dd6b573
7 changed files with 61 additions and 19 deletions

2
.gitignore vendored
View File

@ -79,6 +79,8 @@ oss-fuzz/fuzz-decoder
oss-fuzz/fuzz-encoder oss-fuzz/fuzz-encoder
/*[Bb]uild*/ /*[Bb]uild*/
/out/
CMakeSettings.json
CMakeLists.txt.user CMakeLists.txt.user
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles

View File

@ -43,6 +43,8 @@ EXTRA_DIST = \
flac-config.cmake.in \ flac-config.cmake.in \
cmake/FindOgg.cmake \ cmake/FindOgg.cmake \
cmake/UseSystemExtensions.cmake \ cmake/UseSystemExtensions.cmake \
cmake/CheckCPUArch.cmake \
cmake/CheckCPUArch.c.in \
COPYING.FDL \ COPYING.FDL \
COPYING.GPL \ COPYING.GPL \
COPYING.LGPL \ COPYING.LGPL \

7
cmake/CheckCPUArch.c.in Normal file
View File

@ -0,0 +1,7 @@
int main(void) {
#if @CHECK_CPU_ARCH_DEFINES@
return 0;
#else
fail
#endif
}

23
cmake/CheckCPUArch.cmake Normal file
View File

@ -0,0 +1,23 @@
macro(_CHECK_CPU_ARCH ARCH ARCH_DEFINES VARIABLE)
if(NOT DEFINED HAVE_${VARIABLE})
message(STATUS "Check CPU architecture is ${ARCH}")
set(CHECK_CPU_ARCH_DEFINES ${ARCH_DEFINES})
configure_file(${PROJECT_SOURCE_DIR}/cmake/CheckCPUArch.c.in ${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckCPUArch.c @ONLY)
try_compile(HAVE_${VARIABLE} "${PROJECT_BINARY_DIR}"
"${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckCPUArch.c")
if(HAVE_${VARIABLE})
message(STATUS "Check CPU architecture is ${ARCH} - yes")
set(${VARIABLE} 1 CACHE INTERNAL "Result of CHECK_CPU_ARCH_X64" FORCE)
else ()
message(STATUS "Check CPU architecture is ${ARCH} - no")
endif()
endif ()
endmacro(_CHECK_CPU_ARCH)
macro(CHECK_CPU_ARCH_X64 VARIABLE)
_CHECK_CPU_ARCH(x64 "defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)" ${VARIABLE})
endmacro(CHECK_CPU_ARCH_X64)
macro(CHECK_CPU_ARCH_X86 VARIABLE)
_CHECK_CPU_ARCH(x86 "defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)" ${VARIABLE})
endmacro(CHECK_CPU_ARCH_X86)

View File

@ -15,12 +15,20 @@ endif()
set(DOXYGEN_HTML_FOOTER doxygen.footer.html) set(DOXYGEN_HTML_FOOTER doxygen.footer.html)
set(DOXYGEN_GENERATE_TAGFILE FLAC.tag) set(DOXYGEN_GENERATE_TAGFILE FLAC.tag)
doxygen_add_docs(FLAC-doxygen if(CMAKE_VERSION VERSION_LESS 3.12)
"${PROJECT_SOURCE_DIR}/include/FLAC" doxygen_add_docs(FLAC-doxygen
"${PROJECT_SOURCE_DIR}/include/FLAC++") ALL
"${PROJECT_SOURCE_DIR}/include/FLAC"
"${PROJECT_SOURCE_DIR}/include/FLAC++")
else()
doxygen_add_docs(FLAC-doxygen
"${PROJECT_SOURCE_DIR}/include/FLAC"
"${PROJECT_SOURCE_DIR}/include/FLAC++")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/"
DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/api") DESTINATION "${CMAKE_INSTALL_DOCDIR}/html/api")
endif()
install(FILES install(FILES
html/images/logo.svg html/images/logo.svg

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.11)
option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF) option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
option(WITH_XMMS "Build XMMS plugin" OFF) option(WITH_XMMS "Build XMMS plugin" OFF)
option(BUILD_UTILS "Build utils" OFF)
add_subdirectory("libFLAC") add_subdirectory("libFLAC")
if(BUILD_CXXLIBS) if(BUILD_CXXLIBS)
@ -17,7 +18,7 @@ if(BUILD_PROGRAMS)
add_subdirectory("flac") add_subdirectory("flac")
add_subdirectory("metaflac") add_subdirectory("metaflac")
endif() endif()
if(BUILD_CXXLIBS) if(BUILD_UTILS)
add_subdirectory(utils/flacdiff) add_subdirectory(utils/flacdiff)
if(WIN32) if(WIN32)
add_subdirectory(utils/flactimer) add_subdirectory(utils/flactimer)

View File

@ -1,7 +1,3 @@
if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86(_64)?|(AMD|amd)64|i[346]86")
option(WITH_AVX "Enable AVX, AVX2 optimizations" ON)
endif()
option(WITH_ASM "Use any assembly optimization routines" ON) option(WITH_ASM "Use any assembly optimization routines" ON)
check_include_file("cpuid.h" HAVE_CPUID_H) check_include_file("cpuid.h" HAVE_CPUID_H)
@ -10,14 +6,17 @@ check_include_file("sys/param.h" HAVE_SYS_PARAM_H)
set(CMAKE_REQUIRED_LIBRARIES m) set(CMAKE_REQUIRED_LIBRARIES m)
check_function_exists(lround HAVE_LROUND) check_function_exists(lround HAVE_LROUND)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86_64|(AMD|amd)64") include(CheckCSourceCompiles)
if(CMAKE_SIZEOF_VOID_P EQUAL 4) include(CheckCPUArch)
set(IA32 TRUE)
endif() check_cpu_arch_x64(FLAC__CPU_X86_64)
add_definitions(-DFLAC__CPU_X86_64 -DFLAC__ALIGN_MALLOC_DATA) if(NOT FLAC__CPU_X86_64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "([xX]|i[346])86") check_cpu_arch_x86(FLAC__CPU_IA32)
set(IA32 TRUE) endif()
add_definitions(-DFLAC__CPU_IA32 -DFLAC__ALIGN_MALLOC_DATA)
if(FLAC__CPU_X86_64 OR FLAC__CPU_IA32)
set(FLAC__ALIGN_MALLOC_DATA 1)
option(WITH_AVX "Enable AVX, AVX2 optimizations" ON)
endif() endif()
include(CheckLanguage) include(CheckLanguage)
@ -31,7 +30,7 @@ if(NOT WITH_ASM)
add_definitions(-DFLAC__NO_ASM) add_definitions(-DFLAC__NO_ASM)
endif() endif()
if(IA32) if(FLAC__CPU_IA32)
if(WITH_ASM AND CMAKE_ASM_NASM_COMPILER) if(WITH_ASM AND CMAKE_ASM_NASM_COMPILER)
add_subdirectory(ia32) add_subdirectory(ia32)
endif() endif()