-
Notifications
You must be signed in to change notification settings - Fork 192
/
CMakeLists.txt
1576 lines (1314 loc) · 62.5 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
message(STATUS "Using CMake ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.20.0)
cmake_policy(SET CMP0048 NEW)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Do not enable compiler specific extensions, for eg on GCC use -std=c++1z (=c++17) and not -std=gnu++17
set(CMAKE_CXX_EXTENSIONS OFF)
# Use ccache if available, has to be before "project()"
find_program(CCACHE_PROGRAM NAMES ccache sccache)
if(CCACHE_PROGRAM)
# Support: Unix Makefiles and Ninja only
# RULE_LAUNCH_COMPILE is an internal variable and makes RC compilation fail on windows, hence why we use the C/CXX COMPILER_LAUNCHER instead
message(STATUS "${CCACHE_PROGRAM} found and enabled")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "CXX compiler cache used")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "C compiler cache used")
endif()
# Project macro can only take digits in the version, it splits these out to specific variables
project(OpenStudio VERSION 3.9.0)
include(CMake/compiler_flags.cmake)
# The RT Manifest file and C# SDK only support the digit portion of patch
string(APPEND PROJECT_VERSION_PATCH_DIGIT ${PROJECT_VERSION_PATCH})
# CPack package version does not support extended patch version
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
# 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(CPackComponent)
include(CheckCXXCompilerFlag)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()
if(POLICY CMP0022)
cmake_policy(SET CMP0022 NEW)
endif()
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
###############################################################################
# N I N J A #
###############################################################################
# Ninja support: has to be atop for it to take effect before anything else is done
# Add Color Output if Using Ninja
macro(AddCXXFlagIfSupported flag test)
CHECK_CXX_COMPILER_FLAG(${flag} ${test})
if(${${test}})
message("adding ${flag}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()
if("Ninja" STREQUAL ${CMAKE_GENERATOR})
# Will be passed to OpenStudio.in to deal with the Win32 case
set(NINJA TRUE)
# Clang
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
AddCXXFlagIfSupported(-fcolor-diagnostics COMPILER_SUPPORTS_fcolor-diagnostics)
endif()
# g++
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# For some reason it doesn't say its supported, but it works...
# AddCXXFlagIfSupported(-fdiagnostics-color COMPILER_SUPPORTS_fdiagnostics-color)
message(STATUS "Ninja: Forcing -fdiagnostics-color=always")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
endif()
# Xcode/Ninja generators undefined MAKE
if(CMAKE_GENERATOR MATCHES "Make")
set(MAKE "$(MAKE)")
else()
set(MAKE make)
endif()
###############################################################################
# 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)
# Git SHA (length 10)
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()
# Git branch name
execute_process(COMMAND "${GIT_EXECUTABLE}" "rev-parse" "--abbrev-ref" "HEAD"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
TIMEOUT 10
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE GIT_BRANCH
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${RESULT} EQUAL 0 AND NOT "${GIT_BRANCH}" EQUAL "${PROJECT_GIT_BRANCH}")
set(PROJECT_GIT_BRANCH ${GIT_BRANCH} CACHE STRING "Git Branch Name" FORCE)
endif()
get_filename_component(GIT_DIR "${GIT_EXECUTABLE}" DIRECTORY)
else()
set(GIT_DIR "")
endif()
find_program(PATCH_EXE patch HINTS "${GIT_DIR}" "${GIT_DIR}/../bin/" "${GIT_DIR}/../usr/bin/")
string(COMPARE EQUAL "${PATCH_EXE}" "PATCH_EXE-NOTFOUND" PATCH_EXE_NOTFOUND)
if(PATCH_EXE_NOTFOUND)
message(SEND_ERROR "Required program patch not found")
endif()
# Check if scope has a parent
get_directory_property(hasParent PARENT_DIRECTORY)
# README: what's the difference between all these versions?
# The "OpenStudio_VERSION" ones should be used in CMakeLists.txt
# * OpenStudio_VERSION: includes the prerelease tag if any: '3.0.0-rc1'
# * OpenStudio_VERSION_PATCH: Patch + prelrease tag if any
# The "OPENSTUDIO_VERSION" ones should only be used in OpenStudio.in (aside from using the the long version for naming the installer)
# * OPENSTUDIO_VERSION: just major.minor.patch: '3.0.0'
# * OPENSTUDIO_LONG_VERSION: includes prelrease and build sha: "3.0.0-rc1+ejfbxhza'
# TODO: Modify the more specific variables as needed to indicate prerelease, etc
# Keep in beta in-between release cycles. Set to empty string (or comment out) for official)
set(PROJECT_VERSION_PRERELEASE "")
# OpenStudio version: Only include Major.Minor.Patch, eg "3.0.0", even if you have a prerelease tag
set(OPENSTUDIO_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
if (NOT "${PROJECT_VERSION_PRERELEASE}" STREQUAL "")
message(STATUS "We have a prerelease tag set to '${PROJECT_VERSION_PRERELEASE}'")
if("${PROJECT_GIT_BRANCH}" STREQUAL "master")
message(AUTHOR_WARNING "You are building branch 'master', perhaps you shouldn't have included a pre-release tag")
endif()
string(APPEND OpenStudio_VERSION "-${PROJECT_VERSION_PRERELEASE}")
string(APPEND OpenStudio_VERSION_PATCH "-${PROJECT_VERSION_PRERELEASE}")
# Long version, include prerelease and build metadata. eg '3.0.0-rc1+6383a191dc'
set(OPENSTUDIO_LONG_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${PROJECT_VERSION_PRERELEASE}+${PROJECT_VERSION_BUILD}")
else()
message(STATUS "We do not have a prerelease tag")
if(NOT "${PROJECT_GIT_BRANCH}" STREQUAL "master")
message(AUTHOR_WARNING "You are building another branch than master but you do not have a prerelease tag, consider adding one such as 'beta'")
endif()
# Long version, include build metadata. eg '3.0.0+6383a191dc' for an official release
set(OPENSTUDIO_LONG_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}+${PROJECT_VERSION_BUILD}")
endif()
# Export to parent scope
if(hasParent)
set(OPENSTUDIO_VERSION "${OPENSTUDIO_VERSION}" PARENT_SCOPE)
set(OPENSTUDIO_LONG_VERSION "${OPENSTUDIO_LONG_VERSION}" PARENT_SCOPE)
endif()
# EnergyPlus Idd version
set(ENERGYPLUS_VERSION_MAJOR 24)
set(ENERGYPLUS_VERSION_MINOR 2)
set(ENERGYPLUS_VERSION_PATCH 0)
set(ENERGYPLUS_VERSION "${ENERGYPLUS_VERSION_MAJOR}.${ENERGYPLUS_VERSION_MINOR}.${ENERGYPLUS_VERSION_PATCH}")
# Build SHA is not required to have a value, but if it does OpenStudio will require this build.
set(ENERGYPLUS_BUILD_SHA "94a887817b")
# ENERGYPLUS_RELEASE_NAME is used to locate the E+ download
# from the github releases
set(ENERGYPLUS_RELEASE_NAME "v24.2.0a")
set(ENERGYPLUS_REPO "NREL")
# Radiance
set(RADIANCE_VERSION "5.0.a.12")
# configure file with version information
configure_file(${PROJECT_SOURCE_DIR}/OpenStudio.hxx.in ${PROJECT_BINARY_DIR}/src/OpenStudio.hxx)
# Deployment target
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
endif()
# compiler id for about boxes
if(MSVC)
set(ABOUT_COMPILER "${CMAKE_GENERATOR}")
elseif(APPLE)
set(ABOUT_COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_OSX_ARCHITECTURES} - OSX ${CMAKE_OSX_DEPLOYMENT_TARGET}")
else()
set(ABOUT_COMPILER "${CMAKE_CXX_COMPILER_ID}")
endif()
# If Linux, check LSB_RELEASE globally so we can use it after
# But also infer the new E+ package names (starting at 9.4.0)
if(APPLE)
set(ENERGYPLUS_SYSTEM_VERSION "")
find_program(UNAME uname)
execute_process(COMMAND ${UNAME} -m
OUTPUT_VARIABLE ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
elseif(UNIX)
# OS_RELEASE is the result of `uname -r` which is unhelpful (eg '5.4.0-42-generic')
find_program(LSB_RELEASE lsb_release)
# -rs outputs only 16.04, or 18.04
execute_process(COMMAND ${LSB_RELEASE} -rs
OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# -is outputs "Ubuntu" or "Fedora"
execute_process(COMMAND ${LSB_RELEASE} -is
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_program(UNAME uname)
execute_process(COMMAND ${UNAME} -m
OUTPUT_VARIABLE ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (ARCH STREQUAL "aarch64")
set(ARCH "arm64")
endif()
# eg: `-Ubuntu18.04`
set(ENERGYPLUS_SYSTEM_VERSION "-${LSB_RELEASE_ID_SHORT}${LSB_RELEASE_VERSION_SHORT}")
message(STATUS "LSB_RELEASE_ID_SHORT=${LSB_RELEASE_ID_SHORT}, LSB_RELEASE_VERSION_SHORT=${LSB_RELEASE_VERSION_SHORT}")
elseif(MSVC)
# no-op
set(ENERGYPLUS_SYSTEM_VERSION "")
endif()
###############################################################################
###############################################################################
# Build options
# TODO: should this be only in OpenStudioApplication?
option(BUILD_PAT "Build PAT" OFF)
# Build C++ documentation using Doxygen
# Requires: doxygen
option(BUILD_DOCUMENTATION "Build Documentation" OFF)
# Build CSharp bindings
option(BUILD_CSHARP_BINDINGS "Build CSharp bindings" OFF)
option(BUILD_NUGET_PACKAGE "Build NuGet Package" OFF)
# Build Python bindings
# Requires: SWIG Python
option(BUILD_PYTHON_BINDINGS "Build Python bindings" ON)
mark_as_advanced(BUILD_PYTHON_BINDINGS)
# Build ctest testing
# Requires: EnergyPlus
option(BUILD_TESTING "Build testing targets" OFF)
option(BUILD_BENCHMARK "Build benchmarking targets" OFF)
if(BUILD_BENCHMARK)
configure_file(${PROJECT_SOURCE_DIR}/developer/python/run_benchmark.py ${PROJECT_BINARY_DIR}/run_benchmark.py COPYONLY)
add_custom_target(run_benchmarks
COMMAND python run_benchmark.py --quiet --all
DEPENDS "${PROJECT_BINARY_DIR}/run_benchmark.py"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endif()
option(BUILD_RUBY_BINDINGS "Build Ruby bindings" ON)
mark_as_advanced(BUILD_RUBY_BINDINGS)
if(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bit
set(BUILD_RUBY_BINDINGS OFF CACHE BOOL "Override option" FORCE)
message("Ruby bindings are not support on 32 bit platforms, forcing BUILD_RUBY_BINDINGS OFF")
endif()
option(BUILD_CLI "Build OpenStudio command line interface" ON)
mark_as_advanced(BUILD_CLI)
if(NOT BUILD_RUBY_BINDINGS)
set(BUILD_CLI OFF CACHE BOOL "Override option" FORCE)
message("OpenStudio CLI depends on Ruby bindings which are disabled, therefore BUILD_CLI is also disabled")
endif()
# Build with OpenSSL support
set(BUILD_WITH_OPENSSL ON CACHE INTERNAL "Build With OpenSSL Support For SSH Connections")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_definitions(-Qunused-arguments)
endif()
include(CheckIncludeFile)
check_include_file("unistd.h" HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
add_definitions(-DHAVE_UNISTD_H)
endif()
# Enable runtime checking features
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" OFF)
if(ENABLE_COVERAGE)
add_definitions(--coverage -O0 -g)
set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} --coverage")
endif()
option(ENABLE_THREAD_SANITIZER "Enable thread sanitizer testing in gcc/clang" OFF)
if(ENABLE_THREAD_SANITIZER)
add_definitions(-fsanitize=thread -g)
set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -fsanitize=thread")
endif()
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer testing in gcc/clang" OFF)
if(ENABLE_ADDRESS_SANITIZER)
add_definitions(-fsanitize=address -g)
set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -fsanitize=address")
endif()
option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer testing in gcc/clang" OFF)
if(ENABLE_UNDEFINED_SANITIZER)
add_definitions(-fsanitize=undefined -g)
set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -fsanitize=undefined")
endif()
option(ENABLE_NORECOVER_SANITIZER "When any sanitizer that supports it report an error, exit with non zero" OFF)
if(ENABLE_NORECOVER_SANITIZER)
add_definitions(-fno-sanitize-recover=all)
set(SANITIZER_LINKER_FLAGS "${SANITIZER_LINKER_FLAGS} -fno-sanitize-recover=all")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}")
mark_as_advanced(ENABLE_COVERAGE ENABLE_THREAD_SANITIZER ENABLE_ADDRESS_SANITIZER ENABLE_UNDEFINED_SANITIZER ENABLE_NORECOVER_SANITIZER)
endif()
if(APPLE)
# Without this, cmake will give "Module" libraries the ".so" extension on Apple
# This appears to be a legacy choice by the cmake developers, and seems out of place,
# so the OpenStudio project will use the library suffix ".dylib"
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
# TODO: remove when bumping Boost to 1.81+, cf https://github.com/NREL/OpenStudio/issues/4978
add_definitions(-DBOOST_NO_CXX98_FUNCTION_BASE)
add_definitions(-D_HAS_AUTO_PTR_ETC=0)
endif()
if(UNIX AND NOT APPLE)
# Enable libgtest linking
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif()
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bit
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:NOICF")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:NOICF")
endif()
endif()
option(USE_LTO "Use Link-Time-Optimization" OFF)
if (USE_LTO)
include(CheckIPOSupported)
check_ipo_supported()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
if(WIN32)
add_definitions(-DNOMINMAX)
# Set the BOOST_USE_WINAPI_VERSION to Windows10
add_compile_definitions(BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN7)
# This will also align _WIN32_WINNT and WINVER
# add_compile_definitions(BOOST_USE_WINDOWS_H) # Getting a confict with `typedef GUID UUID` from windows.h
add_compile_definitions(BOOST_WINAPI_DEFINE_VERSION_MACROS)
add_compile_definitions(WIN32_LEAN_AND_MEAN) # That excludes stuff that's not used too often, including the GUID stuff
endif()
if(MSVC AND NOT NINJA)
# Build with Multiple Processes
set(BUILD_WITH_MULTIPLE_PROCESSES ON CACHE BOOL "/MP compiler flag for full processor utilization")
mark_as_advanced(BUILD_WITH_MULTIPLE_PROCESSES)
endif()
###############################################################################
###############################################################################
# Conan
if(BUILD_RUBY_BINDINGS)
find_package(Ruby)
message("Ruby_INCLUDE_DIRS=${Ruby_INCLUDE_DIRS}")
endif()
find_package(pugixml)
find_package(LibXslt)
find_package(libxml2)
find_package(jsoncpp)
find_package(fmt)
find_package(SQLite3)
find_package(cpprestsdk)
find_package(websocketpp)
find_package(Boost)
find_package(geographiclib)
find_package(SWIG 4.1.1 EXACT REQUIRED CONFIG)
message("SWIG_EXECUTABLE=${SWIG_EXECUTABLE}")
message("SWIG_DIR=${SWIG_DIR}")
find_package(TinyGLTF)
find_package(CLI11)
find_package(minizip)
find_package(OpenSSL)
find_package(ZLIB)
if(BUILD_TESTING)
find_package(GTest)
endif()
if(BUILD_BENCHMARK)
find_package(benchmark)
endif()
# A macro to find a conan related value especially when using multi-config builds (MSVC)
# But it also works with single-config builds
macro(FindValue ValueName)
set(LocalVar "")
set(LocalVar $<$<CONFIG:Debug>:${${ValueName}_DEBUG}>$<$<CONFIG:Release>:${${ValueName}_RELEASE}>$<$<CONFIG:RelWithDebInfo>:${${ValueName}_RELWITHDEBINFO}>$<$<CONFIG:MinSizeRel>:${${ValueName}_MINSIZEREL}>
)
# list(JOIN LocalVar "" LocalVar)
string(STRIP ${LocalVar} LocalVar)
set(CURRENT_${ValueName} $<IF:$<BOOL:${LocalVar}>,${LocalVar},${${ValueName}}>)
# For debug purposes
# message(STATUS "Found '${ValueName}' as '${CURRENT_${ValueName}}'")
endmacro()
###############################################################################
# Export to Parent
if(hasParent)
set(Ruby_INCLUDE_DIRS "${Ruby_INCLUDE_DIRS}" PARENT_SCOPE)
endif()
###############################################################################
# CMake control
# High level project configuration
# TODO: Do we actually want everything to go to CMAKE_BINARY_DIR/Products,
# so that when you build OpenStudioApplication you get both OpenStudio (core) and Application in the same place?
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Products")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Products")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Products")
set(LIBRARY_SEARCH_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Release" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Debug")
set(LIB_DESTINATION_DIR lib)
if(WIN32)
# Windows does not have RPATH handling, so we just put everything next to the CLI in the bin/ folder
set(LIB_DESTINATION_DIR bin)
endif()
# TODO: move App macros to a local ProjectMacros.cmake
# Include project specific macros
include("${PROJECT_SOURCE_DIR}/ProjectMacros.cmake")
# Search first in the binary dir, where conan will install finders, then
# search for modules in the root dir to override cmake ones
# Start with ROOT, then PROJECT_BINARY_DIR
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR} ${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/CMake")
# Use CTest
set(ALL_TESTING_TARGETS "") # global list
if(BUILD_TESTING)
enable_testing()
include(CTest)
include(GoogleTest)
endif()
###############################################################################
###############################################################################
# Compiler and system specific options
if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC -fno-strict-aliasing")
# all warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC -fno-strict-aliasing -Winvalid-pch -Wnon-virtual-dtor -Wno-narrowing")
# TODO: temp for gcc-11 which throws narrowing conversions in Path_GTest.cpp due to int codepoints
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
# Treat all warnings as errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual -ftemplate-depth=1024")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual")
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# DLM: had to add this due to issues with boost optional and gcc, may be resolved if we move to std::optional
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
endif()
endif()
endif()
# Note: CMAKE_CXX_STANDARD (with no extensions) already sets -std=c++17 (or std=c++1z).
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
if(MINGW)
# all warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# effective c++
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
# treat warnings as errors
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
# wchar not supported for MinGW
#add_definitions(-DBOOST_LOG_USE_CHAR)
#add_definitions(-DBOOST_LOG_NO_COMPILER_TLS)
endif()
if(MSVC)
# warning level 3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
# warning level 4 - DLM: we should shoot for this
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
# all warnings - DLM: probably too high to ever use
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
# create compiler processes on all effective processors
# /MP is useless for ninja and will cause problems. BUILD_WITH_MULTIPLE_PROCESSES shouldn't have been set if ninja but let's be safe
if(BUILD_WITH_MULTIPLE_PROCESSES AND NOT NINJA)
add_definitions(/MP)
endif()
# Enable warning on thread un-safe static member initialization - DLM: we have been bit by this many times
# TODO: JM 2019-09-19: Disabling for now
# Using the righg flag (/w14460 and not the previously mispelled /w44640) will make compilation fail with many warnings treated as error,
# eg: IddRegex.cpp all scoped `const static std::string result` inside functions will issue that and make it fatal
# add_definitions(/w14640)
# ignore decorated name length exceeded
add_definitions(/wd4503)
# ignore needs to have dll-interface to be used by clients of class
# we will not rely on exporting templates instead all libraries must
# be linked against the same runtime
add_definitions(/wd4251)
# ignore base class not dll-exported error
add_definitions(/wd4275)
add_definitions(/bigobj)
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bit
# ignore conversion from size_t to int for now
add_definitions(/wd4267)
else()
# ignore conversion from 'type1' to 'type2', possible loss of data
add_definitions(/wd4244)
endif()
# treat warnings as errors
# DLM: only do this for our code, added in later
# add_definitions(/WX)
# ignore warnings about the stl being insecure
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
# ignore c++17 deprecation warnings generated by boost
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
add_definitions(-D_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING)
# ignore c++20 deprecation warnings generated by fmt
add_definitions(-D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING)
add_definitions(-D_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS)
add_compile_options(/utf-8)
endif()
##############################################################################
###############################################################################
# Check version of gcc
if(CMAKE_COMPILER_IS_GNUCC)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION)
endif()
###############################################################################
# Dependencies
# EnergyPlus
if(UNIX)
if(APPLE)
# TODO: temp for #5281 - Resigned with a different entitlements to avoid an issue when we pip install stuff into the E+ dir with native comps (numpy for eg)
set(ENERGYPLUS_REPO "jmarrec")
set(ENERGYPLUS_RELEASE_NAME "v24.2.0a-entitlements")
if (ARCH MATCHES "arm64")
set(ENERGYPLUS_EXPECTED_HASH 29616d6aa23e2fc0f71362da9794ef08)
set(ENERGYPLUS_PLATFORM "Darwin-macOS13-arm64")
else()
set(ENERGYPLUS_EXPECTED_HASH 21bdad40fbc560b4b382469ef9f96936)
set(ENERGYPLUS_PLATFORM "Darwin-macOS12.1-x86_64")
endif()
elseif(LSB_RELEASE_ID_SHORT MATCHES "CentOS")
set(ENERGYPLUS_EXPECTED_HASH 4000e06b944daf4f2b0841ac0d3873b5)
set(ENERGYPLUS_PLATFORM "Linux-CentOS7.9.2009-x86_64")
else()
if(LSB_RELEASE_VERSION_SHORT MATCHES "24.04")
if (ARCH MATCHES "arm64")
set(ENERGYPLUS_EXPECTED_HASH afc61e89b7f9e2658c3d99778be50be0)
else()
set(ENERGYPLUS_EXPECTED_HASH 22b3e5f6071d6011ffeeacf854a97c73)
endif()
elseif(LSB_RELEASE_VERSION_SHORT MATCHES "22.04")
if (ARCH MATCHES "arm64")
set(ENERGYPLUS_EXPECTED_HASH 3c18cb8063ec30ef591109ddf8842bf0)
else()
set(ENERGYPLUS_EXPECTED_HASH 9f11a16e6f8a7d658791c5389d700ef1)
endif()
else() # e.g., 18.04, 20.04
message(FATAL_ERROR "EnergyPlus no longer provides packages for Ubuntu < 22.04")
endif()
set(ENERGYPLUS_PLATFORM "Linux${ENERGYPLUS_SYSTEM_VERSION}-${ARCH}")
endif()
set(ENERGYPLUS_PATH "EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_BUILD_SHA}-${ENERGYPLUS_PLATFORM}")
if(EXISTS "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz")
file(MD5 "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz" ENERGYPLUS_HASH)
endif()
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz" OR NOT "${ENERGYPLUS_HASH}" MATCHES "${ENERGYPLUS_EXPECTED_HASH}")
message(STATUS "Downloading EnergyPlus ${ENERGYPLUS_VERSION} (${ENERGYPLUS_PLATFORM})")
message(STATUS "https://github.com/${ENERGYPLUS_REPO}/EnergyPlus/releases/download/${ENERGYPLUS_RELEASE_NAME}/${ENERGYPLUS_PATH}.tar.gz")
if(LSB_RELEASE_ID_SHORT MATCHES "CentOS")
file(DOWNLOAD
"https://github.com/${ENERGYPLUS_REPO}/EnergyPlus/releases/download/${ENERGYPLUS_RELEASE_NAME}/${ENERGYPLUS_PATH}.tar.gz" "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz"
# "http://openstudio-resources.s3.amazonaws.com/dependencies/${ENERGYPLUS_PATH}.tar.gz" "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz"
INACTIVITY_TIMEOUT 300 # 5-min timeout
SHOW_PROGRESS
EXPECTED_MD5 ${ENERGYPLUS_EXPECTED_HASH})
else()
file(DOWNLOAD "https://github.com/${ENERGYPLUS_REPO}/EnergyPlus/releases/download/${ENERGYPLUS_RELEASE_NAME}/${ENERGYPLUS_PATH}.tar.gz" "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz"
INACTIVITY_TIMEOUT 300 # 5-min timeout
SHOW_PROGRESS
EXPECTED_MD5 ${ENERGYPLUS_EXPECTED_HASH})
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}")
file(REMOVE "${PROJECT_BINARY_DIR}/python/engine/pip_install_done.stamp")
endif()
elseif(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bit
set(ENERGYPLUS_PATH "EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_BUILD_SHA}-Windows-x86_64")
set(ENERGYPLUS_ARCH 64)
set(ENERGYPLUS_EXPECTED_HASH 6a2d1d43d64490c87d894ed58f71ccdc)
else()
set(ENERGYPLUS_PATH "EnergyPlus-${ENERGYPLUS_VERSION}-${ENERGYPLUS_BUILD_SHA}-Windows-i386")
set(ENERGYPLUS_ARCH 32)
set(ENERGYPLUS_EXPECTED_HASH 7f0c2901399f43bff6e23c01a5992df1)
endif()
if(EXISTS "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip")
file(MD5 "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip" ENERGYPLUS_HASH)
endif()
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip" OR NOT "${ENERGYPLUS_HASH}" MATCHES "${ENERGYPLUS_EXPECTED_HASH}")
message(STATUS "Downloading EnergyPlus ${ENERGYPLUS_VERSION} (${ENERGYPLUS_ARCH}-bit)")
file(DOWNLOAD "https://github.com/${ENERGYPLUS_REPO}/EnergyPlus/releases/download/${ENERGYPLUS_RELEASE_NAME}/${ENERGYPLUS_PATH}.zip" "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip"
INACTIVITY_TIMEOUT 300 # 5 minute timeout
SHOW_PROGRESS
EXPECTED_MD5 ${ENERGYPLUS_EXPECTED_HASH})
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}")
file(REMOVE "${PROJECT_BINARY_DIR}/python/engine/pip_install_done.stamp")
endif()
endif()
if((DEFINED ENERGYPLUS_EXE) AND NOT (ENERGYPLUS_EXE STREQUAL ""))
get_filename_component(OLD_ENERGYPLUS_EXTRACTED_DIR "${ENERGYPLUS_EXE}" DIRECTORY)
if(NOT "${OLD_ENERGYPLUS_EXTRACTED_DIR}" MATCHES ".*${ENERGYPLUS_PATH}.*")
message(STATUS "Removing old extracted dir = ${OLD_ENERGYPLUS_EXTRACTED_DIR}")
# Remove the old extracted dir
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${OLD_ENERGYPLUS_EXTRACTED_DIR}")
# Unset variables so that FindEnergyPlus is called again
unset(ENERGYPLUS_FOUND CACHE)
unset(ENERGYPLUS_EXE CACHE)
unset(ENERGYPLUS_IDD CACHE)
unset(ENERGYPLUS_WEATHER_DIR CACHE)
endif()
endif()
# Allows placing the archive manually in the build dir too
if (NOT EXISTS "${ENERGYPLUS_PATH}")
unset(ENERGYPLUS_FOUND CACHE)
unset(ENERGYPLUS_EXE CACHE)
unset(ENERGYPLUS_IDD CACHE)
unset(ENERGYPLUS_WEATHER_DIR CACHE)
if (UNIX)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.tar.gz" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}.zip" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
endif()
endif()
# Prior to E+ 9.1.0 (OS 2.7.2), zip/tar.gz would extract to something like `./EnergyPlus-9.0.0-buildsha-Linux-x86_64/EnergyPlus-9-0-0`
if (ENERGYPLUS_VERSION VERSION_LESS "9.1.0")
set(ENV{ENERGYPLUSDIR} "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}/EnergyPlus-${ENERGYPLUS_VERSION_MAJOR}-${ENERGYPLUS_VERSION_MINOR}-${ENERGYPLUS_VERSION_PATCH}")
else()
# After 9.1.0, due to QtIFW/Mac packaging (NREL/EnergPlus#7148), it is going directly to `./EnergyPlus-9.1.0-buildsha-Linux-x86_64/`
set(ENV{ENERGYPLUSDIR} "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}")
endif()
# Find EnergyPlus, which will set the ENERGYPLUS_XXX variables and cache them
find_package(EnergyPlus "${ENERGYPLUS_VERSION}" REQUIRED MODULE)
get_filename_component(ENERGYPLUS_DIR "${ENERGYPLUS_EXE}" DIRECTORY)
# Radiance
if(UNIX)
if(APPLE)
set(RADIANCE_EXPECTED_HASH 115ef9052ad5011d3fc7cebc2991644f)
set(RADIANCE_PLATFORM "Darwin")
elseif(EXISTS "/etc/redhat-release")
# DLM: note that the installer expects the extracted directory to be named radiance-5.0.a.12-Linux
set(RADIANCE_EXPECTED_HASH f75898bbfd238a740c1902d385c42b92)
set(RADIANCE_PLATFORM "Redhat")
else()
set(RADIANCE_EXPECTED_HASH 7b9e4df2b6050fe51c6e138e4c0e6a5a)
set(RADIANCE_PLATFORM "Linux")
endif()
set(RADIANCE_PATH "radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}")
if(EXISTS "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz")
file(MD5 "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz" RADIANCE_HASH)
endif()
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz" OR NOT "${RADIANCE_HASH}" MATCHES "${RADIANCE_EXPECTED_HASH}")
message(STATUS "Downloading Radiance ${RADIANCE_VERSION} (${RADIANCE_PLATFORM})")
if(EXISTS "/etc/redhat-release" OR LSB_RELEASE_ID_SHORT MATCHES "CentOS")
message("http://openstudio-resources.s3.amazonaws.com/dependencies/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}.tar.gz")
file(DOWNLOAD "http://openstudio-resources.s3.amazonaws.com/dependencies/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}.tar.gz" "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz" TIMEOUT 120 INACTIVITY_TIMEOUT 120 SHOW_PROGRESS EXPECTED_MD5 ${RADIANCE_EXPECTED_HASH})
else()
file(DOWNLOAD "http://github.com/NREL/Radiance/releases/download/${RADIANCE_VERSION}/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}.tar.gz" "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz" TIMEOUT 120 INACTIVITY_TIMEOUT 120 SHOW_PROGRESS EXPECTED_MD5 ${RADIANCE_EXPECTED_HASH})
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}")
endif()
set(RADIANCE_LOCATION "${PROJECT_BINARY_DIR}/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}/usr/local/radiance")
elseif(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bit
set(RADIANCE_ARCH 64)
set(RADIANCE_EXPECTED_HASH 7bd7a418d181365b4153c8bc146ede06)
else()
message(WARNING "32 bit Radiance build is not available")
message(WARNING "Using 64 bit build of Radiance with a 32 bit build of OpenStudio")
set(RADIANCE_ARCH 64)
set(RADIANCE_EXPECTED_HASH 7bd7a418d181365b4153c8bc146ede06)
#set(RADIANCE_ARCH 32)
#set(RADIANCE_EXPECTED_HASH 78eda5d4b0215cd675cc3ec8975e6122)
endif()
set(RADIANCE_PATH "radiance-${RADIANCE_VERSION}-win${RADIANCE_ARCH}")
set(RADIANCE_PLATFORM "win${RADIANCE_ARCH}")
if(EXISTS "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.zip")
file(MD5 "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.zip" RADIANCE_HASH)
endif()
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.zip" OR NOT "${RADIANCE_HASH}" MATCHES "${RADIANCE_EXPECTED_HASH}")
message(STATUS "Downloading Radiance ${RADIANCE_VERSION} (${RADIANCE_ARCH}-bit)")
file(DOWNLOAD "http://github.com/NREL/Radiance/releases/download/${RADIANCE_VERSION}/Radiance-${RADIANCE_VERSION}-win${RADIANCE_ARCH}.zip" "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.zip" TIMEOUT 120 INACTIVITY_TIMEOUT 120 SHOW_PROGRESS EXPECTED_MD5 ${RADIANCE_EXPECTED_HASH})
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}")
endif()
set(RADIANCE_LOCATION "${PROJECT_BINARY_DIR}/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}/")
endif()
# Allows placing the archive manually in the build dir too
if (NOT EXISTS "${PROJECT_BINARY_DIR}/radiance-${RADIANCE_VERSION}-${RADIANCE_PLATFORM}")
if (UNIX)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.tar.gz" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${RADIANCE_PATH}.zip" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
endif()
endif()
# Perl
if(NOT UNIX)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/dependencies/strawberry-perl-5.16.2.1-32bit-portable-reduced.tar.bz2"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE rv)
set(PERL_EXE "${PROJECT_BINARY_DIR}/strawberry-perl-5.16.2.1-32bit-portable-reduced/perl/bin/perl.exe")
endif()
include(FetchRubyMinGW.cmake)
FetchRubyMinGW()
if(BUILD_CLI)
# CI will build and upload openstudio gems to s3 at https://github.com/NREL/openstudio-gems
# need to update the MD5sum for each platform and url below
set(OPENSTUDIO_GEMS_BASEURL "http://openstudio-resources.s3.amazonaws.com/dependencies")
# TODO: temp
set(OPENSTUDIO_GEMS_BASEURL "https://github.com/NREL/openstudio-gems/releases/download/v3.9.0-RC3")
# To use the package produced by a PR to https://github.com/NREL/openstudio-gems
set(USE_OPENSTUDIO_GEMS_PR FALSE)
if (USE_OPENSTUDIO_GEMS_PR)
set(OPENSTUDIO_GEMS_BASEURL "http://openstudio-sdk-dependencies.s3.amazonaws.com/openstudio-gems")
set(OPENSTUDIO_GEMS_PR_NUMBER "PR-67")
endif()
if(UNIX)
if(APPLE)
if (ARCH MATCHES arm64)
set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio3-gems-20241112-darwin_arm64-3.2.2.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "cb6a884366780c8ba5da2852ca60e98a")
else()
set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio3-gems-20241112-darwin-3.2.2.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "ce81fcf1bf707281082cde3d87dac114")
endif()
else()
if (ARCH MATCHES "arm64")
set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio3-gems-20240517-linux_arm64-3.2.2.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "f6d094a3bdaf1476ce7911e74276993b")
else()
set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio3-gems-20241112-linux-3.2.2.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "7551691c842a86cc8198959b5d0f1ee9")
endif()
if (USE_OPENSTUDIO_GEMS_PR)
set(OPENSTUDIO_GEMS_BASEURL "${OPENSTUDIO_GEMS_BASEURL}/openstudio-gems-linux/${OPENSTUDIO_GEMS_PR_NUMBER}")
endif()
endif()
elseif(WIN32)
# OpenStudio gems are only supported on 64 bit windows
set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio3-gems-20241112-windows-3.2.2.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "8f1cdcca664a1d3d80908230a00981ef")
if (USE_OPENSTUDIO_GEMS_PR)
set(OPENSTUDIO_GEMS_BASEURL "${OPENSTUDIO_GEMS_BASEURL}/openstudio-gems-windows/${OPENSTUDIO_GEMS_PR_NUMBER}")
endif()
endif()
set(OPENSTUDIO_GEMS_ZIP_LOCAL_PATH "${PROJECT_BINARY_DIR}/${OPENSTUDIO_GEMS_ZIP_FILENAME}")
set(OPENSTUDIO_GEMS_DIR "${PROJECT_BINARY_DIR}/openstudio-gems")
set(OPENSTUDIO_GEMS_TARGETS_FILE "${OPENSTUDIO_GEMS_DIR}/export-extensions.cmake")
set(OPENSTUDIO_GEMS_INIT_FILE "${OPENSTUDIO_GEMS_DIR}/init-extensions.cpp")
if(EXISTS "${OPENSTUDIO_GEMS_ZIP_LOCAL_PATH}")
file(MD5 "${OPENSTUDIO_GEMS_ZIP_LOCAL_PATH}" OPENSTUDIO_GEMS_ZIP_MD5)
endif()
# If you do not have the right tar.gz: download, and remove extracted dir
if(NOT OPENSTUDIO_GEMS_ZIP_MD5 STREQUAL OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5)
message(STATUS "Downloading OpenStudio Gems: ${OPENSTUDIO_GEMS_BASEURL}/${OPENSTUDIO_GEMS_ZIP_FILENAME}")
file(
DOWNLOAD "${OPENSTUDIO_GEMS_BASEURL}/${OPENSTUDIO_GEMS_ZIP_FILENAME}"
${OPENSTUDIO_GEMS_ZIP_LOCAL_PATH}
INACTIVITY_TIMEOUT 300 # 5 minute timeout
SHOW_PROGRESS
EXPECTED_MD5 ${OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5})
file(REMOVE_RECURSE "${OPENSTUDIO_GEMS_DIR}")
endif()
# If the extracted dir has a version.txt, it must match, otherwise remove it
if(EXISTS "${OPENSTUDIO_GEMS_DIR}/version.txt")
file(READ ${OPENSTUDIO_GEMS_DIR}/version.txt EXTRACTED_TAR_GZ_NAME)
string(STRIP ${EXTRACTED_TAR_GZ_NAME} EXTRACTED_TAR_GZ_NAME)
if(NOT EXTRACTED_TAR_GZ_NAME STREQUAL OPENSTUDIO_GEMS_ZIP_FILENAME)
message("Extracted gem dir ${OPENSTUDIO_GEMS_DIR} has the wrong version, removing it")
file(REMOVE_RECURSE "${OPENSTUDIO_GEMS_DIR}")
endif()
else()
# Until the openstudio-gems package from my PR-51 goes onto develop, assume you want to remove it to avoid leaving it in place when you switch back to develop
if(EXISTS "${OPENSTUDIO_GEMS_DIR}" AND NOT USE_OPENSTUDIO_GEMS_PR)
file(REMOVE_RECURSE "${OPENSTUDIO_GEMS_DIR}")
endif()
endif()
# If you do not have the extracted dir, then extract the tar.gz
if(NOT EXISTS "${OPENSTUDIO_GEMS_DIR}")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${OPENSTUDIO_GEMS_ZIP_LOCAL_PATH} WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
file(REMOVE_RECURSE "${PROJECT_BINARY_DIR}/src/cli/embedded_files")
endif()
endif()
# SWIG
# Note: JM 2019-10-16
# We use conan swig_installer 4.0 which enhances our PATH to include the CONAN_BIN_DIRS_SWIG_INSTALLER already
# So I could just do:
# set(SWIG_EXECUTABLE swig)
# But will have the probblem with the swiglib anyways.
# Plus, it doesn't appear to work on windows either, the PATH doesn't include it.
#find_program(SWIG_EXECUTABLE swig PATHS CURRENT_CONAN_SWIG_ROOT NO_DEFAULT_PATH)
#if(NOT SWIG_EXECUTABLE)
# message(FATAL_ERROR "Couldn't find swig, which shouldn't happen. CONAN_BIN_DIRS_SWIG_INSTALLER=${CONAN_BIN_DIRS_SWIG_INSTALLER}, CONAN_SWIG_ROOT_RELEASE=${CONAN_SWIG_ROOT_RELEASE}, CURRENT_CONAN_SWIG_ROOT=${CURRENT_CONAN_SWIG_ROOT}, ${ENV{SWIG_DIR}}, ${ENV{SWIG_INSTALLER_ROOT}}")
#endif()
# Another thing I tried is to use the `virtualenv` generator (`conan_cmake_run( ... GENERATORS virtualenv)`),
# but you end up having to call the activation script on each call, and the call is dependent on the platform which is even more annoying
# (either cmake -E cmd /C activate.bat, or cmake -E source activate.sh)
# I also tried using CMake to extract the value from the activate.sh script on all plaftorms but it seems even more of a hack
# So instead, we use a generator expression to find the right value. At least it makes sense, and should be robust.
FindValue(swig_PACKAGE_FOLDER)
# set(SWIG_EXECUTABLE "${CURRENT_swig_PACKAGE_FOLDER}/bin/swig")
# The conan-provided binary has a built-in swiglib (`swig -swiglib`) that points to the build box on which it was built, which is problematic for us.
# set(SWIG_DIR "${CURRENT_swig_PACKAGE_FOLDER}/bin/swiglib")
# Export SWIG to parent scope
if(hasParent)
set(SWIG_EXECUTABLE "${SWIG_EXECUTABLE}" PARENT_SCOPE)
set(SWIG_DIR "${SWIG_DIR}" PARENT_SCOPE)
endif()
set(ALL_RUBY_BINDING_TARGETS "") # global list
# build rdoc
if(BUILD_DOCUMENTATION)
if(WIN32)
get_filename_component(RUBY_BIN_DIR "${RUBY_EXECUTABLE}" DIRECTORY)
find_file(RDOC NAMES rdoc.bat HINTS $ENV{PATH} "${RUBY_BIN_DIR}")
find_file(RI NAMES ri.bat HINTS $ENV{PATH} "${RUBY_BIN_DIR}")
else()
find_program(RDOC NAMES rdoc)
find_program(RI NAMES ri)
endif()
mark_as_advanced(
RDOC
RI
)
set(ALL_RDOC_TARGETS ${ALL_RUBY_BINDING_TARGETS})
endif()
# C#
if(BUILD_CSHARP_BINDINGS)
set(ALL_CSHARP_BINDING_DEPENDS "") # global list of library dependencies of the generated wrapper cxx files
set(ALL_CSHARP_WRAPPER_FILES "") # global list of generated wrapper cxx files
set(ALL_CSHARP_WRAPPER_TARGETS "") # global list targets that build generated wrapper cxx files
endif()
if(BUILD_NODE_MODULES)
add_definitions(-DBUILD_NODE_MODULE)
endif()
if(BUILD_PYTHON_BINDINGS)
include(python/SetupPython.cmake)
endif()