-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClangModules.in.cmake
95 lines (75 loc) · 3.42 KB
/
ClangModules.in.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
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
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
message(STATUS "No python interpreter found. Can't setup ClangModules without!")
endif()
if(ClangModules_WithoutClang)
set(ClangModules_ClanglessArg "--clangless")
endif()
set(ClangModules_IsClang NO)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(ClangModules_IsClang YES)
endif()
if(PYTHONINTERP_FOUND)
if(ClangModules_WithoutClang OR ClangModules_IsClang)
cmake_minimum_required(VERSION 3.1)
set(ClangModules_UNPACK_FOLDER "${CMAKE_BINARY_DIR}")
function(ClangModules_UnpackFiles)
##UNPACK_PLACEHOLDER
endfunction()
message(STATUS "Setting up ClangModules:")
ClangModules_UnpackFiles()
get_property(ClangModules_CURRENT_COMPILE_OPTIONS DIRECTORY PROPERTY COMPILE_OPTIONS)
set(ClangModules_IncArg ":")
get_property(ClangModules_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(inc ${ClangModules_dirs})
set(ClangModules_IncArg "${ClangModules_IncArg}:${inc}")
endforeach()
if(NOT ClangModules_CheckOnlyFor)
set(ClangModules_CheckOnlyFor ";")
endif()
if(NOT ClangModules_CustomModulemapFolders)
set(ClangModules_CustomModulemapFolders ";")
endif()
if(NOT ClangModules_RequiredModules)
set(ClangModules_RequiredModules ";")
endif()
if(NOT ClangModules_OutputVFSFile)
set(ClangModules_OutputVFSFile "-")
endif()
if(NOT ClangModules_ModulesCache)
set(ClangModules_ModulesCache "${CMAKE_BINARY_DIR}/pcm")
endif()
set(ClangModules_ClangInvocation "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${CMAKE_CXX_FLAGS} ${ClangModules_CURRENT_COMPILE_OPTIONS}")
execute_process(COMMAND ${PYTHON_EXECUTABLE}
"${ClangModules_UNPACK_FOLDER}/ClangModules.py"
--modulemap-dir "${ClangModules_UNPACK_FOLDER}"
--modulemap-dir "${ClangModules_CustomModulemapFolders}"
--output-dir "${ClangModules_UNPACK_FOLDER}"
-I "${ClangModules_IncArg}"
${ClangModules_ClanglessArg}
--vfs-output "${ClangModules_OutputVFSFile}"
--required-modules "${ClangModules_RequiredModules}"
--check-only "${ClangModules_CheckOnlyFor}"
--log "${CMAKE_BINARY_DIR}/ClangModules.log"
--invocation "${ClangModules_ClangInvocation}"
WORKING_DIRECTORY "${ClangModules_UNPACK_FOLDER}"
RESULT_VARIABLE ClangModules_py_exitcode
OUTPUT_VARIABLE ClangModules_CXX_FLAGS_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT "${ClangModules_py_exitcode}" EQUAL 0)
message(FATAL_ERROR "ClangModules failed with exit code ${ClangModules_py_exitcode}!")
endif()
message(STATUS "Done setting up ClangModules!")
if(ClangModules_ExtraFlags)
set(ClangModules_CXX_FLAGS "${ClangModules_CXX_FLAGS_RAW} ${ClangModules_EXTRA_FLAGS} -fmodules-cache-path=${ClangModules_ModulesCache}")
else()
set(ClangModules_CXX_FLAGS "${ClangModules_CXX_FLAGS_RAW} -fmodules-cache-path=${ClangModules_ModulesCache}")
endif()
string(REPLACE "-fcxx-modules" "" ClangModules_C_FLAGS "${ClangModules_CXX_FLAGS}")
if(ClangModules_IsClang AND NOT ClangModules_WithoutClang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ClangModules_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ClangModules_CXX_FLAGS}")
endif()
endif()
endif()