forked from GerHobbelt/pthread-win32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
93 lines (76 loc) · 2.89 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
cmake_minimum_required(VERSION 2.8...3.14)
project(
cthread
VERSION 4.1.0.5
DESCRIPTION "Emulated C11 threads, compatibility C11 atomics, with custom malloc replacement."
HOMEPAGE_URL "https://github.com/zelang-dev/cthread"
LANGUAGES C
)
set(CMAKE_C_STANDARD 90)
include(CMakeDependentOption)
include(GNUInstallDirs)
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
if(WIN32)
if($ENV{Platform} STREQUAL x86)
message("Building Windows x86-32bit")
add_definitions(-D_WIN32_PLATFORM_X86=1)
endif()
endif()
set(CMAKE_CONFIGURATION_TYPES=Debug;Release)
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/built")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
cmake_dependent_option(BUILD_TESTING
"Build the unit tests when BUILD_TESTING is enabled and we are the root project" OFF
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
option(BUILD_SHARED_LIBS "Build the library as a shared (dynamically-linked) " OFF)
add_definitions(-DENABLE_OVERRIDE=1)
set(cthread_files rpmalloc.c cthread.c)
if(BUILD_SHARED_LIBS)
add_library(cthread SHARED ${cthread_files})
else()
add_library(cthread STATIC ${cthread_files})
add_definitions(-DPTW32_STATIC_LIB=1)
endif()
if(UNIX)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -D ENABLE_ASSERTS=1 ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer -Wno-return-type")
find_package(Threads)
target_link_libraries(cthread PUBLIC ${CMAKE_THREAD_LIBS_INIT} atomic)
else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /D ENABLE_ASSERTS=1 ")
add_definitions(-DPTW32_CLEANUP_SEH=1 -D_CRT_SECURE_NO_DEPRECATE)
add_definitions("/wd4244 /wd4267 /wd4033 /wd4715")
add_subdirectory(deps)
target_include_directories(cthread AFTER PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(cthread PUBLIC pthreadVSE3)
endif()
set_property(TARGET cthread PROPERTY POSITION_INDEPENDENT_CODE True)
enable_testing()
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
set(_fmt TGZ)
if(WIN32)
set(_fmt ZIP)
endif()
set(CPACK_GENERATOR ${_fmt})
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_NUGET_COMPONENT_INSTALL ON)
set(CPACK_WIX_COMPONENT_INSTALL ON)
set(CPACK_NSIS_MODIFY_PATH ON)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_PACKAGE_VENDOR "https://github.com/zelang-dev/cthread")
include(CPack)
set(CMAKE_INSTALL_CONFIG_NAME ${CMAKE_BUILD_TYPE})
install(TARGETS ${cthread} DESTINATION lib)
install(FILES cthread.h rpmalloc.h catomic.h DESTINATION include )
if(WIN32)
install(DIRECTORY include/ DESTINATION include )
endif()