Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CMakeLists.txt - github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34e66e7bdfcc5b4c9ab42d0a546a6f96d42568c6 (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
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
include(cmake/QuickCppLibBootstrap.cmake)
include(QuickCppLibRequireOutOfSourceBuild)
include(QuickCppLibUtils)
include(QuickCppLibPolicies)

# Parse the version we tell cmake directly from the version header file
ParseProjectVersionFromHpp("${CMAKE_CURRENT_SOURCE_DIR}/include/afio/version.hpp" VERSIONSTRING)
# Sets the usual PROJECT_NAME etc
project(afio VERSION ${VERSIONSTRING} LANGUAGES C CXX)
# Also set a *cmake* namespace for this project
set(PROJECT_NAMESPACE)
# Setup this cmake environment for this project
include(QuickCppLibSetupProject)
if(NOT PROJECT_IS_DEPENDENCY)
  # This file should be updated with the last git SHA next commit
  UpdateRevisionHppFromGit("${CMAKE_CURRENT_SOURCE_DIR}/include/afio/revision.hpp")
endif()
# Find my library dependencies
find_quickcpplib_library(quickcpplib 1.0 REQUIRED)
find_quickcpplib_library(outcome 2.0 REQUIRED)
find_quickcpplib_library(kerneltest 1.0 REQUIRED)
if(WIN32)
  add_subdirectory("include/afio/ntkernel-error-category" EXCLUDE_FROM_ALL)
endif()

# Make the standard static and shared libraries, and if supported by this compiler, C++ modules
# for both static and shared libraries as well. For the non-C++ module variants, makes the
# interface headers into precompiled headers. Only builds all of them if this is the topmost
# CMakeLists, else built only if something upstream is dependent on one of them.
include(QuickCppLibMakeLibrary)
# Make an interface only library so dependent CMakeLists can bring in this header-only library
include(QuickCppLibMakeHeaderOnlyLibrary)

# Create a custom doxygen generation target
include(QuickCppLibMakeDoxygen)
# Set the standard definitions for these libraries and bring in the all_* helper functions
include(QuickCppLibApplyDefaultDefinitions)
# Do we have the Coroutines TS?
function(CheckCXXHasCoroutines iter flags)
  set(CMAKE_REQUIRED_FLAGS "${flags}")
  check_cxx_source_compiles("
#include <future>
std::future<int> g() { co_return 0; }
int main() { return g().get(); }
" CXX_HAS_COROUTINES${iter})
  set(CXX_HAS_COROUTINES${iter} ${CXX_HAS_COROUTINES${iter}} PARENT_SCOPE)
endfunction()
include(CheckCXXSourceCompiles)
if(MSVC)
  CheckCXXHasCoroutines(_MSVC "/await")
  if(CXX_HAS_COROUTINES_MSVC)
    all_compile_options(PUBLIC "/await")
    all_compile_definitions(PUBLIC "__cpp_coroutines")
  endif()
endif()
if(CLANG OR GCC)
  CheckCXXHasCoroutines(_CLANG_GCC "-std=c++14 -fcoroutines-ts")
  if(CXX_HAS_COROUTINES_CLANG_GCC)
    all_compile_options(PUBLIC "-fcoroutines-ts")
    all_compile_definitions(PUBLIC "__cpp_coroutines")
  endif()
endif()

# Set the C++ features this library requires
all_compile_features(PUBLIC
  # cxx_exceptions                        ## Annoyingly not supported by cmake 3.6
  cxx_alias_templates
  cxx_variadic_templates
  cxx_noexcept
  cxx_constexpr
  cxx_lambda_init_captures
  cxx_attributes
  cxx_generic_lambdas
)
if(NOT MSVC OR CMAKE_VERSION VERSION_GREATER 3.59)
  all_compile_features(PUBLIC
    cxx_variable_templates
  )
endif()
# Set the library dependencies this library has
all_link_libraries(PUBLIC quickcpplib::hl outcome::hl Threads::Threads)
# Set the system dependencies this library has
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  find_library(libstdcxx_stdcxxfs stdc++fs)
  if(libstdcxx_stdcxxfs MATCHES "NOTFOUND")
    set(libstdcxx_stdcxxfs -lstdc++fs)
  endif()
  all_link_libraries(PUBLIC ${libstdcxx_stdcxxfs} rt)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR APPLE)
  find_library(libcxx_cxxexperimental c++experimental)
  all_link_libraries(PUBLIC ${libcxx_cxxexperimental})
endif()
# Set any macros this library requires
if(WIN32)
  all_compile_definitions(PRIVATE _WIN32_WINNT=0x600)  ## Target WinVista
  target_link_libraries(afio_dl PUBLIC ntkernel-error-category::dl)
  target_link_libraries(afio_sl PUBLIC ntkernel-error-category::sl)
endif()
# Anyone using the static or dynamic libraries is not using the header only variant
foreach(lib afio_sl afio_dl)
  target_compile_definitions(${lib} INTERFACE AFIO_HEADERS_ONLY=0) 
  target_compile_definitions(${lib} PRIVATE AFIO_SOURCE=1) 
endforeach()

# For all possible configurations of this library, add each test
include(QuickCppLibMakeStandardTests)
# For each test target, link to kerneltest
foreach(test_target ${afio_TEST_TARGETS})
  target_link_libraries(${test_target} PRIVATE kerneltest::hl)
endforeach()
if(MSVC)
  foreach(test_target ${afio_TEST_TARGETS})
    target_compile_options(${test_target} PRIVATE /wd4503)  ## decorated name length exceeded
  endforeach()
endif()

# Cache this library's auto scanned sources for later reuse
include(QuickCppLibCacheLibrarySources)

# Make available this library for install and export
include(QuickCppLibMakeInstall)
include(QuickCppLibMakeExport)