]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | # Copyright 2019 Mike Dev |
1e59de90 | 2 | # Copyright 2020-2022 Andrey Semashev |
20effc67 | 3 | # |
92f5a8d4 TL |
4 | # Distributed under the Boost Software License, Version 1.0. |
5 | # See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt | |
6 | # | |
7 | # NOTE: CMake support for Boost.Filesystem is currently experimental at best | |
8 | # and the interface is likely to change in the future | |
9 | ||
20effc67 TL |
10 | cmake_minimum_required(VERSION 3.5) |
11 | project(BoostFilesystem VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) | |
12 | ||
13 | include(CheckCXXSourceCompiles) | |
92f5a8d4 | 14 | |
1e59de90 TL |
15 | set(BOOST_FILESYSTEM_NO_DEPRECATED OFF CACHE BOOL "Disable deprecated functionality of Boost.Filesystem") |
16 | set(BOOST_FILESYSTEM_DISABLE_SENDFILE OFF CACHE BOOL "Disable usage of sendfile API in Boost.Filesystem") | |
17 | set(BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE OFF CACHE BOOL "Disable usage of copy_file_range API in Boost.Filesystem") | |
18 | set(BOOST_FILESYSTEM_DISABLE_STATX OFF CACHE BOOL "Disable usage of statx API in Boost.Filesystem") | |
19 | set(BOOST_FILESYSTEM_DISABLE_GETRANDOM OFF CACHE BOOL "Disable usage of getrandom API in Boost.Filesystem") | |
20 | set(BOOST_FILESYSTEM_DISABLE_ARC4RANDOM OFF CACHE BOOL "Disable usage of arc4random API in Boost.Filesystem") | |
21 | set(BOOST_FILESYSTEM_DISABLE_BCRYPT OFF CACHE BOOL "Disable usage of BCrypt API in Boost.Filesystem") | |
22 | ||
23 | # Note: We can't use the Boost::library targets in the configure checks as they may not yet be included | |
24 | # by the superproject when this CMakeLists.txt is included. We also don't want to hardcode include paths | |
25 | # of the needed libraries and their dependencies, recursively, as this is too fragile and requires maintenance. | |
26 | # Instead, we collect include paths of all libraries and use them in the configure checks. This works faster | |
27 | # if there is a unified Boost include tree in the filesystem (i.e. if `b2 headers` was run or we're in the | |
28 | # official monolithic Boost distribution tree). | |
29 | include(cmake/BoostLibraryIncludes.cmake) | |
30 | ||
31 | set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/src" ${BOOST_LIBRARY_INCLUDES}) | |
32 | ||
33 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_attribute_init_priority.cpp>" BOOST_FILESYSTEM_HAS_INIT_PRIORITY) | |
34 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_cxx20_atomic_ref.cpp>" BOOST_FILESYSTEM_HAS_CXX20_ATOMIC_REF) | |
35 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_blksize.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE) | |
20effc67 TL |
36 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtim.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIM) |
37 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtimensec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC) | |
38 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtimespec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC) | |
1e59de90 TL |
39 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_birthtimensec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMENSEC) |
40 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_birthtimespec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMESPEC) | |
41 | if(NOT BOOST_FILESYSTEM_DISABLE_STATX) | |
42 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_statx.cpp>" BOOST_FILESYSTEM_HAS_STATX) | |
43 | if(NOT BOOST_FILESYSTEM_HAS_STATX) | |
44 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_statx_syscall.cpp>" BOOST_FILESYSTEM_HAS_STATX_SYSCALL) | |
45 | endif() | |
46 | endif() | |
47 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_fdopendir_nofollow.cpp>" BOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW) | |
48 | if(WIN32 AND NOT BOOST_FILESYSTEM_DISABLE_BCRYPT) | |
20effc67 TL |
49 | set(CMAKE_REQUIRED_LIBRARIES bcrypt) |
50 | check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_bcrypt.cpp>" BOOST_FILESYSTEM_HAS_BCRYPT) | |
51 | unset(CMAKE_REQUIRED_LIBRARIES) | |
20effc67 TL |
52 | endif() |
53 | ||
1e59de90 TL |
54 | unset(CMAKE_REQUIRED_INCLUDES) |
55 | ||
56 | set(BOOST_FILESYSTEM_SOURCES | |
92f5a8d4 TL |
57 | src/codecvt_error_category.cpp |
58 | src/exception.cpp | |
59 | src/operations.cpp | |
60 | src/directory.cpp | |
61 | src/path.cpp | |
62 | src/path_traits.cpp | |
63 | src/portability.cpp | |
64 | src/unique_path.cpp | |
65 | src/utf8_codecvt_facet.cpp | |
92f5a8d4 | 66 | ) |
1e59de90 TL |
67 | if(WIN32 OR CYGWIN) |
68 | list(APPEND BOOST_FILESYSTEM_SOURCES src/windows_file_codecvt.cpp) | |
69 | endif() | |
92f5a8d4 | 70 | |
1e59de90 | 71 | add_library(boost_filesystem ${BOOST_FILESYSTEM_SOURCES}) |
20effc67 | 72 | add_library(Boost::filesystem ALIAS boost_filesystem) |
92f5a8d4 | 73 | |
20effc67 TL |
74 | target_include_directories(boost_filesystem PUBLIC include) |
75 | target_include_directories(boost_filesystem PRIVATE src) | |
92f5a8d4 | 76 | |
20effc67 | 77 | target_compile_definitions(boost_filesystem |
92f5a8d4 TL |
78 | PUBLIC |
79 | # NOTE: | |
80 | # We deactivate autolinking, because cmake based builds don't need it | |
81 | # and we don't implement name mangling for the library file anyway. | |
82 | # Ususally the parent CMakeLists.txt file should already have globally defined BOOST_ALL_NO_LIB | |
83 | BOOST_FILESYSTEM_NO_LIB | |
84 | $<$<STREQUAL:$<TARGET_PROPERTY:boost_filesystem,TYPE>,SHARED_LIBRARY>:BOOST_FILESYSTEM_DYN_LINK=1> | |
85 | $<$<STREQUAL:$<TARGET_PROPERTY:boost_filesystem,TYPE>,STATIC_LIBRARY>:BOOST_FILESYSTEM_STATIC_LINK=1> | |
86 | ||
87 | PRIVATE | |
88 | BOOST_FILESYSTEM_SOURCE | |
89 | ) | |
90 | ||
1e59de90 TL |
91 | if(WIN32) |
92 | target_compile_definitions(boost_filesystem PRIVATE | |
93 | _SCL_SECURE_NO_WARNINGS | |
94 | _SCL_SECURE_NO_DEPRECATE | |
95 | _CRT_SECURE_NO_WARNINGS | |
96 | _CRT_SECURE_NO_DEPRECATE | |
97 | ) | |
98 | endif() | |
99 | ||
100 | if(WIN32 OR CYGWIN) | |
101 | target_compile_definitions(boost_filesystem PRIVATE | |
102 | BOOST_USE_WINDOWS_H | |
103 | WIN32_LEAN_AND_MEAN | |
104 | NOMINMAX | |
105 | ) | |
106 | endif() | |
107 | ||
108 | if(BOOST_FILESYSTEM_NO_DEPRECATED) | |
109 | target_compile_definitions(boost_filesystem PUBLIC BOOST_FILESYSTEM_NO_DEPRECATED) | |
110 | endif() | |
111 | ||
112 | if(BOOST_FILESYSTEM_HAS_INIT_PRIORITY) | |
113 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_INIT_PRIORITY) | |
114 | endif() | |
115 | ||
116 | if(BOOST_FILESYSTEM_DISABLE_SENDFILE) | |
117 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_SENDFILE) | |
118 | endif() | |
119 | if(BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE) | |
120 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_COPY_FILE_RANGE) | |
121 | endif() | |
122 | if(BOOST_FILESYSTEM_DISABLE_STATX) | |
123 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_STATX) | |
124 | endif() | |
125 | if(BOOST_FILESYSTEM_DISABLE_GETRANDOM) | |
126 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_GETRANDOM) | |
127 | endif() | |
128 | if(BOOST_FILESYSTEM_DISABLE_ARC4RANDOM) | |
129 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_ARC4RANDOM) | |
130 | endif() | |
131 | if(BOOST_FILESYSTEM_DISABLE_BCRYPT) | |
132 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_BCRYPT) | |
133 | endif() | |
134 | ||
135 | if(BOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE) | |
136 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE) | |
137 | endif() | |
20effc67 TL |
138 | if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIM) |
139 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIM) | |
140 | endif() | |
141 | if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC) | |
142 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC) | |
143 | endif() | |
144 | if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC) | |
145 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC) | |
146 | endif() | |
1e59de90 TL |
147 | if(BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMENSEC) |
148 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMENSEC) | |
149 | endif() | |
150 | if(BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMESPEC) | |
151 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_BIRTHTIMESPEC) | |
152 | endif() | |
153 | if(BOOST_FILESYSTEM_HAS_STATX) | |
154 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STATX) | |
155 | endif() | |
156 | if(BOOST_FILESYSTEM_HAS_STATX_SYSCALL) | |
157 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STATX_SYSCALL) | |
158 | endif() | |
159 | if(BOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW) | |
160 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW) | |
161 | endif() | |
20effc67 TL |
162 | |
163 | target_link_libraries(boost_filesystem | |
92f5a8d4 TL |
164 | PUBLIC |
165 | Boost::assert | |
166 | Boost::config | |
167 | Boost::container_hash | |
168 | Boost::core | |
169 | Boost::detail | |
170 | Boost::io | |
171 | Boost::iterator | |
172 | Boost::smart_ptr | |
173 | Boost::system | |
174 | Boost::type_traits | |
92f5a8d4 | 175 | |
92f5a8d4 | 176 | PRIVATE |
20effc67 | 177 | Boost::predef |
92f5a8d4 | 178 | ) |
20effc67 | 179 | |
1e59de90 TL |
180 | if(NOT BOOST_FILESYSTEM_HAS_CXX20_ATOMIC_REF) |
181 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF) | |
182 | target_link_libraries(boost_filesystem | |
183 | PRIVATE | |
184 | Boost::atomic | |
185 | ) | |
186 | endif() | |
187 | ||
20effc67 TL |
188 | if(WIN32) |
189 | if(BOOST_FILESYSTEM_HAS_BCRYPT) | |
190 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_BCRYPT) | |
191 | target_link_libraries(boost_filesystem PRIVATE bcrypt) | |
192 | else() | |
193 | target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_WINCRYPT) | |
194 | if(NOT WINCE) | |
195 | target_link_libraries(boost_filesystem PRIVATE advapi32) | |
196 | else() | |
197 | target_link_libraries(boost_filesystem PRIVATE coredll) | |
198 | endif() | |
199 | endif() | |
200 | ||
201 | target_link_libraries(boost_filesystem | |
202 | PRIVATE | |
203 | Boost::winapi | |
204 | ) | |
205 | endif() |