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. |
Marat Dukhan | bfff348 | 2017-10-15 22:24:32 +0000 | [diff] [blame] | 6 | PROJECT(cpuinfo VERSION 1.0 LANGUAGES C CXX) |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 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 |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 14 | IF(NOT MSVC) |
Marat Dukhan | 7b73888 | 2017-10-18 16:59:28 -0700 | [diff] [blame] | 15 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") |
| 16 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 17 | ENDIF() |
| 18 | |
| 19 | IF(NOT CMAKE_SYSTEM_PROCESSOR) |
| 20 | MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR not defined") |
Marat Dukhan | 7b73888 | 2017-10-18 16:59:28 -0700 | [diff] [blame] | 21 | ELSEIF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|armv5te|armv7|armv7f|armv7s|armv7k|armv7-a|armv7l|arm64|aarch64)$") |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 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() |
Marat Dukhan | 7b73888 | 2017-10-18 16:59:28 -0700 | [diff] [blame] | 58 | ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7|armv7f|armv7s|armv7k|armv7-a|armv7l|arm64|aarch64)$") |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 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 |
Marat Dukhan | ed27213 | 2017-10-15 21:55:45 +0000 | [diff] [blame] | 67 | src/arm/linux/chipset.c |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 68 | src/arm/linux/midr.c) |
Marat Dukhan | 7b73888 | 2017-10-18 16:59:28 -0700 | [diff] [blame] | 69 | IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7l|armv7-a)$") |
| 70 | LIST(APPEND CPUINFO_SRCS src/arm/linux/arm32-isa.c) |
| 71 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android" AND ANDROID_ABI STREQUAL "armeabi") |
| 72 | SET_SOURCE_FILES_PROPERTIES(src/arm/linux/arm32-isa.c PROPERTIES COMPILE_FLAGS -marm) |
| 73 | ENDIF() |
| 74 | ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") |
| 75 | LIST(APPEND CPUINFO_SRCS src/arm/linux/arm64-isa.c) |
| 76 | ENDIF() |
| 77 | ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
Marat Dukhan | ad1ac95 | 2017-10-23 15:32:25 -0700 | [diff] [blame] | 78 | LIST(APPEND CPUINFO_SRCS |
| 79 | src/arm/mach/init.c |
| 80 | src/gpu/gles-ios.m) |
Marat Dukhan | 0252701 | 2017-10-23 16:03:05 -0700 | [diff] [blame^] | 81 | SET_SOURCE_FILES_PROPERTIES(src/gpu/gles-ios.m PROPERTIES COMPILE_FLAGS -fobjc-arc) |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 82 | ENDIF() |
| 83 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 84 | LIST(APPEND CPUINFO_SRCS |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 85 | src/arm/Android/properties.c) |
| 86 | ENDIF() |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 87 | ENDIF() |
| 88 | |
| 89 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 90 | LIST(APPEND CPUINFO_SRCS |
| 91 | src/linux/smallfile.c |
| 92 | src/linux/multiline.c |
| 93 | src/linux/current.c |
| 94 | src/linux/cpulist.c |
| 95 | src/linux/processors.c) |
| 96 | IF(CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 97 | LIST(APPEND CPUINFO_SRCS src/gpu/gles2.c) |
| 98 | ENDIF() |
| 99 | ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 100 | LIST(APPEND CPUINFO_SRCS src/mach/topology.c) |
| 101 | ENDIF() |
| 102 | |
Marat Dukhan | bfff348 | 2017-10-15 22:24:32 +0000 | [diff] [blame] | 103 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 104 | SET(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 105 | SET(THREADS_PREFER_PTHREAD_FLAG TRUE) |
| 106 | FIND_PACKAGE(Threads REQUIRED) |
| 107 | ENDIF() |
| 108 | |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 109 | ADD_LIBRARY(cpuinfo ${CPUINFO_SRCS}) |
| 110 | SET_TARGET_PROPERTIES(cpuinfo PROPERTIES VERSION ${PROJECT_VERSION}) |
| 111 | SET_TARGET_PROPERTIES(cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h) |
| 112 | TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE include) |
| 113 | TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE src) |
Marat Dukhan | bfff348 | 2017-10-15 22:24:32 +0000 | [diff] [blame] | 114 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 115 | TARGET_LINK_LIBRARIES(cpuinfo PUBLIC ${CMAKE_THREAD_LIBS_INIT}) |
| 116 | ENDIF() |
Marat Dukhan | ad1ac95 | 2017-10-23 15:32:25 -0700 | [diff] [blame] | 117 | IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|arm64)$") |
| 118 | TARGET_LINK_LIBRARIES(cpuinfo INTERFACE "-framework OpenGLES") |
| 119 | TARGET_LINK_LIBRARIES(cpuinfo INTERFACE "-framework Foundation") |
| 120 | ENDIF() |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 121 | |
| 122 | INSTALL(TARGETS cpuinfo |
| 123 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 124 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 125 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 126 | |
Marat Dukhan | b8a8337 | 2017-10-13 21:07:44 -0400 | [diff] [blame] | 127 | # ---[ cpuinfo mock library |
| 128 | IF(BUILD_MOCK_TESTS) |
| 129 | SET(CPUINFO_MOCK_SRCS "${CPUINFO_SRCS}") |
| 130 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 131 | LIST(APPEND CPUINFO_MOCK_SRCS src/linux/mockfile.c) |
| 132 | ENDIF() |
| 133 | |
| 134 | ADD_LIBRARY(cpuinfo_mock ${CPUINFO_MOCK_SRCS}) |
| 135 | SET_TARGET_PROPERTIES(cpuinfo_mock PROPERTIES VERSION ${PROJECT_VERSION}) |
| 136 | SET_TARGET_PROPERTIES(cpuinfo_mock PROPERTIES PUBLIC_HEADER include/cpuinfo.h) |
| 137 | TARGET_INCLUDE_DIRECTORIES(cpuinfo_mock PRIVATE include) |
| 138 | TARGET_INCLUDE_DIRECTORIES(cpuinfo_mock PRIVATE src) |
| 139 | TARGET_COMPILE_DEFINITIONS(cpuinfo_mock PRIVATE "-DCPUINFO_MOCK=1") |
Marat Dukhan | bfff348 | 2017-10-15 22:24:32 +0000 | [diff] [blame] | 140 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 141 | TARGET_LINK_LIBRARIES(cpuinfo_mock PUBLIC ${CMAKE_THREAD_LIBS_INIT}) |
| 142 | ENDIF() |
Marat Dukhan | b8a8337 | 2017-10-13 21:07:44 -0400 | [diff] [blame] | 143 | ENDIF() |
| 144 | |
Marat Dukhan | 3645b92 | 2017-10-13 17:03:35 -0400 | [diff] [blame] | 145 | # ---[ Helper and debug tools |
| 146 | IF(BUILD_TOOLS) |
| 147 | ADD_EXECUTABLE(isa-info tools/isa-info.c) |
| 148 | TARGET_LINK_LIBRARIES(isa-info PRIVATE cpuinfo) |
| 149 | |
| 150 | ADD_EXECUTABLE(cpu-info tools/cpu-info.c) |
| 151 | TARGET_LINK_LIBRARIES(cpu-info PRIVATE cpuinfo) |
| 152 | |
| 153 | ADD_EXECUTABLE(cache-info tools/cache-info.c) |
| 154 | TARGET_LINK_LIBRARIES(cache-info PRIVATE cpuinfo) |
| 155 | |
| 156 | IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64)$") |
| 157 | ADD_EXECUTABLE(cpuid-dump tools/cpuid-dump.c) |
| 158 | TARGET_INCLUDE_DIRECTORIES(cpuid-dump PRIVATE src) |
| 159 | TARGET_INCLUDE_DIRECTORIES(cpuid-dump PRIVATE include) |
| 160 | ENDIF() |
| 161 | ENDIF() |