Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tim-Philipp Müller
Opus
Commits
c350cec9
Verified
Commit
c350cec9
authored
Apr 27, 2020
by
Marcus Asteborg
Committed by
Mark Harris
Jun 13, 2020
Browse files
cmake - move all compiler feature detection to OpusConfig
Signed-off-by:
Mark Harris
<
mark.hsj@gmail.com
>
parent
d00d866e
Changes
3
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
c350cec9
...
...
@@ -20,7 +20,6 @@ project(Opus LANGUAGES C VERSION ${PROJECT_VERSION})
include
(
OpusBuildtype
)
option
(
OPUS_BUILD_SHARED_LIBRARY
"Build shared library"
OFF
)
option
(
OPUS_STACK_PROTECTOR
"Use stack protection"
ON
)
option
(
OPUS_CUSTOM_MODES
"Enable non-Opus modes, e.g. 44.1 kHz & 2^n frames"
OFF
)
option
(
OPUS_BUILD_PROGRAMS
"Build programs"
OFF
)
...
...
@@ -66,16 +65,14 @@ cmake_dependent_option(OPUS_NONTHREADSAFE_PSEUDOSTACK
cmake_dependent_option
(
OPUS_FAST_MATH
"Enable fast math"
ON
"OPUS_FLOAT_APPROX; OPUS_FAST_MATH"
"OPUS_FLOAT_APPROX; OPUS_FAST_MATH
; FAST_MATH_SUPPORTED
"
OFF
)
if
(
OPUS_FAST_MATH
)
if
(
MSVC
)
check_and_set_flag
(
FAST_MATH /fp:fast
)
else
()
check_and_set_flag
(
FAST_MATH -ffast-math
)
endif
()
endif
()
cmake_dependent_option
(
OPUS_STACK_PROTECTOR
"Use stack protection"
ON
"STACK_PROTECTOR_SUPPORTED"
OFF
)
if
(
OPUS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS OR OPUS_BUILD_FRAMEWORK
)
# Global flag to cause add_library() to create shared libraries if on.
...
...
@@ -88,23 +85,6 @@ if(OPUS_BUILD_TESTING OR BUILD_TESTING)
set
(
BUILD_TESTING ON
)
endif
()
if
(
OPUS_STACK_PROTECTOR
)
if
(
MSVC
)
# GC on by default on MSVC
check_and_set_flag
(
STACK_PROTECTOR /GS
)
else
()
check_and_set_flag
(
STACK_PROTECTOR -fstack-protector-strong
)
endif
()
else
()
if
(
MSVC
)
check_and_set_flag
(
STACK_PROTECTOR_DISABLED /GS-
)
if
(
STACK_PROTECTOR_DISABLED_SUPPORTED
)
set
(
STACK_PROTECTOR_SUPPORTED OFF
)
endif
()
else
()
set
(
STACK_PROTECTOR_SUPPORTED OFF
)
endif
()
endif
()
if
(
OPUS_CPU_X86 OR OPUS_CPU_X64
)
cmake_dependent_option
(
OPUS_X86_MAY_HAVE_SSE
"Does runtime check for SSE1 support"
...
...
@@ -175,7 +155,7 @@ set_package_properties(Git
"required to set up package version"
)
add_feature_info
(
OPUS_BUILD_SHARED_LIBRARY OPUS_BUILD_SHARED_LIBRARY
"Build shared library"
)
add_feature_info
(
OPUS_STACK_PROTECTOR STACK_PROTECTOR
_SUPPORTED
"Use stack protection"
)
add_feature_info
(
OPUS_STACK_PROTECTOR
OPUS_
STACK_PROTECTOR
"Use stack protection"
)
add_feature_info
(
OPUS_VAR_ARRAYS OPUS_VAR_ARRAYS
"Use variable length arrays for stack arrays"
)
add_feature_info
(
OPUS_USE_ALLOCA OPUS_USE_ALLOCA
...
...
@@ -194,7 +174,7 @@ add_feature_info(
"compile with the floating point API (for machines with float library)"
)
add_feature_info
(
OPUS_FLOAT_APPROX OPUS_FLOAT_APPROX
"Enable floating point approximations (Ensure your platform supports IEEE 754 before enabling)"
)
add_feature_info
(
OPUS_FAST_MATH FAST_MATH
_SUPPORTED
"Enable fast math, (depending on OPUS_FLOAT_APPROX to be enabled)"
)
add_feature_info
(
OPUS_FAST_MATH
OPUS_
FAST_MATH
"Enable fast math, (depending on OPUS_FLOAT_APPROX to be enabled)"
)
add_feature_info
(
OPUS_INSTALL_PKG_CONFIG_MODULE OPUS_INSTALL_PKG_CONFIG_MODULE
"install PkgConfig module"
)
add_feature_info
(
OPUS_INSTALL_CMAKE_CONFIG_MODULE OPUS_INSTALL_CMAKE_CONFIG_MODULE
...
...
@@ -279,15 +259,29 @@ if(OPUS_CUSTOM_MODES)
target_compile_definitions
(
opus PRIVATE CUSTOM_MODES
)
endif
()
if
(
OPUS_FAST_MATH
)
if
(
MSVC
)
target_compile_options
(
opus PRIVATE /fp:fast
)
else
()
target_compile_options
(
opus PRIVATE -ffast-math
)
endif
()
endif
()
if
(
OPUS_STACK_PROTECTOR
)
if
(
MSVC
)
target_compile_options
(
opus PRIVATE /GS
)
else
()
target_compile_options
(
opus PRIVATE -fstack-protector-strong
)
endif
()
elseif
(
STACK_PROTECTOR_DISABLED_SUPPORTED
)
target_compile_options
(
opus PRIVATE /GS-
)
endif
()
if
(
BUILD_SHARED_LIBS
)
if
(
WIN32
)
target_compile_definitions
(
opus PRIVATE DLL_EXPORT
)
else
()
include
(
CheckCCompilerFlag
)
check_c_compiler_flag
(
-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY
)
if
(
COMPILER_HAS_HIDDEN_VISIBILITY
)
set_target_properties
(
opus PROPERTIES C_VISIBILITY_PRESET hidden
)
endif
()
elseif
(
HIDDEN_VISIBILITY_SUPPORTED
)
set_target_properties
(
opus PROPERTIES C_VISIBILITY_PRESET hidden
)
endif
()
endif
()
...
...
@@ -408,7 +402,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
endif
()
if
(
COMPILER_SUPPORT_NEON AND OPUS_USE_NEON
)
if
(
OPUS_MAY_HAVE_NEON
)
if
(
RUNTIME_CPU_CAPABILITY_DETECTION
)
message
(
STATUS
"OPUS_MAY_HAVE_NEON enabling runtime detection"
)
...
...
cmake/OpusConfig.cmake
View file @
c350cec9
...
...
@@ -66,3 +66,13 @@ elseif(OPUS_CPU_ARM)
endif
()
endif
()
endif
()
if
(
MSVC
)
check_flag
(
FAST_MATH /fp:fast
)
check_flag
(
STACK_PROTECTOR /GS
)
check_flag
(
STACK_PROTECTOR_DISABLED /GS-
)
else
()
check_flag
(
FAST_MATH -ffast-math
)
check_flag
(
STACK_PROTECTOR -fstack-protector-strong
)
check_flag
(
HIDDEN_VISIBILITY -fvisibility=hidden
)
endif
()
cmake/OpusFunctions.cmake
View file @
c350cec9
...
...
@@ -92,14 +92,6 @@ function(get_package_version PACKAGE_VERSION)
set
(
PACKAGE_VERSION 0 PARENT_SCOPE
)
endfunction
()
function
(
check_and_set_flag NAME FLAG
)
include
(
CheckCCompilerFlag
)
check_c_compiler_flag
(
${
FLAG
}
${
NAME
}
_SUPPORTED
)
if
(
${
NAME
}
_SUPPORTED
)
add_definitions
(
${
FLAG
}
)
endif
()
endfunction
()
function
(
check_flag NAME FLAG
)
include
(
CheckCCompilerFlag
)
check_c_compiler_flag
(
${
FLAG
}
${
NAME
}
_SUPPORTED
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment