Add thread support
This commit is contained in:
@@ -5,8 +5,12 @@ project(bhlib LANGUAGES C)
|
||||
set(CMAKE_C_STANDARD 90)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
# Check for IPO/LTO
|
||||
# Project includes
|
||||
include(CheckIPOSupported)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
# Check for IPO/LTO
|
||||
check_ipo_supported(RESULT supported)
|
||||
|
||||
if(supported)
|
||||
@@ -23,6 +27,7 @@ set(BHLIB_SOURCE
|
||||
src/algo.c
|
||||
src/hashmap.c
|
||||
src/queue.c
|
||||
src/thread.c
|
||||
)
|
||||
|
||||
set(BHLIB_HEADER
|
||||
@@ -31,9 +36,59 @@ set(BHLIB_HEADER
|
||||
include/bh/queue.h
|
||||
)
|
||||
|
||||
set(BHLIB_INCLUDE_DIRS
|
||||
include
|
||||
${PROJECT_BINARY_DIR}/include
|
||||
)
|
||||
|
||||
|
||||
# Determine platform
|
||||
if(WIN32)
|
||||
message(STATUS "Platform - Win32")
|
||||
|
||||
# Check multithreading support
|
||||
check_symbol_exists(_beginthread process.h BHLIB_USE_WINTHREAD)
|
||||
if(BHLIB_USE_WINTHREAD)
|
||||
message(STATUS "Multithreading enabled")
|
||||
list(APPEND BHLIB_SOURCE
|
||||
src/thread_win.c
|
||||
)
|
||||
else()
|
||||
message(STATUS "Multithreading disabled")
|
||||
list(APPEND BHLIB_SOURCE
|
||||
src/thread_null.c
|
||||
)
|
||||
endif()
|
||||
elseif(UNIX)
|
||||
message(STATUS "Platform: Unix (Linux/BSD/MacOS X)")
|
||||
|
||||
# Check multithreading support
|
||||
check_include_file(pthread.h BHLIB_USE_PTHREAD)
|
||||
if(BHLIB_USE_PTHREAD)
|
||||
message(STATUS "Multithreading enabled")
|
||||
list(APPEND BHLIB_SOURCE
|
||||
src/thread_posix.c
|
||||
)
|
||||
else()
|
||||
message(STATUS "Multithreading disabled")
|
||||
list(APPEND BHLIB_SOURCE
|
||||
src/thread_null.c
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Platform: Unknown")
|
||||
message(STATUS "Multithreading disabled")
|
||||
list(APPEND BHLIB_SOURCE
|
||||
src/thread_null.c
|
||||
)
|
||||
endif()
|
||||
|
||||
# Configure library
|
||||
configure_file(include/bh/config.in include/bh/config.h)
|
||||
|
||||
# Library
|
||||
add_library(bhlib STATIC ${BHLIB_SOURCE} ${BHLIB_HEADER})
|
||||
target_include_directories(bhlib PUBLIC include)
|
||||
target_include_directories(bhlib PUBLIC ${BHLIB_INCLUDE_DIRS})
|
||||
|
||||
# Runtime definition
|
||||
add_executable(main
|
||||
|
||||
Reference in New Issue
Block a user