2024-04-13 14:52:29 +03:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
|
|
|
|
|
# Project and C standard configuration
|
|
|
|
|
project(bhlib LANGUAGES C)
|
|
|
|
|
set(CMAKE_C_STANDARD 90)
|
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
|
|
2024-04-14 22:32:58 +03:00
|
|
|
# Project includes
|
2024-04-13 14:52:29 +03:00
|
|
|
include(CheckIPOSupported)
|
2024-04-14 22:32:58 +03:00
|
|
|
include(CheckIncludeFile)
|
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
|
|
|
|
|
# Check for IPO/LTO
|
2024-04-13 14:52:29 +03:00
|
|
|
check_ipo_supported(RESULT supported)
|
|
|
|
|
|
|
|
|
|
if(supported)
|
|
|
|
|
message(STATUS "IPO/LTO enabled")
|
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Enable testing
|
|
|
|
|
include(CTest)
|
|
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
|
|
# Set library code
|
2024-06-03 22:11:05 +03:00
|
|
|
set(BH_SOURCE
|
2024-04-14 14:00:07 +03:00
|
|
|
src/algo.c
|
2024-06-03 22:11:05 +03:00
|
|
|
src/buffer.c
|
2024-04-13 14:52:29 +03:00
|
|
|
src/hashmap.c
|
|
|
|
|
src/queue.c
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread.c
|
2024-04-23 23:45:43 +03:00
|
|
|
src/io.c
|
|
|
|
|
src/deflate.c
|
2024-04-13 14:52:29 +03:00
|
|
|
)
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
set(BH_HEADER
|
2024-04-23 23:45:43 +03:00
|
|
|
include/bh/bh.h
|
|
|
|
|
include/bh/platform.h
|
2024-06-03 22:11:05 +03:00
|
|
|
include/bh/buffer.h
|
2024-04-14 14:00:07 +03:00
|
|
|
include/bh/algo.h
|
2024-04-13 14:52:29 +03:00
|
|
|
include/bh/hashmap.h
|
|
|
|
|
include/bh/queue.h
|
2024-04-23 23:45:43 +03:00
|
|
|
include/bh/thread.h
|
|
|
|
|
include/bh/io.h
|
|
|
|
|
include/bh/deflate.h
|
2024-04-13 14:52:29 +03:00
|
|
|
)
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
set(BH_INCLUDE_DIRS
|
2024-04-14 22:32:58 +03:00
|
|
|
include
|
|
|
|
|
${PROJECT_BINARY_DIR}/include
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Determine platform
|
|
|
|
|
if(WIN32)
|
|
|
|
|
message(STATUS "Platform - Win32")
|
2024-06-03 22:11:05 +03:00
|
|
|
set(BH_PLATFORM_WIN TRUE)
|
|
|
|
|
|
|
|
|
|
# Add platform dependent files
|
|
|
|
|
list(APPEND BH_SOURCE
|
|
|
|
|
src/file_win.c
|
|
|
|
|
)
|
2024-04-14 22:32:58 +03:00
|
|
|
|
|
|
|
|
# Check multithreading support
|
2024-06-03 22:11:05 +03:00
|
|
|
check_symbol_exists(_beginthread process.h BH_USE_WINTHREAD)
|
|
|
|
|
if(BH_USE_WINTHREAD)
|
2024-04-14 22:32:58 +03:00
|
|
|
message(STATUS "Multithreading enabled")
|
2024-06-03 22:11:05 +03:00
|
|
|
list(APPEND BH_SOURCE
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread_win.c
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Multithreading disabled")
|
2024-06-03 22:11:05 +03:00
|
|
|
list(APPEND BH_SOURCE
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread_null.c
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2024-04-27 11:25:21 +03:00
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
if(BH_NO_WINXP)
|
2024-04-27 11:25:21 +03:00
|
|
|
add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA -DWINVER=_WIN32_WINNT_VISTA)
|
|
|
|
|
endif()
|
2024-04-14 22:32:58 +03:00
|
|
|
elseif(UNIX)
|
|
|
|
|
message(STATUS "Platform: Unix (Linux/BSD/MacOS X)")
|
2024-06-03 22:11:05 +03:00
|
|
|
set(BH_PLATFORM_POSIX TRUE)
|
|
|
|
|
|
|
|
|
|
# Add platform dependent files
|
|
|
|
|
list(APPEND BH_SOURCE
|
|
|
|
|
src/file_posix.c
|
|
|
|
|
)
|
2024-04-14 22:32:58 +03:00
|
|
|
|
|
|
|
|
# Check multithreading support
|
2024-06-03 22:11:05 +03:00
|
|
|
check_include_file(pthread.h BH_USE_PTHREAD)
|
|
|
|
|
if(BH_USE_PTHREAD)
|
2024-04-14 22:32:58 +03:00
|
|
|
message(STATUS "Multithreading enabled")
|
2024-06-03 22:11:05 +03:00
|
|
|
list(APPEND BH_SOURCE
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread_posix.c
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Multithreading disabled")
|
2024-06-03 22:11:05 +03:00
|
|
|
list(APPEND BH_SOURCE
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread_null.c
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Platform: Unknown")
|
|
|
|
|
message(STATUS "Multithreading disabled")
|
2024-06-03 22:11:05 +03:00
|
|
|
list(APPEND BH_SOURCE
|
2024-04-14 22:32:58 +03:00
|
|
|
src/thread_null.c
|
2024-06-03 22:11:05 +03:00
|
|
|
src/file_null.c
|
2024-04-14 22:32:58 +03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Configure library
|
|
|
|
|
configure_file(include/bh/config.in include/bh/config.h)
|
|
|
|
|
|
2024-04-13 14:52:29 +03:00
|
|
|
# Library
|
2024-06-03 22:11:05 +03:00
|
|
|
add_library(bhlib STATIC ${BH_SOURCE} ${BH_HEADER})
|
|
|
|
|
target_include_directories(bhlib PUBLIC ${BH_INCLUDE_DIRS})
|
2024-04-13 14:52:29 +03:00
|
|
|
|
|
|
|
|
# Runtime definition
|
|
|
|
|
add_executable(main
|
|
|
|
|
main.c
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
target_link_libraries(main bhlib)
|
|
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
add_subdirectory(unit)
|
|
|
|
|
add_subdirectory(tests)
|