-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
154 lines (123 loc) · 5.25 KB
/
CMakeLists.txt
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
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE)
message(STATUS "No build type specified, defaulting to MinSizeRel.")
endif()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (get_version)
message(STATUS "Generator ......... ${CMAKE_GENERATOR}")
message(STATUS "Build Type ........ ${CMAKE_BUILD_TYPE}")
message(STATUS "Version ........... ${PTHREADS4W_VERSION}")
project(pthreads4w VERSION ${PTHREADS4W_VERSION} LANGUAGES C)
set(PTW32_VER ${PROJECT_VERSION_MAJOR}${EXTRAVERSION})
set(CMAKE_DEBUG_POSTFIX d)
# Uncomment this if config.h defines RETAIN_WSALASTERROR
#set(XLIBS wsock32.lib)
include_directories(.)
#################################
# Target Arch #
#################################
include (target_arch)
get_target_arch(TARGET_ARCH)
if(${TARGET_ARCH} STREQUAL "ARM")
add_definitions(-D__PTW32_ARCHARM -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
elseif(${TARGET_ARCH} STREQUAL "ARM64")
add_definitions(-D__PTW32_ARCHARM64 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
elseif(${TARGET_ARCH} STREQUAL "x86_64")
add_definitions(-D__PTW32_ARCHAMD64)
elseif(${TARGET_ARCH} STREQUAL "x86")
add_definitions(-D__PTW32_ARCHX86)
elseif(${TARGET_ARCH} STREQUAL "x64")
add_definitions(-D__PTW32_ARCHX64)
else()
MESSAGE(ERROR "\"${TARGET_ARCH}\" not supported in version.rc")
endif()
message(STATUS "Target ............ ${TARGET_ARCH}")
if(MSVC)
message(STATUS "MSVC Version ...... ${MSVC_VERSION}")
endif()
#################################
# Install Path #
#################################
if(DIST_ROOT)
set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}")
else()
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/PTHREADS-BUILT")
endif()
message(STATUS "Install Path ${CMAKE_INSTALL_PREFIX}")
set(DLLDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/bin)
set(LIBDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/lib)
set(HDRDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/include)
set(TESTDEST ${CMAKE_INSTALL_PREFIX}/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/test)
#################################
# Defs #
#################################
add_definitions(-D__PTW32_BUILD_INLINED)
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /errorReport:none /nologo ")
# C++ Exceptions
# (Note: If you are using Microsoft VC++6.0, the library needs to be built
# with /EHa instead of /EHs or else cancellation won't work properly.)
if(MSVC_VERSION EQUAL 1200)
set(VCEFLAGS "/EHa /TP ")
else()
set(VCEFLAGS "/EHs /TP ")
endif()
add_definitions(-DHAVE_CONFIG_H -D__PTW32_RC_MSC)
endif()
# Update filename with proper version info
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
#################################
# Libraries #
#################################
set(targ_suffix "")
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(targ_suffix ${CMAKE_DEBUG_POSTFIX})
endif()
macro(shared_lib type def)
set(targ pthread${type}${PTW32_VER})
add_library(${targ} SHARED pthread.c ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
message(STATUS ${targ})
target_compile_definitions(${targ} PUBLIC "-D${def}")
if(${type} STREQUAL "VCE")
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targ}${targ_suffix}.dll DESTINATION ${DLLDEST})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
endif()
endmacro()
macro(static_lib type def)
set(targ libpthread${type}${PTW32_VER})
add_library(${targ} STATIC pthread.c)
message(STATUS ${targ})
target_compile_definitions(${targ} PUBLIC "-D${def}" -D__PTW32_STATIC_LIB)
if(${type} STREQUAL "VCE")
set_target_properties(${targ} PROPERTIES COMPILE_FLAGS ${VCEFLAGS})
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targ}${targ_suffix}.lib DESTINATION ${LIBDEST})
endif()
endmacro()
shared_lib ( VCE __PTW32_CLEANUP_CXX )
shared_lib ( VSE __PTW32_CLEANUP_SEH )
shared_lib ( VC __PTW32_CLEANUP_C )
static_lib ( VCE __PTW32_CLEANUP_CXX )
static_lib ( VSE __PTW32_CLEANUP_SEH )
static_lib ( VC __PTW32_CLEANUP_C )
#################################
# Install #
#################################
install(FILES _ptw32.h pthread.h sched.h semaphore.h DESTINATION ${HDRDEST})
#################################
# Test #
#################################
include (CTest)
if(NOT CMAKE_CROSSCOMPILING AND BUILD_TESTING)
add_subdirectory(tests)
endif()