-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
121 lines (101 loc) · 4.64 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
cmake_minimum_required(VERSION 3.9)
project(BetterThreads VERSION 1.0)
option(COVERAGE "Enable coverage reporting" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20)
message(FATAL_ERROR "MSVC version must be at least 19.20!")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.2)
message(FATAL_ERROR "GCC version must be at least 10.2!")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
message(FATAL_ERROR "Clang version must be at least 11.0!")
endif()
else()
message(WARNING "You are using an unsupported compiler! MSVC, GCC and Clang are supported.")
endif()
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(LIBRARY_KIND STATIC)
elseif(COVERAGE)
set(LIBRARY_KIND STATIC)
else()
set(LIBRARY_KIND SHARED)
endif()
set(CMAKE_MACOSX_RPATH 1)
set(BUILD_SHARED_LIBS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT WIN32)
set(ANY_TARGET_WARN all extra pedantic sign-conversion cast-qual disabled-optimization
init-self missing-include-dirs sign-promo switch-default undef redundant-decls
strict-aliasing unused-parameter shadow error)
foreach(WARN ${ANY_TARGET_WARN})
add_compile_options(-W${WARN})
endforeach()
else()
add_compile_options(/WX)
endif()
include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZET)
message(STATUS "size_t size: ${SIZEOF_SIZET}")
check_type_size("long int" SIZEOF_LONG_INT)
message(STATUS "long int size: ${SIZEOF_LONG_INT}")
check_type_size("long long int" SIZEOF_LONG_LONG_INT)
message(STATUS "long long int size: ${SIZEOF_LONG_LONG_INT}")
find_package(Git)
if(GIT_FOUND)
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/.git) # Manages the case when an archive is used
execute_process(COMMAND git init WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND rm -Rf ${PROJECT_SOURCE_DIR}/submodules/conclog OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND git submodule add -f https://github.com/ariadne-cps/conclog submodules/conclog WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND rm -Rf ${PROJECT_SOURCE_DIR}/submodules/helper OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND git submodule add -f https://github.com/ariadne-cps/helper submodules/helper WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_QUIET ERROR_QUIET)
endif()
message(STATUS "Getting all submodules if not downloaded already...")
execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_QUIET ERROR_QUIET)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/submodules/conclog/CMakeLists.txt)
message(ERROR "ConcLog download failure")
else()
message(STATUS "ConcLog submodule found")
endif()
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/submodules/helper/CMakeLists.txt)
message(ERROR "Helper download failure")
else()
message(STATUS "Helper submodule found")
endif()
else()
message(FATAL_ERROR "Git not found, no submodules could be downloaded")
endif()
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/submodules/.symbolic)
execute_process(COMMAND mkdir ${PROJECT_SOURCE_DIR}/submodules/.symbolic)
message(STATUS "Created symbolic links directory for submodules")
endif()
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/submodules/.symbolic/conclog)
execute_process(COMMAND ln -s ${PROJECT_SOURCE_DIR}/submodules/conclog/include ${PROJECT_SOURCE_DIR}/submodules/.symbolic/conclog)
message(STATUS "Created symbolic link to ConcLog submodule")
endif()
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/submodules/.symbolic/helper)
execute_process(COMMAND ln -s ${PROJECT_SOURCE_DIR}/submodules/helper/include ${PROJECT_SOURCE_DIR}/submodules/.symbolic/helper)
message(STATUS "Created symbolic link to Helper submodule")
endif()
find_package(Threads REQUIRED)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/submodules/.symbolic)
if(NOT TARGET betterthreads)
add_subdirectory(src)
add_library(betterthreads ${LIBRARY_KIND} $<TARGET_OBJECTS:BETTERTHREADS_SRC>)
if(NOT TARGET tests)
if(COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
endif()
enable_testing()
add_subdirectory(test)
endif()
add_subdirectory(submodules)
target_link_libraries(betterthreads conclog helper ${CMAKE_THREAD_LIBS_INIT})
endif()