Skip to content

Commit

Permalink
fix(csharp): clean up CMakeLists
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed May 7, 2022
1 parent f303523 commit 84f36ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 209 deletions.
96 changes: 18 additions & 78 deletions csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ set(CSHARP_ASSEMBLY_VERSION "${CSHARP_VERSION_MAJOR}.${CSHARP_VERSION_MINOR}.${C
set(CSHARP_TOOLS_VERSION "4.5")

file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/csharp_wrapper/generated_sources")
if(MSVC)
configure_file("${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/OpenStudio.csproj.in" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj")
else()
configure_file("${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/OpenStudio.csproj_dotnet.in" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj")
endif()
configure_file("${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/OpenStudio.csproj.in" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj")

# Trying to get rid of this by placing more attributes in csproj instead
if (MSVC)
configure_file("${PROJECT_SOURCE_DIR}/csharp/developer/OpenStudio/Properties/AssemblyVersion.cs.in" "${PROJECT_BINARY_DIR}/csharp_wrapper/generated_sources/AssemblyVersion.cs")
endif()

#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.
Expand All @@ -48,61 +40,29 @@ endif()

# the main OpenStudio.dll generated

if (MSVC)
# TODO: Remove
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /FORCE:MULTIPLE")

if(NINJA)
set(OPENSTUDIO_CSHARP_DLL "${CSHARP_LIBRARY_OUTPUT_DIRECTORY}/OpenStudio.dll")
set(CONFIG_ARGS "/p:Configuration=${CMAKE_BUILD_TYPE}")
else()
# **Regular case, pure MSVC**
set(OPENSTUDIO_CSHARP_DLL "${CSHARP_LIBRARY_OUTPUT_DIRECTORY}/$(ConfigurationName)/OpenStudio.dll")
set(CONFIG_ARGS "/p:Configuration=$(ConfigurationName)")
endif()

# ignore deprecated warnings since we will export deprecated methods
add_definitions(/wd4996 /bigobj)

# custom command to make OPENSTUDIO_CSHARP_DLL
add_custom_command(
OUTPUT ${OPENSTUDIO_CSHARP_DLL}
COMMAND "MSBuild" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj" "${CONFIG_ARGS}"
DEPENDS ${ALL_CSHARP_WRAPPER_TARGETS} ${ALL_CSHARP_WRAPPER_FILES}
)
# 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()

if(NINJA)
install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp/OpenStudio.dll" DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
else()
# **Regular case, pure MSVC**
install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp/Debug/OpenStudio.dll" DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")
install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp/Release/OpenStudio.dll" DESTINATION CSharp/openstudio/ CONFIGURATIONS RELEASE COMPONENT "CSharpAPI")
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")

else()
# 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()
# ignore deprecated warnings since we will export deprecated methods
add_definitions(-Wno-deprecated-declarations)

# TODO: there are probably adjustments to make to OpenStudio.csproj_dotnet.in
# 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")
# custom command to make OPENSTUDIO_CSHARP_DLL
add_custom_command(
OUTPUT ${OPENSTUDIO_CSHARP_DLL}
COMMAND "${DOTNET}" "build" "-c" "$<CONFIGURATION>" "-f" "netstandard2.0" "${PROJECT_BINARY_DIR}/csharp_wrapper/OpenStudio.csproj"
DEPENDS ${ALL_CSHARP_WRAPPER_TARGETS} ${ALL_CSHARP_WRAPPER_FILES}
)

# ignore deprecated warnings since we will export deprecated methods
add_definitions(-Wno-deprecated-declarations)
install(FILES "${OPENSTUDIO_CSHARP_DLL}" DESTINATION CSharp/openstudio/ CONFIGURATIONS DEBUG COMPONENT "CSharpAPI")

# custom command to make OPENSTUDIO_CSHARP_DLL
add_custom_command(
OUTPUT ${OPENSTUDIO_CSHARP_DLL}
COMMAND "${DOTNET}" "build" "-c" "$<CONFIGURATION>" "-f" "netstandard2.0" "${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")
endif()

# keep the following lists aligned with translator_names in ProjectMacros.cmake
set(translator_wrappers
Expand Down Expand Up @@ -257,23 +217,6 @@ if( BUILD_NUGET_PACKAGE )
INSTALL_COMMAND ""
)

# This is used in the OpenStudio.nuspec template
# One problem. What if 64 bit is configured with ninja,
# but 32 bit is configured without ninja?
if(NINJA)
set(OPENSTUDIO_CONFIGURATION_TYPE "")
else()
# Regular case: pure MSVC
set(OPENSTUDIO_CONFIGURATION_TYPE "$CONFIGURATION$")
endif()

configure_file( ${PROJECT_SOURCE_DIR}/csharp/OpenStudio.nuspec.in ${PROJECT_BINARY_DIR}/OpenStudio.nuspec )

add_custom_target(nuget_package
COMMAND NuGet pack OpenStudio.nuspec -BasePath "${PROJECT_BINARY_DIR}/" -properties Configuration=$<CONFIGURATION>
DEPENDS csharp_sdk
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
)
elseif(APPLE)
set(OPENSTUDIO_CSHARP_DLLNAME "Products/csharp/$CONFIGURATION$/netstandard2.0/OpenStudio.dll")
set(OPENSTUDIO_CSHARP_LIBNAME "Products/libopenstudio_csharp.dylib")
Expand All @@ -286,9 +229,6 @@ if( BUILD_NUGET_PACKAGE )
set(OPENSTUDIO_MODEL_CSHARP_LIBNAME "Products/libopenstudio_model_csharp.so")
set(OPENSTUDIO_TRANSLATORS_CSHARP_LIBNAME "Products/libopenstudio_translators_csharp.so")

# TODO: Remove altogether? For dotnet I'm trying to use the nuget properties metadata directly in csproj, but not managing to do it
configure_file( ${PROJECT_SOURCE_DIR}/csharp/OpenStudio.nuspec.in ${PROJECT_BINARY_DIR}/OpenStudio.nuspec )

#dotnet pack OpenStudio.csproj --configuration $<CONFIG> -p:NuspecFile="${PROJECT_BINARY_DIR}/OpenStudio.nuspec" -p:NuspectProperties="Configuration=$<CONFIG>"
# dotnet pack <path to .csproj file> -p:NuspecFile=<path to nuspec file> -p:NuspecProperties=<> -p:NuspecBasePath=<Base path>
add_custom_target(nuget_package
Expand Down
120 changes: 61 additions & 59 deletions csharp/developer/OpenStudio/OpenStudio.csproj.in
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="${CSHARP_TOOLS_VERSION}" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">${CSHARP_PLATFORM}</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{63F7E86E-6A41-4033-A5C6-E41015F5AD4B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenStudio</RootNamespace>
<AssemblyName>OpenStudio</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>${CSHARP_SOURCE_DIR}\developer\OpenStudio\StrongNameKeyFile.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|${CSHARP_PLATFORM}' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>${CSHARP_LIBRARY_OUTPUT_DIRECTORY}\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>


<!-- CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' -->
<!-- CS0108: iddObjectType() hides inherited member ModelObject.iddObjectType() -->
<!-- CS2002: source file specified multiple times: CANNOT BE SUPPRESSED, cf https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/nowarn-compiler-option-->
<NoWarn>1591,0108,2002</NoWarn>
<WarningLevel>4</WarningLevel>
<DocumentationFile>${CSHARP_LIBRARY_OUTPUT_DIRECTORY}\Debug\OpenStudio.xml</DocumentationFile>
<NoWarn>1591,0108</NoWarn>


<!-- NuGet metadata properties -->
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<Product>OpenStudio</Product>
<Version>${CSHARP_ASSEMBLY_VERSION}</Version>
<Copyright>Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved.</Copyright>
<Description>OpenStudio C# bindings for whole building energy simulation</Description>
<RepositoryUrl>https://github.com/NREL/OpenStudio</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Authors>NREL</Authors>
<PackageTags>OpenStudio;EnergyPlus;Simulation;Modeling</PackageTags>
<!-- Deprecated -->
<PackageLicenseUrl>http://github.com/NREL/OpenStudio/blob/develop/LICENSE.md</PackageLicenseUrl>


</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|${CSHARP_PLATFORM}' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>${CSHARP_LIBRARY_OUTPUT_DIRECTORY}\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>${CSHARP_LIBRARY_OUTPUT_DIRECTORY}\Release\OpenStudio.xml</DocumentationFile>
<NoWarn>1591,0108</NoWarn> <!-- CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member', CS0108: iddObjectType() hides inherited member ModelObject.iddObjectType() -->

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>

<!-- Linux:
libopenstudio_csharp.so
libopenstudio_model_csharp.so
libopenstudio_translators_csharp.so
libopenstudiolib.so
-->

<!-- Mac:
libopenstudio_csharp.dylib
libopenstudio_model_csharp.dylib
libopenstudio_translators_csharp.dylib
libopenstudiolib.dylib
-->

<!-- Windows:
openstudio_csharp.dll
openstudio_model_csharp.dll
openstudio_translators_csharp.dll
openstudiolib.dll
-->
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="${CSHARP_SOURCE_DIR}\developer\OpenStudio\Properties\AssemblyInfo.cs" />
<Compile Include="${CSHARP_BINARY_DIR}\generated_sources\*.cs" />
<Compile Include="${CSHARP_BINARY_DIR}\generated_sources\*\*.cs" />
</ItemGroup>
<ItemGroup>
<None Include="${CSHARP_SOURCE_DIR}\developer\OpenStudio\StrongNameKeyFile.snk" />
<Content Include="../Products//*openstudio*csharp.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
<Content Include="../Products//*openstudiolib.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>


</Project>
72 changes: 0 additions & 72 deletions csharp/developer/OpenStudio/OpenStudio.csproj_dotnet.in

This file was deleted.

0 comments on commit 84f36ac

Please sign in to comment.