@@ -35,6 +35,23 @@ if (CMAKE_OSX_ARCHITECTURES)
3535 unset (arm64_index)
3636endif ()
3737
38+ ## Target features
39+ # Try to detect if the given flag is defined by the compiler.
40+ include (CheckCXXSourceCompiles)
41+ function (check_compile_definition FLAG PREFIX )
42+ enable_language (CXX)
43+
44+ check_cxx_source_compiles("
45+ #ifndef ${FLAG}
46+ #error \" Flag not detected.\"
47+ #endif
48+ int main() { return 0; }
49+ "
50+ "${FLAG} _DEFINED" )
51+
52+ set ("${PREFIX}${FLAG} _DEFINED" ${${FLAG} _DEFINED} PARENT_SCOPE)
53+ endfunction ()
54+
3855## options
3956option (BUILD_SHARED_LIBS "Shared Libraries" ON )
4057option (OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files" ON )
@@ -147,6 +164,49 @@ endif()
147164if (OJPH_DISABLE_SIMD)
148165 add_compile_definitions (OJPH_DISABLE_SIMD)
149166else ()
167+ check_compile_definition(__SSE__ OJPH_)
168+ check_compile_definition(__SSE2__ OJPH_)
169+ check_compile_definition(__SSSE3__ OJPH_)
170+ check_compile_definition(__SSE4_1__ OJPH_)
171+ check_compile_definition(__AVX__ OJPH_)
172+ check_compile_definition(__AVX2__ OJPH_)
173+ check_compile_definition(__AVX512F__ OJPH_)
174+ check_compile_definition(__ARM_NEON__ OJPH_)
175+ check_compile_definition(__ARM_NEON OJPH_)
176+
177+ if (NOT DEFINED OJPH___SSE___DEFINED)
178+ message (STATUS "SSE flag not detected, disabling SSE support." )
179+ set (OJPH_DISABLE_SSE ON )
180+ endif ()
181+ if (NOT DEFINED OJPH___SSE2___DEFINED)
182+ message (STATUS "SSE2 flag not detected, disabling SSE2 support." )
183+ set (OJPH_DISABLE_SSE2 ON )
184+ endif ()
185+ if (NOT DEFINED OJPH___SSSE3___DEFINED)
186+ message (STATUS "SSSE3 flag not detected, disabling SSSE3 support." )
187+ set (OJPH_DISABLE_SSSE3 ON )
188+ endif ()
189+ if (NOT DEFINED OJPH___SSE4_1___DEFINED)
190+ message (STATUS "SSE4_1 flag not detected, disabling SSE4 support." )
191+ set (OJPH_DISABLE_SSE4 ON )
192+ endif ()
193+ if (NOT DEFINED OJPH___AVX___DEFINED)
194+ message (STATUS "AVX flag not detected, disabling AVX support." )
195+ set (OJPH_DISABLE_AVX ON )
196+ endif ()
197+ if (NOT DEFINED OJPH___AVX2___DEFINED)
198+ message (STATUS "AVX2 flag not detected, disabling AVX2 support." )
199+ set (OJPH_DISABLE_AVX2 ON )
200+ endif ()
201+ if (NOT DEFINED OJPH___AVX512F___DEFINED)
202+ message (STATUS "AVX512F flag not detected, disabling AVX512 support." )
203+ set (OJPH_DISABLE_AVX512 ON )
204+ endif ()
205+ if (NOT DEFINED OJPH___ARM_NEON___DEFINED AND NOT DEFINED OJPH___ARM_NEON_DEFINED)
206+ message (STATUS "NEON flag not detected, disabling NEON support." )
207+ set (OJPH_DISABLE_NEON ON )
208+ endif ()
209+
150210 if (OJPH_DISABLE_SSE)
151211 add_compile_definitions (OJPH_DISABLE_SSE)
152212 endif ()
0 commit comments