summaryrefslogtreecommitdiff
path: root/3rdparty/plibsys/cmake
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/plibsys/cmake')
-rw-r--r--3rdparty/plibsys/cmake/PlatformDetect.cmake144
-rw-r--r--3rdparty/plibsys/cmake/StdargDetect.cmake74
-rw-r--r--3rdparty/plibsys/cmake/ThreadNameDetect.cmake135
-rw-r--r--3rdparty/plibsys/cmake/VisibilityDetect.cmake127
4 files changed, 480 insertions, 0 deletions
diff --git a/3rdparty/plibsys/cmake/PlatformDetect.cmake b/3rdparty/plibsys/cmake/PlatformDetect.cmake
new file mode 100644
index 0000000..ab05065
--- /dev/null
+++ b/3rdparty/plibsys/cmake/PlatformDetect.cmake
@@ -0,0 +1,144 @@
+# The MIT License
+#
+# Copyright (C) 2018 Alexander Saprykin <saprykin.spb@gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# 'Software'), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function (plibsys_detect_c_compiler result)
+ # Get target system OS
+ string (TOLOWER ${CMAKE_SYSTEM_NAME} PLIBSYS_TARGET_OS)
+
+ # Detect C compiler by it's ID
+ if (CMAKE_C_COMPILER_ID STREQUAL GNU)
+ set (PLIBSYS_C_COMPILER gcc)
+ elseif (CMAKE_C_COMPILER_ID STREQUAL MSVC)
+ set (PLIBSYS_C_COMPILER msvc)
+ else()
+ string (TOLOWER ${CMAKE_C_COMPILER_ID} PLIBSYS_C_COMPILER)
+ endif()
+
+ # Fix gcc -> qcc naming on QNX 6
+ if ((PLIBSYS_TARGET_OS STREQUAL qnx) AND (PLIBSYS_C_COMPILER STREQUAL gcc))
+ set (PLIBSYS_C_COMPILER qcc)
+ endif()
+
+ # Rename intel -> icc
+ if (PLIBSYS_C_COMPILER STREQUAL intel)
+ set (PLIBSYS_C_COMPILER icc)
+ endif()
+
+ # Rename openwatcom -> watcom
+ if (PLIBSYS_C_COMPILER STREQUAL openwatcom)
+ set (PLIBSYS_C_COMPILER watcom)
+ endif()
+
+ # Rename xl -> xlc
+ if (PLIBSYS_C_COMPILER STREQUAL xl)
+ set (PLIBSYS_C_COMPILER xlc)
+ endif()
+
+ # Assign result
+ set (${result} ${PLIBSYS_C_COMPILER} PARENT_SCOPE)
+endfunction (plibsys_detect_c_compiler)
+
+function (plibsys_detect_os_bits result)
+ if (PLIBSYS_SIZEOF_VOID_P EQUAL 8)
+ set (PLIBSYS_ARCH_BITS 64)
+ elseif (PLIBSYS_SIZEOF_VOID_P EQUAL 4)
+ set (PLIBSYS_ARCH_BITS 32)
+ elseif(PLIBSYS_SIZEOF_VOID_P EQUAL 0)
+ set (PLIBSYS_ARCH_BITS "universal")
+ else()
+ set (PLIBSYS_ARCH_BITS "unknown")
+ endif()
+
+ set (${result} ${PLIBSYS_ARCH_BITS} PARENT_SCOPE)
+endfunction (plibsys_detect_os_bits)
+
+function (plibsys_detect_cpu_arch result)
+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(i[1-9]86)|(x86_64)")
+ if (CMAKE_CROSSCOMPILING)
+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "i[1-9]86")
+ set (PLIBSYS_PROCESSOR_ARCH "x86")
+ else()
+ set (PLIBSYS_PROCESSOR_ARCH "x64")
+ endif()
+ else()
+ plibsys_detect_os_bits (PLIBSYS_OS_BITS)
+ if (PLIBSYS_OS_BITS STREQUAL "32")
+ set (PLIBSYS_PROCESSOR_ARCH "x86")
+ elseif (PLIBSYS_OS_BITS STREQUAL "64")
+ set (PLIBSYS_PROCESSOR_ARCH "x64")
+ else()
+ set (PLIBSYS_PROCESSOR_ARCH "x${PLIBSYS_OS_BITS}")
+ endif()
+ endif()
+ else()
+ set (PLIBSYS_PROCESSOR_ARCH ${CMAKE_SYSTEM_PROCESSOR})
+ endif()
+
+ set (${result} ${PLIBSYS_PROCESSOR_ARCH} PARENT_SCOPE)
+endfunction (plibsys_detect_cpu_arch)
+
+function (plibsys_detect_target_os result)
+ string (TOLOWER ${CMAKE_SYSTEM_NAME} PLIBSYS_TARGET_OS)
+
+ # Rename mingw -> windows
+ if (PLIBSYS_TARGET_OS MATCHES "(mingw.*)")
+ set (PLIBSYS_TARGET_OS windows)
+ endif()
+
+ # Rename hp-ux -> hpux
+ if (PLIBSYS_TARGET_OS STREQUAL hp-ux)
+ set (PLIBSYS_TARGET_OS hpux)
+ endif()
+
+ # Rename sco_sv -> scosv
+ if (PLIBSYS_TARGET_OS STREQUAL sco_sv)
+ set (PLIBSYS_TARGET_OS scosv)
+ endif()
+
+ # Rename osf1 -> tru64
+ if (PLIBSYS_TARGET_OS STREQUAL osf1)
+ set (PLIBSYS_TARGET_OS tru64)
+ endif()
+
+ # Rename craylinuxenvironment -> linux
+ if (PLIBSYS_TARGET_OS STREQUAL craylinuxenvironment)
+ set (PLIBSYS_TARGET_OS linux)
+ endif()
+
+ set (${result} ${PLIBSYS_TARGET_OS} PARENT_SCOPE)
+endfunction (plibsys_detect_target_os)
+
+function (plibsys_detect_target_platform result)
+ plibsys_detect_target_os (PLIBSYS_TARGET_OS)
+ plibsys_detect_os_bits (PLIBSYS_OS_BITS)
+ plibsys_detect_c_compiler (PLIBSYS_C_COMPILER)
+
+ if (PLIBSYS_TARGET_OS STREQUAL windows)
+ set (PLIBSYS_TARGET_PLATFORM win${PLIBSYS_OS_BITS})
+ else()
+ set (PLIBSYS_TARGET_PLATFORM ${PLIBSYS_TARGET_OS})
+ endif()
+
+ set (PLIBSYS_TARGET_PLATFORM ${PLIBSYS_TARGET_PLATFORM}-${PLIBSYS_C_COMPILER})
+ set (${result} ${PLIBSYS_TARGET_PLATFORM} PARENT_SCOPE)
+endfunction (plibsys_detect_target_platform)
diff --git a/3rdparty/plibsys/cmake/StdargDetect.cmake b/3rdparty/plibsys/cmake/StdargDetect.cmake
new file mode 100644
index 0000000..a85f59a
--- /dev/null
+++ b/3rdparty/plibsys/cmake/StdargDetect.cmake
@@ -0,0 +1,74 @@
+# The MIT License
+#
+# Copyright (C) 2017 Jean-Damien Durand <jeandamiendurand@gmail.com>
+# Copyright (C) 2019 Alexander Saprykin <saprykin.spb@gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# 'Software'), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function (plibsys_detect_va_copy result)
+ #
+ # On platforms that supports va_start() and al.
+ # there is sometimes the need to do va_copy() when
+ # calling another va_list aware function.
+ #
+ # This means that va_copy() is not needed (thus not available)
+ # everywhere.
+ #
+ # We depend on stdarg.h in any case, stdio.h in some cases.
+ #
+ # Known implementations vary from va_copy to __va_copy (old proposed name).
+ # We check the _va_copy eventually.
+ #
+ set (P_VA_COPY FALSE)
+ foreach (KEYWORD "va_copy" "_va_copy" "__va_copy")
+ check_c_source_compiles ("
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+
+ void f (int i, ...) {
+ va_list args1, args2;
+
+ va_start (args1, i);
+ ${KEYWORD}(args2, args1);
+ if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) {
+ exit (1);
+ }
+ va_end (args1);
+ va_end (args2);
+ }
+
+ int main () {
+ f (0, 42);
+ exit (0);
+ }"
+ PLIBSYS_${KEYWORD}
+ )
+
+ if (PLIBSYS_${KEYWORD})
+ set (P_VA_COPY ${KEYWORD})
+ break()
+ endif()
+ endforeach()
+
+ # Assign result
+ set (${result} ${P_VA_COPY} PARENT_SCOPE)
+
+endfunction (plibsys_detect_va_copy)
diff --git a/3rdparty/plibsys/cmake/ThreadNameDetect.cmake b/3rdparty/plibsys/cmake/ThreadNameDetect.cmake
new file mode 100644
index 0000000..c850d82
--- /dev/null
+++ b/3rdparty/plibsys/cmake/ThreadNameDetect.cmake
@@ -0,0 +1,135 @@
+# The MIT License
+#
+# Copyright (C) 2019 Alexander Saprykin <saprykin.spb@gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# 'Software'), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function (plibsys_detect_thread_name has_pthread_np_h result)
+ set (PTHREAD_HEADERS "#include <pthread.h>")
+
+ if (${has_pthread_np_h})
+ set (PTHREAD_HEADERS "${PTHREAD_HEADERS}\n#include<pthread_np.h>")
+ endif()
+
+ # Check pthread_setname_np() with 1 arg
+
+ if (NOT PLIBSYS_THREAD_SETTER)
+ check_c_source_compiles ("
+ ${PTHREAD_HEADERS}
+
+ int main () {
+ pthread_setname_np (\"thread_name\");
+ return 0;
+ }"
+ PLIBSYS_HAS_POSIX_SETNAME_NP_1
+ )
+
+ if (PLIBSYS_HAS_POSIX_SETNAME_NP_1)
+ set (PLIBSYS_THREAD_SETTER "pthread_setname_np")
+ endif()
+ endif()
+
+ # Check pthread_setname_np() with 2 args
+
+ if (NOT PLIBSYS_THREAD_SETTER)
+ check_c_source_compiles ("
+ ${PTHREAD_HEADERS}
+
+ int main () {
+ pthread_setname_np ((pthread_t) 0, \"thread_name\");
+ return 0;
+ }"
+ PLIBSYS_HAS_POSIX_SETNAME_NP_2
+ )
+
+ if (PLIBSYS_HAS_POSIX_SETNAME_NP_2)
+ set (PLIBSYS_THREAD_SETTER "pthread_setname_np")
+ endif()
+ endif()
+
+ # Check pthread_setname_np() with 3 args
+
+ if (NOT PLIBSYS_THREAD_SETTER)
+ check_c_source_compiles ("
+ ${PTHREAD_HEADERS}
+
+ int main () {
+ pthread_setname_np ((pthread_t) 0, \"thread_name\", 0);
+ return 0;
+ }"
+ PLIBSYS_HAS_POSIX_SETNAME_NP_3
+ )
+
+ if (PLIBSYS_HAS_POSIX_SETNAME_NP_3)
+ set (PLIBSYS_THREAD_SETTER "pthread_setname_np")
+ endif()
+ endif()
+
+ # Check pthread_set_name_np()
+
+ if (NOT PLIBSYS_THREAD_SETTER)
+ check_c_source_compiles ("
+ ${PTHREAD_HEADERS}
+
+ int main () {
+ pthread_set_name_np ((pthread_t) 0, \"thread_name\");
+ return 0;
+ }"
+ PLIBSYS_HAS_POSIX_SET_NAME_NP
+ )
+
+ if (PLIBSYS_HAS_POSIX_SET_NAME_NP)
+ set (PLIBSYS_THREAD_SETTER "pthread_set_name_np")
+ endif()
+ endif()
+
+ # The last try is prctl()
+
+ if (NOT PLIBSYS_THREAD_SETTER)
+ check_c_source_compiles ("
+ #include <sys/prctl.h>
+ #include <linux/prctl.h>
+
+ int main () {
+ prctl (PR_SET_NAME, \"thread_name\", NULL, NULL, NULL);
+ return 0;
+ }"
+ PLIBSYS_PRCTL
+ )
+
+ if (PLIBSYS_PRCTL)
+ set (PLIBSYS_THREAD_SETTER "prctl")
+ endif()
+ endif()
+
+ # It seems that CMake (old versions like 2.8.x - 2.10.x) has a bug,
+ # such that when passing empty values to the parent scope, these variable
+ # are not treated as empty, thereby use NONE value instead
+
+ if (PLIBSYS_THREAD_SETTER STREQUAL "pthread_setname_np")
+ set (${result} "PLIBSYS_HAS_PTHREAD_SETNAME" PARENT_SCOPE)
+ elseif (PLIBSYS_THREAD_SETTER STREQUAL "pthread_set_name_np")
+ set (${result} "PLIBSYS_HAS_PTHREAD_SET_NAME" PARENT_SCOPE)
+ elseif (PLIBSYS_THREAD_SETTER STREQUAL "prctl")
+ set (${result} "PLIBSYS_HAS_PTHREAD_PRCTL" PARENT_SCOPE)
+ else()
+ set (${result} "NONE" PARENT_SCOPE)
+ endif()
+endfunction (plibsys_detect_thread_name)
diff --git a/3rdparty/plibsys/cmake/VisibilityDetect.cmake b/3rdparty/plibsys/cmake/VisibilityDetect.cmake
new file mode 100644
index 0000000..cbf23cd
--- /dev/null
+++ b/3rdparty/plibsys/cmake/VisibilityDetect.cmake
@@ -0,0 +1,127 @@
+# The MIT License
+#
+# Copyright (C) 2018 Alexander Saprykin <saprykin.spb@gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# 'Software'), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function (plibsys_detect_visibility cflags ldflags)
+ if (WIN32 OR CYGWIN OR MSYS)
+ set (${cflags} "" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Check GCC
+ check_c_source_compiles ("int main () {
+ #if (__GNUC__ >= 4) && !defined(_CRAYC) && \\\\
+ !defined(__sun) && !defined(sun) && \\\\
+ !defined(__hpux) && !defined(hpux) && \\\\
+ !defined(__sgi) && !defined(sgi) && \\\\
+ !defined(__osf__) && !defined(__osf) && \\\\
+ !defined(__OS2__) \\\\
+ !defined(_AIX) && !defined(__CYGWIN__) && !defined(__MSYS__)
+ return 0;
+ #else
+ stop_compile_here
+ #endif
+ }"
+ PLIBSYS_HAS_GCC_VISIBILITY
+ )
+
+ if (PLIBSYS_HAS_GCC_VISIBILITY)
+ set (${cflags} "-fvisibility=hidden" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Check Sun Studio
+ check_c_source_compiles ("int main () {
+ #if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)) || \\\\
+ (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x5110))
+ return 0;
+ #else
+ stop_compile_here
+ #endif
+ }"
+ PLIBSYS_HAS_SUN_VISIBILITY
+ )
+
+ if (PLIBSYS_HAS_SUN_VISIBILITY)
+ set (${cflags} "" PARENT_SCOPE)
+ set (${ldlags} "-xldscope=__hidden" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Check IBM XL C
+ check_c_source_compiles ("int main () {
+ #if (defined(__xlC__) && (__xlC__ >= 0x0D01))
+ return 0;
+ #else
+ stop_compile_here
+ #endif
+ }"
+ PLIBSYS_HAS_XLC_VISIBILITY
+ )
+
+ if (PLIBSYS_HAS_XLC_VISIBILITY)
+ set (${cflags} "-qvisibility=hidden" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Check HP C/aC++
+ check_c_source_compiles ("int main () {
+ #if (defined(__HP_cc) && (__HP_cc >= 0x061500)) || \\\\
+ (defined(__HP_aCC) && (__HP_aCC >= 0x061500))
+ return 0;
+ #else
+ stop_compile_here
+ #endif
+ }"
+ PLIBSYS_HAS_HP_VISIBILITY
+ )
+
+ if (PLIBSYS_HAS_HP_VISIBILITY)
+ set (${cflags} "-Bhidden" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Check Clang
+ check_c_source_compiles ("int main () {
+ #if defined(__has_attribute) && __has_attribute(visibility)
+ return 0;
+ #else
+ stop_compile_here
+ #endif
+ }"
+ PLIBSYS_HAS_CLANG_VISIBILITY
+ )
+
+ if (PLIBSYS_HAS_CLANG_VISIBILITY)
+ set (${cflags} "-fvisibility=hidden" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+ return()
+ endif()
+
+ # Empty result
+ set (${cflags} "" PARENT_SCOPE)
+ set (${ldflags} "" PARENT_SCOPE)
+endfunction (plibsys_detect_visibility)