| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6613322 commit b4ccc41
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,144 @@ | |||
| 1 | + # The MIT License | ||
| 2 | + # | ||
| 3 | + # Copyright (C) 2018 Alexander Saprykin <saprykin.spb@gmail.com> | ||
| 4 | + # | ||
| 5 | + # Permission is hereby granted, free of charge, to any person obtaining | ||
| 6 | + # a copy of this software and associated documentation files (the | ||
| 7 | + # 'Software'), to deal in the Software without restriction, including | ||
| 8 | + # without limitation the rights to use, copy, modify, merge, publish, | ||
| 9 | + # distribute, sublicense, and/or sell copies of the Software, and to | ||
| 10 | + # permit persons to whom the Software is furnished to do so, subject to | ||
| 11 | + # the following conditions: | ||
| 12 | + # | ||
| 13 | + # The above copyright notice and this permission notice shall be | ||
| 14 | + # included in all copies or substantial portions of the Software. | ||
| 15 | + # | ||
| 16 | + # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | + # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | + # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 20 | + # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 21 | + # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 22 | + # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | + | ||
| 24 | + function (plibsys_detect_c_compiler result) | ||
| 25 | + # Get target system OS | ||
| 26 | + string (TOLOWER ${CMAKE_SYSTEM_NAME} PLIBSYS_TARGET_OS) | ||
| 27 | + | ||
| 28 | + # Detect C compiler by it's ID | ||
| 29 | + if (CMAKE_C_COMPILER_ID STREQUAL GNU) | ||
| 30 | + set (PLIBSYS_C_COMPILER gcc) | ||
| 31 | + elseif (CMAKE_C_COMPILER_ID STREQUAL MSVC) | ||
| 32 | + set (PLIBSYS_C_COMPILER msvc) | ||
| 33 | + else() | ||
| 34 | + string (TOLOWER ${CMAKE_C_COMPILER_ID} PLIBSYS_C_COMPILER) | ||
| 35 | + endif() | ||
| 36 | + | ||
| 37 | + # Fix gcc -> qcc naming on QNX 6 | ||
| 38 | + if ((PLIBSYS_TARGET_OS STREQUAL qnx) AND (PLIBSYS_C_COMPILER STREQUAL gcc)) | ||
| 39 | + set (PLIBSYS_C_COMPILER qcc) | ||
| 40 | + endif() | ||
| 41 | + | ||
| 42 | + # Rename intel -> icc | ||
| 43 | + if (PLIBSYS_C_COMPILER STREQUAL intel) | ||
| 44 | + set (PLIBSYS_C_COMPILER icc) | ||
| 45 | + endif() | ||
| 46 | + | ||
| 47 | + # Rename openwatcom -> watcom | ||
| 48 | + if (PLIBSYS_C_COMPILER STREQUAL openwatcom) | ||
| 49 | + set (PLIBSYS_C_COMPILER watcom) | ||
| 50 | + endif() | ||
| 51 | + | ||
| 52 | + # Rename xl -> xlc | ||
| 53 | + if (PLIBSYS_C_COMPILER STREQUAL xl) | ||
| 54 | + set (PLIBSYS_C_COMPILER xlc) | ||
| 55 | + endif() | ||
| 56 | + | ||
| 57 | + # Assign result | ||
| 58 | + set (${result} ${PLIBSYS_C_COMPILER} PARENT_SCOPE) | ||
| 59 | + endfunction (plibsys_detect_c_compiler) | ||
| 60 | + | ||
| 61 | + function (plibsys_detect_os_bits result) | ||
| 62 | + if (PLIBSYS_SIZEOF_VOID_P EQUAL 8) | ||
| 63 | + set (PLIBSYS_ARCH_BITS 64) | ||
| 64 | + elseif (PLIBSYS_SIZEOF_VOID_P EQUAL 4) | ||
| 65 | + set (PLIBSYS_ARCH_BITS 32) | ||
| 66 | + elseif(PLIBSYS_SIZEOF_VOID_P EQUAL 0) | ||
| 67 | + set (PLIBSYS_ARCH_BITS "universal") | ||
| 68 | + else() | ||
| 69 | + set (PLIBSYS_ARCH_BITS "unknown") | ||
| 70 | + endif() | ||
| 71 | + | ||
| 72 | + set (${result} ${PLIBSYS_ARCH_BITS} PARENT_SCOPE) | ||
| 73 | + endfunction (plibsys_detect_os_bits) | ||
| 74 | + | ||
| 75 | + function (plibsys_detect_cpu_arch result) | ||
| 76 | + if (CMAKE_SYSTEM_PROCESSOR MATCHES "(i[1-9]86)|(x86_64)") | ||
| 77 | + if (CMAKE_CROSSCOMPILING) | ||
| 78 | + if (CMAKE_SYSTEM_PROCESSOR MATCHES "i[1-9]86") | ||
| 79 | + set (PLIBSYS_PROCESSOR_ARCH "x86") | ||
| 80 | + else() | ||
| 81 | + set (PLIBSYS_PROCESSOR_ARCH "x64") | ||
| 82 | + endif() | ||
| 83 | + else() | ||
| 84 | + plibsys_detect_os_bits (PLIBSYS_OS_BITS) | ||
| 85 | + if (PLIBSYS_OS_BITS STREQUAL "32") | ||
| 86 | + set (PLIBSYS_PROCESSOR_ARCH "x86") | ||
| 87 | + elseif (PLIBSYS_OS_BITS STREQUAL "64") | ||
| 88 | + set (PLIBSYS_PROCESSOR_ARCH "x64") | ||
| 89 | + else() | ||
| 90 | + set (PLIBSYS_PROCESSOR_ARCH "x${PLIBSYS_OS_BITS}") | ||
| 91 | + endif() | ||
| 92 | + endif() | ||
| 93 | + else() | ||
| 94 | + set (PLIBSYS_PROCESSOR_ARCH ${CMAKE_SYSTEM_PROCESSOR}) | ||
| 95 | + endif() | ||
| 96 | + | ||
| 97 | + set (${result} ${PLIBSYS_PROCESSOR_ARCH} PARENT_SCOPE) | ||
| 98 | + endfunction (plibsys_detect_cpu_arch) | ||
| 99 | + | ||
| 100 | + function (plibsys_detect_target_os result) | ||
| 101 | + string (TOLOWER ${CMAKE_SYSTEM_NAME} PLIBSYS_TARGET_OS) | ||
| 102 | + | ||
| 103 | + # Rename mingw -> windows | ||
| 104 | + if (PLIBSYS_TARGET_OS MATCHES "(mingw.*)") | ||
| 105 | + set (PLIBSYS_TARGET_OS windows) | ||
| 106 | + endif() | ||
| 107 | + | ||
| 108 | + # Rename hp-ux -> hpux | ||
| 109 | + if (PLIBSYS_TARGET_OS STREQUAL hp-ux) | ||
| 110 | + set (PLIBSYS_TARGET_OS hpux) | ||
| 111 | + endif() | ||
| 112 | + | ||
| 113 | + # Rename sco_sv -> scosv | ||
| 114 | + if (PLIBSYS_TARGET_OS STREQUAL sco_sv) | ||
| 115 | + set (PLIBSYS_TARGET_OS scosv) | ||
| 116 | + endif() | ||
| 117 | + | ||
| 118 | + # Rename osf1 -> tru64 | ||
| 119 | + if (PLIBSYS_TARGET_OS STREQUAL osf1) | ||
| 120 | + set (PLIBSYS_TARGET_OS tru64) | ||
| 121 | + endif() | ||
| 122 | + | ||
| 123 | + # Rename craylinuxenvironment -> linux | ||
| 124 | + if (PLIBSYS_TARGET_OS STREQUAL craylinuxenvironment) | ||
| 125 | + set (PLIBSYS_TARGET_OS linux) | ||
| 126 | + endif() | ||
| 127 | + | ||
| 128 | + set (${result} ${PLIBSYS_TARGET_OS} PARENT_SCOPE) | ||
| 129 | + endfunction (plibsys_detect_target_os) | ||
| 130 | + | ||
| 131 | + function (plibsys_detect_target_platform result) | ||
| 132 | + plibsys_detect_target_os (PLIBSYS_TARGET_OS) | ||
| 133 | + plibsys_detect_os_bits (PLIBSYS_OS_BITS) | ||
| 134 | + plibsys_detect_c_compiler (PLIBSYS_C_COMPILER) | ||
| 135 | + | ||
| 136 | + if (PLIBSYS_TARGET_OS STREQUAL windows) | ||
| 137 | + set (PLIBSYS_TARGET_PLATFORM win${PLIBSYS_OS_BITS}) | ||
| 138 | + else() | ||
| 139 | + set (PLIBSYS_TARGET_PLATFORM ${PLIBSYS_TARGET_OS}) | ||
| 140 | + endif() | ||
| 141 | + | ||
| 142 | + set (PLIBSYS_TARGET_PLATFORM ${PLIBSYS_TARGET_PLATFORM}-${PLIBSYS_C_COMPILER}) | ||
| 143 | + set (${result} ${PLIBSYS_TARGET_PLATFORM} PARENT_SCOPE) | ||
| 144 | + endfunction (plibsys_detect_target_platform) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,74 @@ | |||
| 1 | + # The MIT License | ||
| 2 | + # | ||
| 3 | + # Copyright (C) 2017 Jean-Damien Durand <jeandamiendurand@gmail.com> | ||
| 4 | + # Copyright (C) 2019 Alexander Saprykin <saprykin.spb@gmail.com> | ||
| 5 | + # | ||
| 6 | + # Permission is hereby granted, free of charge, to any person obtaining | ||
| 7 | + # a copy of this software and associated documentation files (the | ||
| 8 | + # 'Software'), to deal in the Software without restriction, including | ||
| 9 | + # without limitation the rights to use, copy, modify, merge, publish, | ||
| 10 | + # distribute, sublicense, and/or sell copies of the Software, and to | ||
| 11 | + # permit persons to whom the Software is furnished to do so, subject to | ||
| 12 | + # the following conditions: | ||
| 13 | + # | ||
| 14 | + # The above copyright notice and this permission notice shall be | ||
| 15 | + # included in all copies or substantial portions of the Software. | ||
| 16 | + # | ||
| 17 | + # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
| 18 | + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 19 | + # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 20 | + # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 21 | + # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 22 | + # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 23 | + # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 24 | + | ||
| 25 | + function (plibsys_detect_va_copy result) | ||
| 26 | + # | ||
| 27 | + # On platforms that supports va_start() and al. | ||
| 28 | + # there is sometimes the need to do va_copy() when | ||
| 29 | + # calling another va_list aware function. | ||
| 30 | + # | ||
| 31 | + # This means that va_copy() is not needed (thus not available) | ||
| 32 | + # everywhere. | ||
| 33 | + # | ||
| 34 | + # We depend on stdarg.h in any case, stdio.h in some cases. | ||
| 35 | + # | ||
| 36 | + # Known implementations vary from va_copy to __va_copy (old proposed name). | ||
| 37 | + # We check the _va_copy eventually. | ||
| 38 | + # | ||
| 39 | + set (P_VA_COPY FALSE) | ||
| 40 | + foreach (KEYWORD "va_copy" "_va_copy" "__va_copy") | ||
| 41 | + check_c_source_compiles (" | ||
| 42 | + #include <stdio.h> | ||
| 43 | + #include <stdlib.h> | ||
| 44 | + #include <stdarg.h> | ||
| 45 | + | ||
| 46 | + void f (int i, ...) { | ||
| 47 | + va_list args1, args2; | ||
| 48 | + | ||
| 49 | + va_start (args1, i); | ||
| 50 | + ${KEYWORD}(args2, args1); | ||
| 51 | + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) { | ||
| 52 | + exit (1); | ||
| 53 | + } | ||
| 54 | + va_end (args1); | ||
| 55 | + va_end (args2); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + int main () { | ||
| 59 | + f (0, 42); | ||
| 60 | + exit (0); | ||
| 61 | + }" | ||
| 62 | + PLIBSYS_${KEYWORD} | ||
| 63 | + ) | ||
| 64 | + | ||
| 65 | + if (PLIBSYS_${KEYWORD}) | ||
| 66 | + set (P_VA_COPY ${KEYWORD}) | ||
| 67 | + break() | ||
| 68 | + endif() | ||
| 69 | + endforeach() | ||
| 70 | + | ||
| 71 | + # Assign result | ||
| 72 | + set (${result} ${P_VA_COPY} PARENT_SCOPE) | ||
| 73 | + | ||
| 74 | + endfunction (plibsys_detect_va_copy) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,135 @@ | |||
| 1 | + # The MIT License | ||
| 2 | + # | ||
| 3 | + # Copyright (C) 2019 Alexander Saprykin <saprykin.spb@gmail.com> | ||
| 4 | + # | ||
| 5 | + # Permission is hereby granted, free of charge, to any person obtaining | ||
| 6 | + # a copy of this software and associated documentation files (the | ||
| 7 | + # 'Software'), to deal in the Software without restriction, including | ||
| 8 | + # without limitation the rights to use, copy, modify, merge, publish, | ||
| 9 | + # distribute, sublicense, and/or sell copies of the Software, and to | ||
| 10 | + # permit persons to whom the Software is furnished to do so, subject to | ||
| 11 | + # the following conditions: | ||
| 12 | + # | ||
| 13 | + # The above copyright notice and this permission notice shall be | ||
| 14 | + # included in all copies or substantial portions of the Software. | ||
| 15 | + # | ||
| 16 | + # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | + # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | + # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 20 | + # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 21 | + # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 22 | + # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | + | ||
| 24 | + function (plibsys_detect_thread_name has_pthread_np_h result) | ||
| 25 | + set (PTHREAD_HEADERS "#include <pthread.h>") | ||
| 26 | + | ||
| 27 | + if (${has_pthread_np_h}) | ||
| 28 | + set (PTHREAD_HEADERS "${PTHREAD_HEADERS}\n#include<pthread_np.h>") | ||
| 29 | + endif() | ||
| 30 | + | ||
| 31 | + # Check pthread_setname_np() with 1 arg | ||
| 32 | + | ||
| 33 | + if (NOT PLIBSYS_THREAD_SETTER) | ||
| 34 | + check_c_source_compiles (" | ||
| 35 | + ${PTHREAD_HEADERS} | ||
| 36 | + | ||
| 37 | + int main () { | ||
| 38 | + pthread_setname_np (\"thread_name\"); | ||
| 39 | + return 0; | ||
| 40 | + }" | ||
| 41 | + PLIBSYS_HAS_POSIX_SETNAME_NP_1 | ||
| 42 | + ) | ||
| 43 | + | ||
| 44 | + if (PLIBSYS_HAS_POSIX_SETNAME_NP_1) | ||
| 45 | + set (PLIBSYS_THREAD_SETTER "pthread_setname_np") | ||
| 46 | + endif() | ||
| 47 | + endif() | ||
| 48 | + | ||
| 49 | + # Check pthread_setname_np() with 2 args | ||
| 50 | + | ||
| 51 | + if (NOT PLIBSYS_THREAD_SETTER) | ||
| 52 | + check_c_source_compiles (" | ||
| 53 | + ${PTHREAD_HEADERS} | ||
| 54 | + | ||
| 55 | + int main () { | ||
| 56 | + pthread_setname_np ((pthread_t) 0, \"thread_name\"); | ||
| 57 | + return 0; | ||
| 58 | + }" | ||
| 59 | + PLIBSYS_HAS_POSIX_SETNAME_NP_2 | ||
| 60 | + ) | ||
| 61 | + | ||
| 62 | + if (PLIBSYS_HAS_POSIX_SETNAME_NP_2) | ||
| 63 | + set (PLIBSYS_THREAD_SETTER "pthread_setname_np") | ||
| 64 | + endif() | ||
| 65 | + endif() | ||
| 66 | + | ||
| 67 | + # Check pthread_setname_np() with 3 args | ||
| 68 | + | ||
| 69 | + if (NOT PLIBSYS_THREAD_SETTER) | ||
| 70 | + check_c_source_compiles (" | ||
| 71 | + ${PTHREAD_HEADERS} | ||
| 72 | + | ||
| 73 | + int main () { | ||
| 74 | + pthread_setname_np ((pthread_t) 0, \"thread_name\", 0); | ||
| 75 | + return 0; | ||
| 76 | + }" | ||
| 77 | + PLIBSYS_HAS_POSIX_SETNAME_NP_3 | ||
| 78 | + ) | ||
| 79 | + | ||
| 80 | + if (PLIBSYS_HAS_POSIX_SETNAME_NP_3) | ||
| 81 | + set (PLIBSYS_THREAD_SETTER "pthread_setname_np") | ||
| 82 | + endif() | ||
| 83 | + endif() | ||
| 84 | + | ||
| 85 | + # Check pthread_set_name_np() | ||
| 86 | + | ||
| 87 | + if (NOT PLIBSYS_THREAD_SETTER) | ||
| 88 | + check_c_source_compiles (" | ||
| 89 | + ${PTHREAD_HEADERS} | ||
| 90 | + | ||
| 91 | + int main () { | ||
| 92 | + pthread_set_name_np ((pthread_t) 0, \"thread_name\"); | ||
| 93 | + return 0; | ||
| 94 | + }" | ||
| 95 | + PLIBSYS_HAS_POSIX_SET_NAME_NP | ||
| 96 | + ) | ||
| 97 | + | ||
| 98 | + if (PLIBSYS_HAS_POSIX_SET_NAME_NP) | ||
| 99 | + set (PLIBSYS_THREAD_SETTER "pthread_set_name_np") | ||
| 100 | + endif() | ||
| 101 | + endif() | ||
| 102 | + | ||
| 103 | + # The last try is prctl() | ||
| 104 | + | ||
| 105 | + if (NOT PLIBSYS_THREAD_SETTER) | ||
| 106 | + check_c_source_compiles (" | ||
| 107 | + #include <sys/prctl.h> | ||
| 108 | + #include <linux/prctl.h> | ||
| 109 | + | ||
| 110 | + int main () { | ||
| 111 | + prctl (PR_SET_NAME, \"thread_name\", NULL, NULL, NULL); | ||
| 112 | + return 0; | ||
| 113 | + }" | ||
| 114 | + PLIBSYS_PRCTL | ||
| 115 | + ) | ||
| 116 | + | ||
| 117 | + if (PLIBSYS_PRCTL) | ||
| 118 | + set (PLIBSYS_THREAD_SETTER "prctl") | ||
| 119 | + endif() | ||
| 120 | + endif() | ||
| 121 | + | ||
| 122 | + # It seems that CMake (old versions like 2.8.x - 2.10.x) has a bug, | ||
| 123 | + # such that when passing empty values to the parent scope, these variable | ||
| 124 | + # are not treated as empty, thereby use NONE value instead | ||
| 125 | + | ||
| 126 | + if (PLIBSYS_THREAD_SETTER STREQUAL "pthread_setname_np") | ||
| 127 | + set (${result} "PLIBSYS_HAS_PTHREAD_SETNAME" PARENT_SCOPE) | ||
| 128 | + elseif (PLIBSYS_THREAD_SETTER STREQUAL "pthread_set_name_np") | ||
| 129 | + set (${result} "PLIBSYS_HAS_PTHREAD_SET_NAME" PARENT_SCOPE) | ||
| 130 | + elseif (PLIBSYS_THREAD_SETTER STREQUAL "prctl") | ||
| 131 | + set (${result} "PLIBSYS_HAS_PTHREAD_PRCTL" PARENT_SCOPE) | ||
| 132 | + else() | ||
| 133 | + set (${result} "NONE" PARENT_SCOPE) | ||
| 134 | + endif() | ||
| 135 | + endfunction (plibsys_detect_thread_name) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments