diff --git a/CMakeLists.txt b/CMakeLists.txt index 209688f..34eb2cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,18 @@ option(LIBCPUID_TESTS "Enable building tests" OFF) set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 99) +# pthreads library +if(${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly" OR ${CMAKE_SYSTEM_NAME} STREQUAL "NetBSD") + find_package(Threads REQUIRED) +endif() + +# check if popcount64 is available +include(CheckSymbolExists) +check_symbol_exists(popcount64 "string.h" HAVE_POPCOUNT64) +if(HAVE_POPCOUNT64) + add_definitions(-DHAVE_POPCOUNT64) +endif(HAVE_POPCOUNT64) + # Global variables list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") diff --git a/configure.ac b/configure.ac index d2d9253..ccdbbbb 100644 --- a/configure.ac +++ b/configure.ac @@ -62,18 +62,45 @@ fi AC_CANONICAL_HOST +AC_MSG_CHECKING([Whether we need POSIX threads]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ + #if defined(__NetBSD__) || defined(__DragonFly__) + #else + # error "no pthreads needed" + #endif + ]) +], [ + AC_MSG_RESULT([yes]) + AC_SUBST([LIBCPUID_LDFLAGS], ["-pthread"]) +], [ + AC_MSG_RESULT([no]) +]) + build_windows=no +build_netbsd=no +build_dragonflybsd=no case "${host_os}" in cygwin*|mingw*) build_windows=yes ;; + netbsd*) + build_netbsd=yes + ;; + dragonfly*) + build_dragonflybsd=yes + ;; esac if test "$build_windows" = "no"; then AM_CPPFLAGS="$AM_CPPFLAGS -D_GNU_SOURCE" fi +if test "$build_netbsd" = "yes" || test "$build_dragonflybsd" = "yes"; then + AM_LDFLAGS="$AM_LDFLAGS -pthread" +fi + AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"]) AC_SUBST(AM_CPPFLAGS) diff --git a/libcpuid/CMakeLists.txt b/libcpuid/CMakeLists.txt index 418be3f..dcad1bf 100644 --- a/libcpuid/CMakeLists.txt +++ b/libcpuid/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(cpuid ${cpuid_sources}) set_property(TARGET cpuid PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(cpuid SYSTEM PUBLIC $) +target_link_libraries(cpuid ${CMAKE_THREAD_LIBS_INIT}) target_compile_definitions(cpuid PRIVATE VERSION="${PROJECT_VERSION}") set_target_properties(cpuid PROPERTIES VERSION "${LIBCPUID_CURRENT}.${LIBCPUID_AGE}.${LIBCPUID_REVISION}") set_target_properties(cpuid PROPERTIES SOVERSION "${LIBCPUID_CURRENT}")