| 1 | # SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | # |
| 3 | # Platform detection code. |
| 4 | # |
| 5 | # This sets various OS_* and CPU_* variables based on the OS. |
| 6 | # |
| 7 | # This sorts out what OS and CPU we’re building for, which is |
| 8 | # information used by numerous other parts of the build system. |
| 9 | |
| 10 | include_guard() |
| 11 | |
| 12 | macro(_nd_windows_config) |
| 13 | set(OS_WINDOWS True) |
| 14 | |
| 15 | if(NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "/opt/netdata") |
| 16 | message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be set to /opt/netdata, but it is set to ${CMAKE_INSTALL_PREFIX}") |
| 17 | endif() |
| 18 | |
| 19 | if(BUILD_FOR_PACKAGING) |
| 20 | set(NETDATA_RUNTIME_PREFIX "/") |
| 21 | endif() |
| 22 | |
| 23 | set(BINDIR usr/bin) |
| 24 | set(CMAKE_RC_COMPILER_INIT windres) |
| 25 | ENABLE_LANGUAGE(RC) |
| 26 | |
| 27 | SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>") |
| 28 | add_definitions(-D_GNU_SOURCE) |
| 29 | |
| 30 | if($ENV{CLION_IDE}) |
| 31 | set(RUN_UNDER_CLION True) |
| 32 | |
| 33 | # clion needs these to find the includes |
| 34 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") |
| 35 | if("$ENV{MSYSTEM}" STREQUAL "MSYS") |
| 36 | include_directories(c:/msys64/usr/include) |
| 37 | include_directories(c:/msys64/usr/include/w32api) |
| 38 | elseif("$ENV{MSYSTEM}" STREQUAL "MINGW64") |
| 39 | include_directories(c:/msys64/mingw64/include) |
| 40 | elseif("$ENV{MSYSTEM}" STREQUAL "UCRT64") |
| 41 | include_directories(c:/msys64/ucrt64/include) |
| 42 | endif() |
| 43 | endif() |
| 44 | endif() |
| 45 | |
| 46 | message(STATUS " Compiling for Windows (${CMAKE_SYSTEM_NAME}, MSYSTEM=$ENV{MSYSTEM})... ") |
| 47 | endmacro() |
| 48 | |
| 49 | set(OS_FREEBSD False) |
| 50 | set(OS_LINUX False) |
| 51 | set(OS_MACOS False) |
| 52 | set(OS_WINDOWS False) |
| 53 | |
| 54 | set(CPU_X86 False) |
| 55 | set(CPU_X86_64 False) |
| 56 | set(CPU_ARM False) |
| 57 | set(CPU_ARM64 False) |
| 58 | set(CPU_OTHER False) |
| 59 | |
| 60 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 61 | set(OS_MACOS True) |
| 62 | find_library(IOKIT IOKit) |
| 63 | find_library(FOUNDATION Foundation) |
| 64 | message(STATUS " Compiling for MacOS... ") |
| 65 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") |
| 66 | set(OS_FREEBSD True) |
| 67 | message(STATUS " Compiling for FreeBSD... ") |
| 68 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") |
| 69 | set(OS_LINUX True) |
| 70 | add_definitions(-D_GNU_SOURCE) |
| 71 | message(STATUS " Compiling for Linux... ") |
| 72 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") |
| 73 | _nd_windows_config() |
| 74 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS") |
| 75 | _nd_windows_config() |
| 76 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") |
| 77 | _nd_windows_config() |
| 78 | else() |
| 79 | message(FATAL_ERROR "Unknown/unsupported platform: ${CMAKE_SYSTEM_NAME} (Supported platforms: FreeBSD, Linux, macOS, Windows)") |
| 80 | endif() |
| 81 | |
| 82 | string(STRIP "${CMAKE_SYSTEM_PROCESSOR}" _nd_cpu_raw) |
| 83 | string(TOLOWER "${_nd_cpu_raw}" _nd_cpu) |
| 84 | |
| 85 | message(STATUS "Detected CPU: ${CMAKE_SYSTEM_PROCESSOR}") |
| 86 | |
| 87 | if("${_nd_cpu}" MATCHES "^(x86_64|x64|amd64)") |
| 88 | set(CPU_X86_64 True) |
| 89 | elseif("${_nd_cpu}" MATCHES "^(x86|i[3456]86|ix86)") |
| 90 | set(CPU_X86 True) |
| 91 | elseif("${_nd_cpu}" MATCHES "^(aarch|arm)64") |
| 92 | set(CPU_ARM64 True) |
| 93 | elseif("${_nd_cpu}" MATCHES "^(arm|armv[567].*)") |
| 94 | set(CPU_ARM True) |
| 95 | else() |
| 96 | set(CPU_OTHER True) |
| 97 | endif() |