blob: 299eda90add74948daea72b19fa543621b1e429e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
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)
# Project includes
include(CheckIPOSupported)
include(CheckIncludeFile)
include(CheckSymbolExists)
# Project settings
option(BH_PLATFORM_THREADS "Enable multithreading support" TRUE)
# Check for IPO/LTO
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
set(BH_SOURCE
src/algo.c
src/buffer.c
src/hashmap.c
src/queue.c
src/thread.c
src/io.c
src/deflate.c
)
set(BH_HEADER
include/bh/bh.h
include/bh/platform.h
include/bh/buffer.h
include/bh/algo.h
include/bh/hashmap.h
include/bh/queue.h
include/bh/thread.h
include/bh/io.h
include/bh/deflate.h
)
set(BH_INCLUDE_DIRS
include
${PROJECT_BINARY_DIR}/include
)
# Determine platform
if(WIN32)
message(STATUS "Platform - Win32")
set(BH_PLATFORM_WIN TRUE)
option(BH_THREADS_WINXP "Enable threading support for Windows XP" FALSE)
# Add platform dependent files
list(APPEND BH_SOURCE
src/file_win.c
)
# Check multithreading support
if(BH_PLATFORM_THREADS)
check_symbol_exists(_beginthread process.h BH_PLATFORM_THREADS)
endif()
if(BH_PLATFORM_THREADS)
message(STATUS "Multithreading enabled")
list(APPEND BH_SOURCE
src/thread_win.c
)
else()
message(STATUS "Multithreading disabled")
list(APPEND BH_SOURCE
src/thread_null.c
)
endif()
if(NOT BH_THREADS_WINXP)
add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA -DWINVER=_WIN32_WINNT_VISTA)
endif()
elseif(UNIX)
message(STATUS "Platform: Unix (Linux/BSD/MacOS X)")
set(BH_PLATFORM_POSIX TRUE)
# Add platform dependent files
list(APPEND BH_SOURCE
src/file_posix.c
)
# Check multithreading support
if(BH_PLATFORM_THREADS)
check_include_file(pthread.h BH_PLATFORM_THREADS)
endif()
if(BH_PLATFORM_THREADS)
message(STATUS "Multithreading enabled")
list(APPEND BH_SOURCE
src/thread_posix.c
)
else()
message(STATUS "Multithreading disabled")
list(APPEND BH_SOURCE
src/thread_null.c
)
endif()
else()
message(STATUS "Platform: Unknown")
message(STATUS "Multithreading disabled")
list(APPEND BH_SOURCE
src/thread_null.c
src/file_null.c
)
endif()
# Configure library
configure_file(include/bh/config.in include/bh/config.h)
configure_file(include/bh/internal/config.in include/bh/internal/config.h)
# Library
add_library(bhlib STATIC ${BH_SOURCE} ${BH_HEADER})
target_include_directories(bhlib PUBLIC ${BH_INCLUDE_DIRS})
# Enable warnings and pedantics
if(MSVC)
target_compile_options(bhlib PRIVATE /W4)
else()
target_compile_options(bhlib PRIVATE -Wall -Wextra -Wpedantic)
endif()
# Runtime definition
add_executable(main
main.c
)
target_link_libraries(main bhlib)
# Tests
add_subdirectory(unit)
add_subdirectory(tests)
|