-
Notifications
You must be signed in to change notification settings - Fork 17
/
CMakeLists.txt
103 lines (91 loc) · 3.35 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
cmake_minimum_required (VERSION 3.1)
if(POLICY CMP0056) # added in CMake 3.2
cmake_policy(SET CMP0056 NEW)
endif()
project (xvc CXX C)
include(GNUInstallDirs)
find_package(Threads REQUIRED)
# Project options
option(HIGH_BITDEPTH "Store pixel samples as 16bit values." ON)
option(BUILD_SHARED_LIBS "Build shared instead of static libraries." OFF)
option(BUILD_APPS "Build sample console applications" ON)
option(BUILD_TESTS "Build all test code" ON)
option(BUILD_TESTS_LIBS "Build all test code as library" OFF)
option(ENABLE_ASSEMBLY "Compile with assembly coded functions" ON)
option(ENABLE_ASSERTIONS "Compile with assertions" ON)
option(CODE_ANALYZE "Compile with code analyzer (MSVC)" OFF)
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(SANITIZE_BUILD "" CACHE STRING "Compile with sanitizer enabled (GCC/clang)")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()
if(MSVC AND BUILD_TESTS AND BUILD_SHARED_LIBS)
message(WARNING "Unit-tests disabled when building shared libraries")
set(BUILD_TESTS OFF CACHE BOOL "Build all test code" FORCE)
endif()
# Target arch detection
set(XVC_HAVE_NEON FALSE)
if(NOT XVC_TARGET_ARCH)
# Determine arch based on host cpu and generator used
if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio .+ ARM$")
set(XVC_TARGET_ARCH "ARM")
set(XVC_HAVE_NEON TRUE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
set(XVC_TARGET_ARCH "x86")
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64|armv7")
set(XVC_TARGET_ARCH "ARM")
set(XVC_HAVE_NEON TRUE)
else()
message(FATAL_ERROR "Unexpected host cpu: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
else()
# Extract architecture family from user specified arch
if("${XVC_TARGET_ARCH}" STREQUAL "x86_64")
set(XVC_TARGET_ARCH "x86")
elseif("${XVC_TARGET_ARCH}" MATCHES "^arm")
if ("${XVC_TARGET_ARCH}" MATCHES "^arm64")
set(XVC_HAVE_NEON TRUE)
elseif ("${XVC_TARGET_ARCH}" MATCHES "^armv7|^arm.*-v7")
set(XVC_HAVE_NEON TRUE)
endif()
set(XVC_TARGET_ARCH "ARM")
elseif("${XVC_TARGET_ARCH}" MATCHES "^mips")
set(XVC_TARGET_ARCH "MIPS")
endif()
endif()
if(NOT "${XVC_TARGET_ARCH}" MATCHES "^(x86|ARM|MIPS)$")
message(FATAL_ERROR "Unexpected target architecture: ${XVC_TARGET_ARCH}")
endif()
if(HIGH_BITDEPTH)
add_definitions(-DXVC_HIGH_BITDEPTH=1)
else()
add_definitions(-DXVC_HIGH_BITDEPTH=0)
endif()
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_subdirectory(src)
if(BUILD_APPS)
add_subdirectory(app)
endif()
if(BUILD_TESTS OR BUILD_TESTS_LIBS)
enable_testing()
add_subdirectory(test)
endif()
# pkg-config support
set(PKG_CONFIG_LINK_LIBS "")
foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
set(PKG_CONFIG_LINK_LIBS "${PKG_CONFIG_LINK_LIBS} ${LIB}")
else()
set(PKG_CONFIG_LINK_LIBS "${PKG_CONFIG_LINK_LIBS} -l${LIB}")
endif()
endforeach()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/xvc.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/xvc.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/xvc.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")