This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forward_headers.cmake
52 lines (47 loc) · 1.8 KB
/
forward_headers.cmake
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
#!/usr/bin/env cmake -P
#
# Copyright (C) 2012 Daniel Pfeifer <[email protected]>
#
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
# On Windows, symlinks are available since Vista, but they require the
# /Create Symbolic Link/ privilege, which only administrators have by default.
if(CMAKE_HOST_WIN32)
set(test_file "${CMAKE_CURRENT_LIST_DIR}/symlinktest")
file(TO_NATIVE_PATH "${CMAKE_CURRENT_LIST_FILE}" file)
file(TO_NATIVE_PATH "${test_file}" target)
execute_process(COMMAND cmd /C mklink "${target}" "${file}" OUTPUT_QUIET)
if(EXISTS "${test_file}")
set(MKLINK_WORKING TRUE)
else()
set(MKLINK_WORKING FALSE)
message(STATUS "Symlinks are NOT supported.")
endif()
endif()
# Make a header file available from another path.
#
# This function creates symlinks where available. As a fallback it simply
# creates a file at the target position that `#include`s the appropriate header.
function(forward_header file target)
get_filename_component(directory "${target}" PATH)
file(MAKE_DIRECTORY "${directory}")
if(NOT CMAKE_HOST_WIN32)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${file}" "${target}")
elseif(MKLINK_WORKING)
file(TO_NATIVE_PATH "${target}" target)
file(TO_NATIVE_PATH "${file}" file)
execute_process(COMMAND cmd /C mklink "${target}" "${file}" OUTPUT_QUIET)
else()
file(WRITE "${target}" "#include \"${file}\"\n")
endif()
endfunction()
file(REMOVE_RECURSE boost)
file(GLOB_RECURSE headers
"libs/*/include/boost/*.?pp"
"libs/*/*/include/boost/*.?pp"
)
foreach(file ${headers})
string(REGEX REPLACE ".*//include//boost//" "" relative "${file}")
forward_header("${file}" "${CMAKE_CURRENT_LIST_DIR}/boost/${relative}")
endforeach()