Skip to content

Commit 14a830f

Browse files
author
Stepan Dyatkovskiy
committed
C++ Levitation, cmake: Fixed llvm#36, added cmake sample for driver use.
1 parent 45be98b commit 14a830f

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
project("cppl-sandbox")
2+
cmake_minimum_required (VERSION 2.6)
3+
4+
include(log.cmake)
5+
include(file.cmake)
6+
7+
# set(LEVITATION_LOG_LEVEL ${LEVITATION_TRACE_LEVEL})
8+
9+
auxSources(${CMAKE_SOURCE_DIR} SOURCES)
10+
11+
# Path to cppl compiler
12+
set(CPPL "/Users/stepan/projects/shared/toolchains/llvm.git.darwin-debug-x86_64/install/bin/cppl")
13+
14+
set(BUILD_DIR ${PROJECT_BINARY_DIR}/build)
15+
16+
set(EXECUTABLE "sandbox.out")
17+
18+
set_property(DIRECTORY APPEND PROPERTY
19+
ADDITIONAL_MAKE_CLEAN_FILES
20+
${BUILD_DIR} ${EXECUTABLE}
21+
)
22+
23+
set(COMPILE_COMMAND
24+
${CPPL}
25+
-root=${CMAKE_SOURCE_DIR}
26+
-buildRoot=${BUILD_DIR}
27+
-o ${EXECUTABLE}
28+
)
29+
30+
add_custom_command(
31+
OUTPUT ${EXECUTABLE}
32+
DEPENDS ${SOURCES}
33+
COMMAND ${COMPILE_COMMAND}
34+
)
35+
36+
add_custom_target(
37+
build ALL
38+
DEPENDS
39+
${EXECUTABLE}
40+
)
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
macro(subDirList result curdir)
2+
file(GLOB children ${curdir} ${curdir}/*)
3+
set(dirlist "")
4+
foreach(child ${children})
5+
if(IS_DIRECTORY ${child})
6+
list(APPEND dirlist ${child})
7+
endif()
8+
endforeach()
9+
list(REMOVE_ITEM dirlist "${curdir}")
10+
set(${result} ${dirlist})
11+
endmacro()
12+
13+
macro(subDirListMask result curdir mask)
14+
file(GLOB children ${curdir} ${curdir}/${mask})
15+
set(dirlist "")
16+
foreach(child ${children})
17+
if(IS_DIRECTORY ${child})
18+
list(APPEND dirlist ${child})
19+
endif()
20+
endforeach()
21+
list(REMOVE_ITEM dirlist "${curdir}")
22+
set(${result} ${dirlist})
23+
endmacro()
24+
25+
macro(replaceExtension newPathVar oldPath newExtension)
26+
string(FIND ${oldPath} "." found REVERSE)
27+
if (NOT (${found} EQUAL -1))
28+
string(SUBSTRING ${oldPath} 0 "${found}-1" ${newPathVar})
29+
else()
30+
set(${newPathVar} ${oldPath})
31+
endif()
32+
33+
set(${newPathVar} "${${newPathVar}}.${newExtension}")
34+
35+
endmacro()
36+
37+
macro(setupOutputFile newPathVar sourceFile newExtension)
38+
replaceExtension(${newPathVar}
39+
${sourceFile} ${newExtension}
40+
)
41+
42+
replaceParent(${newPathVar}
43+
${${newPathVar}}
44+
${CMAKE_SOURCE_DIR}
45+
${PROJECT_BINARY_DIR}
46+
)
47+
endmacro()
48+
49+
macro(createSubDirFor file)
50+
get_filename_component(fileDir ${file} DIRECTORY)
51+
if(NOT(EXISTS ${fileDir}))
52+
trace("Creating directory ${fileDir}")
53+
file(MAKE_DIRECTORY ${fileDir})
54+
endif()
55+
endmacro()
56+
57+
macro(replaceParent newPathVar oldPath oldParent newParent)
58+
string(REPLACE ${oldParent} ${newParent} ${newPathVar} ${oldPath} )
59+
endmacro()
60+
61+
macro(filesListMask result curdir mask)
62+
trace("Looking for ${mask} files in ${curdir}...")
63+
file(GLOB children ${curdir} ${curdir}/${mask})
64+
set(dirlist "")
65+
foreach(child ${children})
66+
if(NOT (IS_DIRECTORY ${child}))
67+
trace("Found ${child}")
68+
list(APPEND dirlist ${child})
69+
endif()
70+
endforeach()
71+
list(REMOVE_ITEM dirlist "${curdir}")
72+
set(${result} ${${result}} ${dirlist})
73+
endmacro()
74+
75+
macro(subDirListRecursive result curdir)
76+
set(dirlist "")
77+
set(dirlist2 "")
78+
subDirList(dirlist ${curdir})
79+
list(LENGTH dirlist current)
80+
list(LENGTH dirlist2 new)
81+
set(${result} ${dirlist})
82+
while(NOT (${current} EQUAL ${new}))
83+
set(dirlist2 "")
84+
foreach(d ${dirlist})
85+
if (NOT (${d} STREQUAL ${curdir}) AND
86+
NOT (${d} STREQUAL ${PROJECT_BINARY_DIR})
87+
)
88+
subDirList(newDirList ${d})
89+
set(dirlist2 ${dirlist2} ${newDirList})
90+
endif()
91+
endforeach()
92+
set(tmp ${dirlist2})
93+
set(dirlist2 ${dirlist})
94+
set(dirlist ${tmp})
95+
list(LENGTH dirlist current)
96+
list(LENGTH dirlist2 new)
97+
set(${result} ${${result}} ${dirlist})
98+
endwhile()
99+
endmacro()
100+
101+
macro(auxSources dir sourcesVar)
102+
set(newSources "")
103+
aux_source_directory(${dir} newSources)
104+
trace("Scanning sources at ${dir}")
105+
trace("Found sources: ${newSources}")
106+
set (${sourcesVar} ${${sourcesVar}} ${newSources})
107+
endmacro()
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
set(LEVITATION_ERROR_LEVEL 0)
2+
set(LEVITATION_WARNING_LEVEL 1)
3+
set(LEVITATION_INFO_LEVEL 2)
4+
set(LEVITATION_DEBUG_LEVEL 3)
5+
set(LEVITATION_TRACE_LEVEL 4)
6+
7+
if (NOT (DEFINED LEVITATION_LOG_LEVEL))
8+
set(LEVITATION_LOG_LEVEL ${LEVITATION_INFO_LEVEL})
9+
endif()
10+
11+
macro(error msg)
12+
if (NOT (LEVITATION_LOG_LEVEL LESS ${LEVITATION_ERROR_LEVEL}))
13+
message(FATAL_ERROR "ERROR: ${msg}")
14+
endif()
15+
endmacro()
16+
17+
macro(warning msg)
18+
if (NOT (LEVITATION_LOG_LEVEL LESS ${LEVITATION_WARNING_LEVEL}))
19+
message(WARNING: "${msg}")
20+
endif()
21+
endmacro()
22+
23+
24+
macro(info msg)
25+
if (NOT (LEVITATION_LOG_LEVEL LESS ${LEVITATION_INFO_LEVEL}))
26+
message(STATUS "${msg}")
27+
endif()
28+
endmacro()
29+
30+
macro(debug msg)
31+
if (NOT (LEVITATION_LOG_LEVEL LESS ${LEVITATION_DEBUG_LEVEL}))
32+
message("DEBUG: ${msg}")
33+
endif()
34+
endmacro()
35+
36+
macro(trace msg)
37+
if (NOT (LEVITATION_LOG_LEVEL LESS ${LEVITATION_TRACE_LEVEL}))
38+
message("TRACE: ${msg}")
39+
endif()
40+
endmacro()

0 commit comments

Comments
 (0)