• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 Mike Dev
2# Copyright 2020 Andrey Semashev
3#
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
10cmake_minimum_required(VERSION 3.5)
11project(BoostFilesystem VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
12
13include(CheckCXXSourceCompiles)
14
15check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtim.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIM)
16check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtimensec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC)
17check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_stat_st_mtimespec.cpp>" BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC)
18if(WIN32)
19    # Note: We can't use the Boost::library targets here as they may not yet be included by the superproject when this CMakeLists.txt is included.
20    set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../..")
21    set(CMAKE_REQUIRED_LIBRARIES bcrypt)
22    check_cxx_source_compiles("#include <${CMAKE_CURRENT_SOURCE_DIR}/config/has_bcrypt.cpp>" BOOST_FILESYSTEM_HAS_BCRYPT)
23    unset(CMAKE_REQUIRED_LIBRARIES)
24    unset(CMAKE_REQUIRED_INCLUDES)
25endif()
26
27add_library(boost_filesystem
28    src/codecvt_error_category.cpp
29    src/exception.cpp
30    src/operations.cpp
31    src/directory.cpp
32    src/path.cpp
33    src/path_traits.cpp
34    src/portability.cpp
35    src/unique_path.cpp
36    src/utf8_codecvt_facet.cpp
37    src/windows_file_codecvt.cpp
38)
39
40add_library(Boost::filesystem ALIAS boost_filesystem)
41
42target_include_directories(boost_filesystem PUBLIC include)
43target_include_directories(boost_filesystem PRIVATE src)
44
45target_compile_definitions(boost_filesystem
46    PUBLIC
47        # NOTE:
48        # We deactivate autolinking, because cmake based builds don't need it
49        # and we don't implement name mangling for the library file anyway.
50        # Ususally the parent CMakeLists.txt file should already have globally defined BOOST_ALL_NO_LIB
51        BOOST_FILESYSTEM_NO_LIB
52        $<$<STREQUAL:$<TARGET_PROPERTY:boost_filesystem,TYPE>,SHARED_LIBRARY>:BOOST_FILESYSTEM_DYN_LINK=1>
53        $<$<STREQUAL:$<TARGET_PROPERTY:boost_filesystem,TYPE>,STATIC_LIBRARY>:BOOST_FILESYSTEM_STATIC_LINK=1>
54
55    PRIVATE
56        BOOST_FILESYSTEM_SOURCE
57)
58
59if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIM)
60    target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIM)
61endif()
62if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC)
63    target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIMENSEC)
64endif()
65if(BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC)
66    target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_MTIMESPEC)
67endif()
68
69target_link_libraries(boost_filesystem
70    PUBLIC
71        Boost::assert
72        Boost::config
73        Boost::container_hash
74        Boost::core
75        Boost::detail
76        Boost::io
77        Boost::iterator
78        Boost::smart_ptr
79        Boost::system
80        Boost::type_traits
81
82    PRIVATE
83        Boost::predef
84)
85
86if(WIN32)
87    if(BOOST_FILESYSTEM_HAS_BCRYPT)
88        target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_BCRYPT)
89        target_link_libraries(boost_filesystem PRIVATE bcrypt)
90    else()
91        target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_WINCRYPT)
92        if(NOT WINCE)
93            target_link_libraries(boost_filesystem PRIVATE advapi32)
94        else()
95            target_link_libraries(boost_filesystem PRIVATE coredll)
96        endif()
97    endif()
98
99    target_link_libraries(boost_filesystem
100        PRIVATE
101            Boost::winapi
102    )
103endif()
104