-
Notifications
You must be signed in to change notification settings - Fork 192
/
CMakeLists.txt
200 lines (162 loc) · 7 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
install(DIRECTORY "examples"
DESTINATION "CSharp/"
COMPONENT "CSharpAPI"
FILES_MATCHING PATTERN "*.cs"
PATTERN "*.csproj"
PATTERN "*.sln"
PATTERN "*.resx"
PATTERN "*.settings"
PATTERN "*.docx"
)
file(TO_NATIVE_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp" CSHARP_LIBRARY_OUTPUT_DIRECTORY)
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/csharp" CSHARP_SOURCE_DIR)
file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/csharp_wrapper" CSHARP_BINARY_DIR)
set(CSHARP_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CSHARP_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CSHARP_VERSION_PATCH ${PROJECT_VERSION_PATCH_DIGIT})
set(CSHARP_VERSION_BUILD 0)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CSHARP_PLATFORM "x64")
else()
set(CSHARP_PLATFORM "x86")
endif()
set(CSHARP_ASSEMBLY_VERSION "${CSHARP_VERSION_MAJOR}.${CSHARP_VERSION_MINOR}.${CSHARP_VERSION_PATCH}.${CSHARP_VERSION_BUILD}")
set(CSHARP_TOOLS_VERSION "4.5")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/csharp_wrapper/generated_sources")
configure_file("${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/OpenStudio.csproj.in" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj")
#This is generating odd errors about needing to convert the included project file, but it seems like it would be a good
#way to move forward, if it worked. Leaving here as a note.
#include_external_msproject(OpenStudio "${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/OpenStudio.csproj" ${CSHARP_LIBRARIES})
#in lieu of the above, we are using the following:
# the main OpenStudio.dll generated
# Rely on dotnet Core (open source)
find_program(DOTNET dotnet)
if(NOT DOTNET)
message(FATAL_ERROR "C# generation outside of MSVC requires .NET Core (dotnet)")
endif()
# The Release/Debug can be stripped probably
# Also probably don't need to use multiple `<TargetFrameworks>` which is the reason there's an extra netstandard2.0/ level
set(OPENSTUDIO_CSHARP_DLL "${CSHARP_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}/netstandard2.0/OpenStudio.dll")
# ignore deprecated warnings since we will export deprecated methods
add_library(csharp_warnings INTERFACE)
target_compile_options(csharp_warnings INTERFACE "$<${is_msvc_genex}:/wd4996>")
target_compile_options(csharp_warnings INTERFACE "$<${is_msvc_genex}:/bigobj>")
target_compile_options(csharp_warnings INTERFACE "$<${is_gnu_or_clang_genex}:-Wno-deprecated-declarations>")
target_compile_options(csharp_warnings INTERFACE "$<${is_gnu_or_clang_genex}:-Wno-unused-function>")
# custom command to make OPENSTUDIO_CSHARP_DLL
add_custom_command(
OUTPUT ${OPENSTUDIO_CSHARP_DLL}
COMMAND "${DOTNET}" "build" "-c" "$<CONFIGURATION>" "/p:Platform=${CSHARP_PLATFORM}" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj"
DEPENDS ${ALL_CSHARP_WRAPPER_TARGETS} ${ALL_CSHARP_WRAPPER_FILES}
)
install(FILES "${OPENSTUDIO_CSHARP_DLL}" DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
# keep the following lists aligned with translator_names in ProjectMacros.cmake
set(translator_wrappers
csharp_OpenStudioAirflow_wrap.cxx
csharp_OpenStudioEnergyPlus_wrap.cxx
csharp_OpenStudioGBXML_wrap.cxx
csharp_OpenStudioGltf_wrap.cxx
csharp_OpenStudioISOModel_wrap.cxx
csharp_OpenStudioRadiance_wrap.cxx
csharp_OpenStudioSDD_wrap.cxx
)
set(model_wrappers
csharp_OpenStudioMeasure_wrap.cxx
csharp_OpenStudioModel_wrap.cxx
csharp_OpenStudioModelAirflow_wrap.cxx
csharp_OpenStudioModelAvailabilityManager_wrap.cxx
csharp_OpenStudioModelCore_wrap.cxx
csharp_OpenStudioModelGenerators_wrap.cxx
csharp_OpenStudioModelGeometry_wrap.cxx
csharp_OpenStudioModelHVAC_wrap.cxx
csharp_OpenStudioModelPlantEquipmentOperationScheme_wrap.cxx
csharp_OpenStudioModelRefrigeration_wrap.cxx
csharp_OpenStudioModelResources_wrap.cxx
csharp_OpenStudioModelSetpointManager
csharp_OpenStudioModelSimulation_wrap.cxx
csharp_OpenStudioModelStraightComponent_wrap.cxx
csharp_OpenStudioModelZoneHVAC_wrap.cxx
csharp_OpenStudioOSVersion_wrap.cxx
)
set(utilities_wrappers
csharp_OpenStudioEnergyPlus_wrap.cxx
csharp_OpenStudioRadiance_wrap.cxx
csharp_OpenStudioGBXML_wrap.cxx
csharp_OpenStudioGltf_wrap.cxx
csharp_OpenStudioAirflow_wrap.cxx
csharp_OpenStudioISOModel_wrap.cxx
csharp_OpenStudioSDD_wrap.cxx
)
foreach(wrapper_file IN LISTS ALL_CSHARP_WRAPPER_FILES)
get_filename_component(wrapper_name ${wrapper_file} NAME)
set(notfound TRUE)
foreach(model_wrapper IN LISTS model_wrappers)
if( wrapper_name STREQUAL model_wrapper )
list(APPEND model_wrapper_files ${wrapper_file})
set(notfound FALSE)
break()
endif()
endforeach()
foreach(translator_wrapper IN LISTS translator_wrappers)
if( wrapper_name STREQUAL translator_wrapper )
list(APPEND translator_wrapper_files ${wrapper_file})
set(notfound FALSE)
break()
endif()
endforeach()
if( notfound )
list(APPEND core_wrapper_files ${wrapper_file})
endif()
endforeach()
#message("model_wrapper_files = ${model_wrapper_files}")
#message("translator_wrapper_files = ${translator_wrapper_files}")
#message("core_wrapper_files = ${core_wrapper_files}")
set_source_files_properties(${ALL_CSHARP_WRAPPER_FILES} PROPERTIES GENERATED TRUE)
add_library(
openstudio_csharp
SHARED # Was "MODULE" on Windows before
${core_wrapper_files}
)
add_dependencies(openstudio_csharp ${ALL_CSHARP_WRAPPER_TARGETS})
# TODO: Remove
# DLM: currently there are some multiply defined symbols, force them for now, investigate later
# Note JM 2019-10-07:
# eg: multiple definition of `CSharp_OpenStudio_LeftShift__SWIG_1'
# This is due to the ostream << operators
target_link_libraries(openstudio_csharp
PRIVATE
openstudiolib
csharp_warnings
)
install(TARGETS openstudio_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
install(TARGETS openstudio_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS RELEASE COMPONENT "CSharpAPI")
add_library(
openstudio_model_csharp
SHARED # Was "MODULE" on Windows before
${model_wrapper_files}
)
add_dependencies(openstudio_model_csharp ${ALL_CSHARP_WRAPPER_TARGETS})
target_link_libraries(openstudio_model_csharp
PRIVATE
openstudiolib
csharp_warnings
)
install(TARGETS openstudio_model_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
install(TARGETS openstudio_model_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS RELEASE COMPONENT "CSharpAPI")
add_library(
openstudio_translators_csharp
SHARED # Was "MODULE" on Windows before
${translator_wrapper_files}
)
add_dependencies(openstudio_translators_csharp ${ALL_CSHARP_WRAPPER_TARGETS})
target_link_libraries(openstudio_translators_csharp
PRIVATE
openstudiolib
csharp_warnings
)
install(TARGETS openstudio_translators_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
install(TARGETS openstudio_translators_csharp DESTINATION CSharp/openstudio/ CONFIGURATIONS RELEASE COMPONENT "CSharpAPI")
# convenience target to build the SDK
add_custom_target(csharp_sdk ALL
DEPENDS ${OPENSTUDIO_CSHARP_DLL} openstudio_csharp openstudio_model_csharp openstudio_translators_csharp
)