-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cmake
executable file
·165 lines (138 loc) · 5.67 KB
/
build.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/cmake -P
##########################################################################
# Copyright (C) 2011 Daniel Pfeifer <daniel@pfeifer-mail.de> #
# #
# 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 #
##########################################################################
# cmake -DBUILDDIR=../build -DTOOLCHAIN=vs9 -DBUILDSTEP=configure -P build.cmake
set(MAKE_COMMAND make -k)
set(GENERATOR "Unix Makefiles")
if(NOT DEFINED BUILDDIR)
set(BUILDDIR "${CMAKE_CURRENT_LIST_DIR}/build")
elseif(NOT IS_ABSOLUTE "${BUILDDIR}")
set(BUILDDIR "${CMAKE_CURRENT_LIST_DIR}/${BUILDDIR}")
endif()
if(CMAKE_HOST_WIN32 AND NOT DEFINED TOOLCHAIN)
if(EXISTS "$ENV{VS100COMNTOOLS}vsvars32.bat")
set(TOOLCHAIN vs10)
elseif(EXISTS "$ENV{VS90COMNTOOLS}vsvars32.bat")
set(TOOLCHAIN vs9)
elseif(EXISTS "$ENV{VS80COMNTOOLS}vsvars32.bat")
set(TOOLCHAIN vs8)
elseif(EXISTS "$ENV{VS71COMNTOOLS}vsvars32.bat")
set(TOOLCHAIN vs71)
endif()
endif(CMAKE_HOST_WIN32 AND NOT DEFINED TOOLCHAIN)
if(DEFINED TOOLCHAIN)
set(toolchain_file "${CMAKE_CURRENT_LIST_DIR}/toolchains/${TOOLCHAIN}.cmake")
if(EXISTS "${toolchain_file}")
include("${toolchain_file}")
set(toolchain_param "-DCMAKE_TOOLCHAIN_FILE=${toolchain_file}")
endif(EXISTS "${toolchain_file}")
endif(DEFINED TOOLCHAIN)
if(CMAKE_HOST_WIN32)
if(TOOLCHAIN STREQUAL "vs10")
set(VSVARS_BAT "%VS100COMNTOOLS%vsvars32.bat")
elseif(TOOLCHAIN STREQUAL "vs9")
set(VSVARS_BAT "%VS90COMNTOOLS%vsvars32.bat")
elseif(TOOLCHAIN STREQUAL "vs8")
set(VSVARS_BAT "%VS80COMNTOOLS%vsvars32.bat")
elseif(TOOLCHAIN STREQUAL "vs71" OR TOOLCHAIN STREQUAL "vs7.1")
set(VSVARS_BAT "%VS71COMNTOOLS%vsvars32.bat")
endif()
if(DEFINED VSVARS_BAT)
file(WRITE "${BUILDDIR}/vsvars.bat"
"@call \"${VSVARS_BAT}\"\n"
"@> vsvars.cmake echo set(ENV{PATH} \"%PATH:\\=\\\\%\")\n"
"@>>vsvars.cmake echo set(ENV{INCLUDE} \"%INCLUDE:\\=\\\\%\")\n"
"@>>vsvars.cmake echo set(ENV{LIB} \"%LIB:\\=\\\\%\")\n"
"@>>vsvars.cmake echo set(ENV{LIBPATH} \"%LIBPATH:\\=\\\\%\")\n"
)
execute_process(COMMAND "${BUILDDIR}/vsvars.bat"
WORKING_DIRECTORY "${BUILDDIR}"
OUTPUT_QUIET
)
include("${BUILDDIR}/vsvars.cmake")
set(GENERATOR "NMake Makefiles")
set(MAKE_COMMAND nmake /NOLOGO /K)
endif(DEFINED VSVARS_BAT)
endif(CMAKE_HOST_WIN32)
set(debug_dir "${BUILDDIR}/debug")
set(release_dir "${BUILDDIR}/release")
set(package_dir "${BUILDDIR}/package")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "aggregate")
file(MAKE_DIRECTORY "${debug_dir}")
file(MAKE_DIRECTORY "${release_dir}")
# TODO: dont aggregate sources during configure
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "aggregate")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "configure")
execute_process(COMMAND "${CMAKE_COMMAND}" "-G${GENERATOR}"
-DBOOST_UPDATE_SOURCE=1 # TODO: move to aggregate step
"${toolchain_param}" -DCMAKE_BUILD_TYPE=Debug
"${CMAKE_CURRENT_LIST_DIR}"
WORKING_DIRECTORY "${debug_dir}"
RESULT_VARIABLE debug_result
)
execute_process(COMMAND "${CMAKE_COMMAND}" "-G${GENERATOR}"
"${toolchain_param}" -DCMAKE_BUILD_TYPE=Release
"${debug_dir}/monolithic"
WORKING_DIRECTORY "${release_dir}"
RESULT_VARIABLE release_result
)
if(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
message(FATAL_ERROR "Configuring failed.")
endif(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "configure")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "build")
execute_process(COMMAND ${MAKE_COMMAND}
WORKING_DIRECTORY "${debug_dir}"
RESULT_VARIABLE debug_result
)
execute_process(COMMAND ${MAKE_COMMAND}
WORKING_DIRECTORY "${release_dir}"
RESULT_VARIABLE release_result
)
if(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
message(FATAL_ERROR "Building failed.")
endif(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "build")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "test")
execute_process(COMMAND ${MAKE_COMMAND} test
WORKING_DIRECTORY "${debug_dir}"
RESULT_VARIABLE debug_result
)
execute_process(COMMAND ${MAKE_COMMAND} test
WORKING_DIRECTORY "${release_dir}"
RESULT_VARIABLE release_result
)
if(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
message(FATAL_ERROR "Testing failed.")
endif(NOT debug_result EQUAL 0 OR NOT release_result EQUAL 0)
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "test")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "documentation")
execute_process(COMMAND ${MAKE_COMMAND} documentation
WORKING_DIRECTORY "${release_dir}"
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Generating of documentation failed.")
endif(NOT result EQUAL 0)
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "documentation")
if(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "package")
file(WRITE "${package_dir}/CPackConfig.cmake"
"include(\"${release_dir}/CPackConfig.cmake\")\n"
"set(CPACK_INSTALL_CMAKE_PROJECTS\n"
" \"${debug_dir};Boost;ALL;/\"\n"
" \"${release_dir};Boost;ALL;/\"\n"
" )\n"
)
execute_process(COMMAND cpack
WORKING_DIRECTORY "${package_dir}"
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Packaging failed.")
endif(NOT result EQUAL 0)
endif(NOT DEFINED BUILDSTEP OR BUILDSTEP STREQUAL "package")