-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
275 lines (215 loc) · 11.1 KB
/
CMakeLists.txt
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
cmake_minimum_required(VERSION 3.10.2)
cmake_policy(SET CMP0048 NEW)
project(URBANoptCLI VERSION 0.13.0)
include(FindOpenStudioSDK.cmake)
get_target_property(os_cli_location openstudio::openstudio LOCATION)
set(os_cli_install_name "openstudio${CMAKE_EXECUTABLE_SUFFIX}")
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
if ( APPLE )
find_library(SECURITY_FRAMEWORK Security)
endif()
include(ExternalProject)
include(CPackComponent)
###############################################################################
# P R O J E C T V E R S I O N #
###############################################################################
# Project version information
set(PROJECT_VERSION_BUILD "Unknown" CACHE STRING "Build number") # git sha
find_package(Git)
if(NOT GIT_FOUND)
find_program(GIT_EXECUTABLE git HINTS "$ENV{LOCALAPPDATA}/Programs/git/bin" "C:/Program Files/Git/bin")
if(NOT GIT_EXECUTABLE_NOTFOUND)
set(GIT_FOUND TRUE)
endif()
endif()
if(GIT_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" "rev-parse" "--short=10" "HEAD"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
TIMEOUT 10
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE GIT_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${RESULT} EQUAL 0 AND NOT "${GIT_VERSION}" EQUAL "${PROJECT_VERSION_BUILD}")
set(PROJECT_VERSION_BUILD ${GIT_VERSION} CACHE STRING "Build number" FORCE) # git sha
endif()
get_filename_component(GIT_DIR "${GIT_EXECUTABLE}" DIRECTORY)
else()
set(GIT_DIR "")
endif()
# URBANopt version: Allows to add a pre1 tag as needed.
set(URBANOPT_CLI_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# TODO JM 2019-07-12: Comment out (or delete) if prerelease tag not needed
set(URBANOPT_CLI_PRERELEASE_TAG "")
if (NOT "${URBANOPT_CLI_PRERELEASE_TAG}" STREQUAL "")
message(STATUS "We have a prerelease tag set to '${URBANOPT_CLI_PRERELEASE_TAG}'")
set(URBANOPT_CLI_VERSION "${URBANOPT_CLI_VERSION}-${URBANOPT_CLI_PRERELEASE_TAG}")
else()
message(STATUS "We do not have a prerelease tag")
endif()
set(URBANOPT_CLI_LONG_VERSION "${URBANOPT_CLI_VERSION}.${PROJECT_VERSION_BUILD}")
message(STATUS "URBANOPT_CLI_VERSION=${URBANOPT_CLI_VERSION}")
message(STATUS "URBANOPT_CLI_LONG_VERSION=${URBANOPT_CLI_LONG_VERSION}")
###############################################################################
# B U I L D O P T I O N S #
###############################################################################
option(BUILD_PACKAGE "Build package" OFF)
###############################################################################
# D E P E N D E N C I E S #
###############################################################################
# Required dependencies
# CI will build and upload urbanopt-cli-gems to s3 at (TBD)
# need to update the MD5sum for each platform and url below
if(UNIX)
if(APPLE)
set(URBANOPT_CLI_GEMS_ZIP_FILENAME "urbanopt-cli-gems-20240709-darwin.tar.gz")
set(URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5 "b683bb30457904041567079ca4ff0fef")
else()
if (ARCH MATCHES "arm64")
set(URBANOPT_CLI_GEMS_ZIP_FILENAME "urbanopt-cli-gems-20240524-linux-arm.tar.gz")
set(URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5 "18915b55621ee755bf92c506b5cdba2a")
else()
set(URBANOPT_CLI_GEMS_ZIP_FILENAME "urbanopt-cli-gems-20240719-linux.tar.gz")
set(URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5 "54f27859ff66915f6b343b0b9731a39c")
endif()
endif()
elseif(WIN32)
if(CMAKE_CL_64)
set(URBANOPT_CLI_GEMS_ZIP_FILENAME "urbanopt-cli-gems-20240709-windows.tar.gz")
set(URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5 "d34b30aae5677f20738b4be6ad31862e")
endif()
endif()
set(URBANOPT_CLI_GEMS_ZIP_LOCAL_PATH "${PROJECT_BINARY_DIR}/${URBANOPT_CLI_GEMS_ZIP_FILENAME}")
set(URBANOPT_CLI_GEMS_DIR "${PROJECT_BINARY_DIR}/urbanopt-cli-gems")
if(EXISTS "${URBANOPT_CLI_GEMS_ZIP_LOCAL_PATH}")
file(MD5 "${URBANOPT_CLI_GEMS_ZIP_LOCAL_PATH}" URBANOPT_CLI_GEMS_ZIP_MD5)
endif()
if(NOT URBANOPT_CLI_GEMS_ZIP_MD5 STREQUAL URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5)
message(STATUS "Downloading URBANopt-CLI Gems: ${URBANOPT_CLI_GEMS_ZIP_FILENAME}")
file(DOWNLOAD "https://urbanopt-cli-resources.s3-us-west-2.amazonaws.com/gems/${URBANOPT_CLI_GEMS_ZIP_FILENAME}"
${URBANOPT_CLI_GEMS_ZIP_LOCAL_PATH}
INACTIVITY_TIMEOUT 300 # 5 minute timeout
SHOW_PROGRESS
EXPECTED_MD5 ${URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5})
# file(REMOVE_RECURSE "${URBANOPT_CLI_GEMS_DIR}")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${URBANOPT_CLI_GEMS_ZIP_LOCAL_PATH} WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
endif()
set(RUBY_DIR "${PROJECT_BINARY_DIR}/ruby")
if(UNIX)
if(APPLE)
set(RUBY_ZIP_FILENAME "ruby-2.7.2-darwin.tar.gz")
set(RUBY_ZIP_EXPECTED_MD5 "1ee27d6381797a5af7398f8eee8edb07")
else()
if (ARCH MATCHES "arm64")
set(URBANOPT_CLI_GEMS_ZIP_FILENAME "ruby-2.7.2-ubuntu-22.04-arm.tar.gz")
set(URBANOPT_CLI_GEMS_ZIP_EXPECTED_MD5 "bfef9299b151f84334684134c9a09347")
else()
set(RUBY_ZIP_EXPECTED_MD5 "853425b0c9878b064937f9e49688c6c6")
set(RUBY_ZIP_FILENAME "ruby-2.7.2-linux.tar.gz")
endif()
endif()
elseif(WIN32)
set(RUBY_ZIP_FILENAME "ruby-2.7.2-win32.tar.gz")
set(RUBY_ZIP_EXPECTED_MD5 "414a24f3ebb074534d2186595683c5b4")
endif()
set(RUBY_ZIP_LOCAL_PATH "${PROJECT_BINARY_DIR}/${RUBY_ZIP_FILENAME}")
set(RUBY_DIR "${PROJECT_BINARY_DIR}/ruby")
if(EXISTS "${RUBY_ZIP_LOCAL_PATH}")
file(MD5 "${RUBY_ZIP_LOCAL_PATH}" RUBY_ZIP_MD5)
endif()
if(NOT RUBY_ZIP_MD5 STREQUAL RUBY_ZIP_EXPECTED_MD5)
message(STATUS "Downloading Ruby: ${RUBY_ZIP_FILENAME}")
file(DOWNLOAD "https://urbanopt-cli-resources.s3-us-west-2.amazonaws.com/ruby/${RUBY_ZIP_FILENAME}"
${RUBY_ZIP_LOCAL_PATH}
INACTIVITY_TIMEOUT 300 # 5 minute timeout
SHOW_PROGRESS
EXPECTED_MD5 ${RUBY_ZIP_EXPECTED_MD5})
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${RUBY_ZIP_LOCAL_PATH} WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
endif()
###############################################################################
# I N S T A L L E R #
###############################################################################
######### Install SDK dependencies here ################
install(DIRECTORY "${OPENSTUDIO_SDK_PATH}/" DESTINATION "OpenStudio" COMPONENT "OpenStudio" USE_SOURCE_PERMISSIONS)
#install(DIRECTORY "${URBANOPT_CLI_GEMS_DIR}/" DESTINATION ".gems" COMPONENT "URBANopt" USE_SOURCE_PERMISSIONS)
if(UNIX)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/setup-env-unix.sh DESTINATION "." COMPONENT "URBANopt" RENAME "setup-env.sh")
elseif(WIN32)
install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/setup-env-gitbash.sh DESTINATION "." COMPONENT "URBANopt" RENAME "setup-env.sh")
install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/setup-env.ps1 DESTINATION "." COMPONENT "URBANopt")
install(PROGRAMS ${PROJECT_SOURCE_DIR}/scripts/setup-env.bat DESTINATION "." COMPONENT "URBANopt")
endif()
install(DIRECTORY "${PROJECT_BINARY_DIR}/ruby" DESTINATION "." COMPONENT "Ruby" USE_SOURCE_PERMISSIONS)
install(DIRECTORY "${PROJECT_BINARY_DIR}/urbanopt-cli-gems/" DESTINATION "gems" COMPONENT "URBANopt" USE_SOURCE_PERMISSIONS)
#if(WIN32)
# install(PROGRAMS "${OPENSTUDIO_SDK_PATH}/bin/install_utility.exe" DESTINATION bin COMPONENT "CLI")
#else()
# install(PROGRAMS "${OPENSTUDIO_SDK_PATH}/bin/install_utility" DESTINATION bin COMPONENT "CLI")
#endif()
set(CPACK_PACKAGE_VENDOR "National Renewable Energy Laboratory")
# These are ok, even if we have a prerelease tag
set(CPACK_PACKAGE_VERSION_MAJOR ${URBANOPT_CLI_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${URBANOPT_CLI_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${URBANOPT_CLI_VERSION_PATCH})
# TODO:/URBANOPT_CLI_VERSION
# CPACK_DEBIAN_PACKAGE_DESCRIPTION defaults to this one too. dpkg-deb -I xxx.deb will show this description
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "URBANoptCLI ${URBANOPT_CLI_VERSION} is a CLI software tool to support whole building energy modeling using EnergyPlus and advanced daylight analysis using Radiance")
# The actual package file name on disk
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${URBANOPT_CLI_LONG_VERSION}-${CMAKE_SYSTEM_NAME}")
set(CPACK_PACKAGE_CONTACT "openstudio@nrel.gov")
# Install additional Documents, such as release notes
#install(FILES "${PROJECT_SOURCE_DIR}/LICENSE.md" DESTINATION .)
if (APPLE)
#set(CPACK_IFW_TARGET_DIRECTORY "/Applications/URBANopt-cli-${URBANOPT_CLI_VERSION}")
set(CPACK_IFW_TARGET_DIRECTORY "/Applications/URBANoptCLI_${URBANOPT_CLI_VERSION}/")
elseif(UNIX)
# For debug
# set(CPACK_DEBIAN_PACKAGE_DEBUG ON)
# These two will set the .deb install path correctly
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqdbm14,sqlite3,libgomp1,libncurses5")
set(CPACK_SET_DESTDIR ON)
set(CPACK_INSTALL_PREFIX /usr/local/urbanopt-cli-${URBANOPT_CLI_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "openstudio@nrel.gov")
# Default the debian package name to include version to allow several versions to be installed concurrently instead of overwriting any existing one
set(CPACK_DEBIAN_PACKAGE_NAME "urbanopt-cli-${URBANOPT_CLI_VERSION}")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://www.openstudio.net")
#set(POSTINST_FILE "${PROJECT_BINARY_DIR}/postinst")
#set(POSTRM_FILE "${PROJECT_BINARY_DIR}/postrm")
#configure_file(${PROJECT_SOURCE_DIR}/debian/postinst.in ${POSTINST_FILE} @ONLY)
#configure_file(${PROJECT_SOURCE_DIR}/debian/postrm.in ${POSTRM_FILE} @ONLY)
#execute_process(COMMAND chmod 755 "${POSTINST_FILE}")
#execute_process(COMMAND chmod 755 "${POSTRM_FILE}")
#TODO
# install(FILES "${PROJECT_SOURCE_DIR}/src/openstudio_app/x-openstudio.xml" DESTINATION /usr/share/mime/application)
#install(FILES "${PROJECT_SOURCE_DIR}/src/openstudio_app/x-openstudio.xml" DESTINATION Temp/)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_BIN_PACKAGE_CONTROL_EXTRA};${POSTINST_FILE};${POSTRM_FILE}")
elseif(WIN32)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "URBANopt-cli-${URBANOPT_CLI_VERSION}")
set(CPACK_IFW_TARGET_DIRECTORY "C:/${CPACK_PACKAGE_INSTALL_DIRECTORY}")
set(CPACK_BINARY_IFW ON CACHE BOOL "Enable to build IFW packages")
set(CPACK_BINARY_NSIS OFF CACHE BOOL "Enable to build NSIS packages")
endif()
include(CPackIFW)
cpack_add_component(URBANopt
DISPLAY_NAME "URBANopt CLI"
DESCRIPTION "URBANopt CLI software tool"
)
cpack_add_component(OpenStudio
DISPLAY_NAME "OpenStudio SDK"
DESCRIPTION "OpenStudio SDK"
)
cpack_ifw_configure_component(URBANopt
REQUIRES_ADMIN_RIGHTS
)
cpack_ifw_configure_component(OpenStudio
# SCRIPT src/openstudio_app/install_operations.qs
REQUIRES_ADMIN_RIGHTS
)
include(CPack)