-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
172 lines (149 loc) · 5.57 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # -std=c++11 instead of -std=gnu++11
function(SimdOption _varName _defaultValue _featureName)
set(FAR_SIMD_${_varName} ${_defaultValue} CACHE STRING "Configure support for ${_featureName}. Valid values are 'Disabled' to compile out support, 'RuntimeCheckEnabled' to use CPUID to dymically check support at runtime, and 'CompileTimeAssumed' to assume support at compile time.")
set_property(CACHE FAR_SIMD_${_varName} PROPERTY STRINGS Disabled RuntimeCheckEnabled CompileTimeAssumed)
set(VAL ${FAR_SIMD_${_varName}})
if ("${VAL}" STREQUAL "RuntimeCheckEnabled")
set(FAR_ENABLE_${_varName} 1 PARENT_SCOPE)
elseif ("${VAL}" STREQUAL "CompileTimeAssumed")
set(FAR_ENABLE_${_varName} 1 PARENT_SCOPE)
set(FAR_ASSUME_${_varName} 1 PARENT_SCOPE)
endif()
endfunction()
function(LanguageOption)
set(FAR_LANG "C" CACHE STRING "Library language")
set_property(CACHE FAR_LANG PROPERTY STRINGS "C" "C++")
if ("${FAR_LANG}" STREQUAL "C++")
set(FAR_LANG_CPP 1 PARENT_SCOPE)
else()
set(FAR_LANG_C 1 PARENT_SCOPE)
endif()
endfunction()
#---------------------------------------------------------------------
#
# Project
#
project(libfar)
# Version
set(FAR_MAJOR_VERSION 0)
set(FAR_MINOR_VERSION 1)
set(FAR_PATCH_VERSION 0)
set(FAR_EXTRA_VERSION "" CACHE STRING "Extra version string")
set(FAR_VERSION "${FAR_MAJOR_VERSION}.${FAR_MINOR_VERSION}")
set(FAR_VERSION "${FAR_VERSION}.${FAR_PATCH_VERSION}${FAR_EXTRA_VERSION}")
# SIMD options
SimdOption(SSE CompileTimeAssumed "SSE")
SimdOption(SSE2 CompileTimeAssumed "SSE2")
SimdOption(SSE3 RuntimeCheckEnabled "SSE3")
SimdOption(SSSE3 RuntimeCheckEnabled "SSSE3")
SimdOption(SSE41 RuntimeCheckEnabled "SSE4.1")
SimdOption(SSE42 RuntimeCheckEnabled "SSE4.2")
SimdOption(AVX RuntimeCheckEnabled "AVX")
SimdOption(AVX2 RuntimeCheckEnabled "AVX2")
LanguageOption()
# Library language
if (FAR_LANG_C)
message(STATUS "Compiling libfar as a C library.")
if (MSVC)
set(FAR_CXXFLAGS "${FAR_CXXFLAGS} /TC")
else()
set(FAR_CXXFLAGS "${FAR_CXXFLAGS} -x c")
endif()
elseif (FAR_LANG_CPP)
message(STATUS "Compiling libfar as a C++ library.")
if (MSVC)
set(FAR_CXXFLAGS "${FAR_CXXFLAGS} /TP")
else()
set(FAR_CXXFLAGS "${FAR_CXXFLAGS} -x c++")
endif()
endif()
# Platform
if ( APPLE )
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
set( FAR_MACOSX TRUE )
set( FAR_PLATFORM "MacOSX" )
set( FAR_EXTRA_VERSION "-osx64" CACHE STRING "Extra version string" FORCE )
endif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
elseif ( WIN32 OR CYGWIN OR MINGW OR MSYS )
set( FAR_WINDOWS TRUE )
set( FAR_PLATFORM "Windows" )
set( FAR_EXTRA_VERSION "-win64" CACHE STRING "Extra extra version string" FORCE )
elseif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
set( FAR_LINUX TRUE )
set( FAR_PLATFORM "Linux" )
set( FAR_EXTRA_VERSION "-linux64" CACHE STRING "Extra extra version string" FORCE )
endif ( APPLE )
message( STATUS "Platform: ${FAR_PLATFORM}" )
message( STATUS "Extra version: ${FAR_EXTRA_VERSION}" )
# Use solution directories in Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Remove ZERO_CHECK project from Visual Studio solution
set(CMAKE_SUPPRESS_REGENERATION TRUE)
# Replace the Debug and Release of Cmake by our own configs.
include(tools/build/buildconfig.cmake)
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /GF /permissive-")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /GF /permissive-")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oi /Oy /Gy")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /Oy /Gy")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Both Clang and Apple-Clang
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -msse4.1")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -msse4.1")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto=thin")
endif()
set(libfar_source_files
src/adapt.c
src/cpuid.c
src/resample.c
src/fpu/adapt_fpu.c
src/fpu/resample_fpu.c
src/sse41/adapt_sse41.c
src/sse41/resample_sse41.c
)
add_library(libfar STATIC
${libfar_source_files}
"include/libfar.h"
"include/libfar/libfar_config.h"
"include/libfar/libfar_version.h"
"include/libfar/adapt.h"
"include/libfar/cpuid.h"
"include/libfar/resample.h"
"include/libfar/fpu/adapt_fpu.h"
"include/libfar/fpu/resample_fpu.h"
"include/libfar/sse41/adapt_sse41.h"
"include/libfar/sse41/resample_sse41.h"
)
# Source files have the .c extension, which defaults to C code.
# When compiling the library as C++, force the language.
if (FAR_LANG_CPP)
set_source_files_properties(
${libfar_source_files}
PROPERTIES LANGUAGE CXX
)
endif()
target_include_directories(libfar
PUBLIC
include
PRIVATE
${CMAKE_BINARY_DIR}
)
# Configure
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libfar_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/libfar/libfar_config.h )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libfar_version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/libfar/libfar_version.h)
#---------------------------------------------------------------------
#
# Testing
#
include(GoogleTest)
add_executable(libfar_tests
"test/test_adapt.cpp"
"test/test_memory.cpp"
"test/test_resample.cpp"
"test/pch.h"
)
gtest_add_tests(TARGET libfar_tests)