Fix CMake build for ARM/Linux
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3bce90..ed799cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@
INCLUDE(GNUInstallDirs)
# ---[ Project and semantic versioning.
-PROJECT(cpuinfo LANGUAGES C CXX VERSION 1.0.0 DESCRIPTION "CPU INFOrmation library")
+PROJECT(cpuinfo VERSION 1.0 LANGUAGES C CXX)
# ---[ Options.
OPTION(BUILD_TOOLS "Build command-line tools" ON)
@@ -95,11 +95,20 @@
LIST(APPEND CPUINFO_SRCS src/mach/topology.c)
ENDIF()
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
+ SET(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+ SET(THREADS_PREFER_PTHREAD_FLAG TRUE)
+ FIND_PACKAGE(Threads REQUIRED)
+ENDIF()
+
ADD_LIBRARY(cpuinfo ${CPUINFO_SRCS})
SET_TARGET_PROPERTIES(cpuinfo PROPERTIES VERSION ${PROJECT_VERSION})
SET_TARGET_PROPERTIES(cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h)
TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE include)
TARGET_INCLUDE_DIRECTORIES(cpuinfo PRIVATE src)
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
+ TARGET_LINK_LIBRARIES(cpuinfo PUBLIC ${CMAKE_THREAD_LIBS_INIT})
+ENDIF()
INSTALL(TARGETS cpuinfo
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -119,6 +128,9 @@
TARGET_INCLUDE_DIRECTORIES(cpuinfo_mock PRIVATE include)
TARGET_INCLUDE_DIRECTORIES(cpuinfo_mock PRIVATE src)
TARGET_COMPILE_DEFINITIONS(cpuinfo_mock PRIVATE "-DCPUINFO_MOCK=1")
+ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
+ TARGET_LINK_LIBRARIES(cpuinfo_mock PUBLIC ${CMAKE_THREAD_LIBS_INIT})
+ ENDIF()
ENDIF()
# ---[ Helper and debug tools
diff --git a/configure.py b/configure.py
index 4393cd4..d01cea6 100755
--- a/configure.py
+++ b/configure.py
@@ -16,8 +16,6 @@
"CPUINFO_LOG_LEVEL": {"none": 0, "error": 1, "warning": 2, "info": 3, "debug": 4}[options.log_level],
"CPUINFO_MOCK": int(options.mock)
}
- if build.target.is_linux:
- macros["_GNU_SOURCE"] = 1
build.export_cpath("include", ["cpuinfo.h"])
diff --git a/src/linux/current.c b/src/linux/current.c
index 7654e4d..d4a7f69 100644
--- a/src/linux/current.c
+++ b/src/linux/current.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE 1
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/src/linux/processors.c b/src/linux/processors.c
index 8df06f5..aa6814e 100644
--- a/src/linux/processors.c
+++ b/src/linux/processors.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE 1
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>