-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeMakefile.cmake
129 lines (100 loc) · 2.93 KB
/
MeMakefile.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.0)
macro(add_compile_options)
endmacro(add_compile_options)
macro(add_custom_command)
endmacro(add_custom_command)
macro(add_custom_target)
endmacro(add_custom_target)
macro(add_dependencies)
endmacro(add_dependencies)
macro(add_executable)
endmacro(add_executable)
macro(add_library)
endmacro(add_library)
macro(add_subdirectory)
endmacro(add_subdirectory)
macro(configure_file)
endmacro(configure_file)
macro(include_directories)
endmacro(include_directories)
macro(install)
endmacro(install)
macro(project)
endmacro(project)
macro(set_property)
endmacro(set_property)
macro(set_target_properties)
endmacro(set_target_properties)
macro(target_include_directories)
endmacro(target_include_directories)
macro(target_link_libraries)
endmacro(target_link_libraries)
macro(try_compile)
endmacro(try_compile)
function(me_makefile_make target)
if(NOT TARGET)
set(TARGET x64-linux)
endif()
if(NOT BUILD_TYPE)
set(BUILD_TYPE Debug)
endif()
string(TOLOWER ${BUILD_TYPE} BUILD_TYPE_NAME)
set(TARGET_DIR "${ME_ROOT_DIR}/target/${TARGET}-${BUILD_TYPE_NAME}")
set(BUILD_DIR "${ME_ROOT_DIR}/build/${TARGET}-${BUILD_TYPE_NAME}")
if(CLEAN)
if (NOT x$ENV{DIST} STREQUAL x)
set(DISTCLEAN ON)
else()
message(STATUS "Clear directory ${BUILD_DIR}/${target}")
file(REMOVE_RECURSE "${BUILD_DIR}/${target}")
return()
endif()
endif()
if(DISTCLEAN)
message(STATUS "Clear directory ${BUILD_DIR}")
file(REMOVE_RECURSE "${BUILD_DIR}")
return()
endif()
file(MAKE_DIRECTORY "${BUILD_DIR}")
if (NOT x$ENV{DIST} STREQUAL x)
set(ENV{ALL} 1)
endif()
find_program(Ninja NAMES ninja ninja-build)
if(Ninja STREQUAL Ninja-NOTFOUND)
message(STATUS "Ninja not found, use make instead.")
else()
message(STATUS "Found Ninja: ${Ninja}")
set(ME_GENERATOR "-GNinja")
endif()
get_filename_component(STDOUT /proc/self/fd/1 REALPATH)
if(EXISTS ${STDOUT})
set(OUTPUT_FILE OUTPUT_FILE ${STDOUT})
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} ${ME_GENERATOR}
"-DCMAKE_TOOLCHAIN_FILE=${ME_CMAKE_DIR}/MeToolchain.cmake"
"-DWIMAL_TARGET=${TARGET}"
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX=${TARGET_DIR}"
"-DME_EXTRA_PROJECTS=${target}"
"${ME_ROOT_DIR}"
${OUTPUT_FILE}
WORKING_DIRECTORY "${BUILD_DIR}"
RESULT_VARIABLE SUCCESS
)
if(NOT SUCCESS EQUAL 0)
return()
endif()
if (x$ENV{DIST} STREQUAL x)
if(ME_INSTALL)
set(target install-${target})
else()
set(target ${target}-)
endif()
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} --build . --target ${target}
${OUTPUT_FILE}
WORKING_DIRECTORY "${BUILD_DIR}"
)
endfunction(me_makefile_make)