Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame^] | 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR) |
| 2 | |
| 3 | INCLUDE(GNUInstallDirs) |
| 4 | |
| 5 | # ---[ Project and semantic versioning. |
| 6 | PROJECT(cpuinfo VERSION 1.0.0 DESCRIPTION "CPU INFOrmation library") |
| 7 | |
| 8 | # ---[ Options. |
| 9 | OPTION(BUILD_TOOLS "Build command-line tools" ON) |
| 10 | OPTION(BUILD_UNIT_TESTS "Build C++ unit tests (need googletest)" ON) |
| 11 | OPTION(BUILD_MOCK_TESTS "Build C++ mock tests (need googletest)" ON) |
| 12 | |
| 13 | # ---[ Build flags |
| 14 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") |
| 15 | IF(NOT MSVC) |
| 16 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -fPIC") |
| 17 | ENDIF() |
| 18 | |
| 19 | IF(NOT CMAKE_SYSTEM_PROCESSOR) |
| 20 | MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR not defined") |
| 21 | ELSEIF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|armv5te|armv7-a|aarch64)$") |
| 22 | MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}") |
| 23 | ENDIF() |
| 24 | |
| 25 | IF(NOT CMAKE_SYSTEM_NAME) |
| 26 | MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_NAME not defined") |
| 27 | ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux|Android)$") |
| 28 | MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}") |
| 29 | ENDIF() |
| 30 | |
| 31 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 32 | |
| 33 | # ---[ cpuinfo library |
| 34 | SET(CPUINFO_SRCS |
| 35 | src/init.c |
| 36 | src/api.c |
| 37 | src/log.c) |
| 38 | |
| 39 | IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64)$") |
| 40 | LIST(APPEND CPUINFO_SRCS |
| 41 | src/x86/init.c |
| 42 | src/x86/info.c |
| 43 | src/x86/vendor.c |
| 44 | src/x86/uarch.c |
| 45 | src/x86/name.c |
| 46 | src/x86/topology.c |
| 47 | src/x86/isa.c |
| 48 | src/x86/cache/init.c |
| 49 | src/x86/cache/descriptor.c |
| 50 | src/x86/cache/deterministic.c) |
| 51 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 52 | LIST(APPEND CPUINFO_SRCS |
| 53 | src/x86/linux/init.c |
| 54 | src/x86/linux/cpuinfo.c) |
| 55 | ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 56 | LIST(APPEND CPUINFO_SRCS src/x86/mach/init.c) |
| 57 | ENDIF() |
| 58 | ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7-a|aarch64)$") |
| 59 | LIST(APPEND CPUINFO_SRCS |
| 60 | src/arm/uarch.c |
| 61 | src/arm/cache.c) |
| 62 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 63 | LIST(APPEND CPUINFO_SRCS |
| 64 | src/arm/linux/init.c |
| 65 | src/arm/linux/cpuinfo.c |
| 66 | src/arm/linux/clusters.c |
| 67 | src/arm/linux/midr.c) |
| 68 | ENDIF() |
| 69 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 70 | LIST(APPEND CPUINFO_SRCS |
| 71 | src/arm/Android/chipset.c |
| 72 | src/arm/Android/properties.c) |
| 73 | ENDIF() |
| 74 | IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7-a)$") |
| 75 | LIST(APPEND CPUINFO_SRCS src/arm/linux/arm32-isa.c) |
| 76 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android" AND ANDROID_ABI STREQUAL "armeabi") |
| 77 | SET_SOURCE_FILES_PROPERTIES(src/arm/linux/arm32-isa.c PROPERTIES COMPILE_FLAGS -marm) |
| 78 | ENDIF() |
| 79 | ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") |
| 80 | LIST(APPEND CPUINFO_SRCS src/arm/linux/arm64-isa.c) |
| 81 | ENDIF() |
| 82 | ENDIF() |
| 83 | |
| 84 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 85 | LIST(APPEND CPUINFO_SRCS |
| 86 | src/linux/smallfile.c |
| 87 | src/linux/multiline.c |
| 88 | src/linux/current.c |
| 89 | src/linux/cpulist.c |
| 90 | src/linux/processors.c) |
| 91 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 92 | LIST(APPEND CPUINFO_SRCS src/gpu/gles2.c) |
| 93 | ENDIF() |
| 94 | ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 95 | LIST(APPEND CPUINFO_SRCS src/mach/topology.c) |
| 96 | ENDIF() |
| 97 | |
| 98 | ADD_LIBRARY(cpuinfo ${CPUINFO_SRCS}) |
| 99 | SET_TARGET_PROPERTIES(cpuinfo PROPERTIES VERSION ${PROJECT_VERSION}) |
| 100 | SET_TARGET_PROPERTIES(cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h) |
| 101 | TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE include) |
| 102 | TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE src) |
| 103 | |
| 104 | INSTALL(TARGETS cpuinfo |
| 105 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 106 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 107 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 108 | |
| 109 | # ---[ Helper and debug tools |
| 110 | IF(BUILD_TOOLS) |
| 111 | ADD_EXECUTABLE(isa-info tools/isa-info.c) |
| 112 | TARGET_LINK_LIBRARIES(isa-info PRIVATE cpuinfo) |
| 113 | |
| 114 | ADD_EXECUTABLE(cpu-info tools/cpu-info.c) |
| 115 | TARGET_LINK_LIBRARIES(cpu-info PRIVATE cpuinfo) |
| 116 | |
| 117 | ADD_EXECUTABLE(cache-info tools/cache-info.c) |
| 118 | TARGET_LINK_LIBRARIES(cache-info PRIVATE cpuinfo) |
| 119 | |
| 120 | IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64)$") |
| 121 | ADD_EXECUTABLE(cpuid-dump tools/cpuid-dump.c) |
| 122 | TARGET_INCLUDE_DIRECTORIES(cpuid-dump PRIVATE src) |
| 123 | TARGET_INCLUDE_DIRECTORIES(cpuid-dump PRIVATE include) |
| 124 | ENDIF() |
| 125 | ENDIF() |