Skip to content

Commit

Permalink
To be honest, I do not quite remember everything I changed here. But …
Browse files Browse the repository at this point in the history
…it is all good, I tell ya.
  • Loading branch information
ahmad-el-sayed committed Oct 17, 2024
1 parent e0e9891 commit 74e1e31
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 66 deletions.
9 changes: 7 additions & 2 deletions cmake/cached_globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif()
set(
GLOB_UGRID_PROJECT_VERSION
"${UGRID_PROJECT_VERSION_MAJOR}.${UGRID_PROJECT_VERSION_MINOR}.${UGRID_PROJECT_VERSION_PATCH}.${UGRID_PROJECT_VERSION_TWEAK}"
CACHE STRING ".NET target framework"
CACHE STRING "Project version"
)

# year
Expand All @@ -19,7 +19,12 @@ set(GLOB_CURRENT_YEAR ${GLOB_CURRENT_YEAR} CACHE STRING "Current year")

# .NET config
if(WIN32 AND BUILD_DOTNET_WRAPPER)
set(GLOB_DOTNET_TARGET_FRAMEWORK "net481" CACHE STRING ".NET target framework")
set(GLOB_LIB_DOTNET_TARGET_FRAMEWORK "netstandard2.0;net481;net6.0;net8.0" CACHE STRING "Library .NET target framework")
set(GLOB_TEST_DOTNET_TARGET_FRAMEWORK "net481;net6.0;net8.0" CACHE STRING "Test .NET target framework")

#set(GLOB_LIB_DOTNET_TARGET_FRAMEWORK "netstandard2.0" CACHE STRING "Library .NET target framework")
#set(GLOB_TEST_DOTNET_TARGET_FRAMEWORK "net481" CACHE STRING "Test .NET target framework")

set(GLOB_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8.1" CACHE STRING ".NET target framework version")
set(GLOB_DOTNET_SDK "Microsoft.NET.Sdk" CACHE STRING ".NET SDK")
set(GLOB_CSHARP_LANGUAGE_VERSION "7.3" CACHE STRING "C# Compiler Options for language feature rules")
Expand Down
16 changes: 15 additions & 1 deletion cmake/user_config_options.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(CMakeDependentOption)

# unit testing option
option(
ENABLE_UNIT_TESTING
Expand All @@ -14,4 +16,16 @@ if(LINUX AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
)
endif()

option(BUILD_DOTNET_WRAPPER "Configures and builds the C# targets that use code generated by SWIG" OFF)
option(
BUILD_DOTNET_WRAPPER
"Configures and builds the C# targets that use code generated by SWIG"
OFF
)

cmake_dependent_option(
PACK_NUPKG_LOCALLY
"Pack the NuGet package locally. Should be used only to verify packages locally."
ON
"BUILD_DOTNET_WRAPPER"
OFF
)
6 changes: 0 additions & 6 deletions libs/UGridNET/config/App.config.in

This file was deleted.

10 changes: 2 additions & 8 deletions libs/UGridNET/config/Directory.Build.props.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
<Product>UGrid</Product>
<Version>@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.@PROJECT_VERSION_TWEAK@</Version>
<FileVersion>@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.@PROJECT_VERSION_TWEAK@</FileVersion>

<TargetFramework>@GLOB_DOTNET_TARGET_FRAMEWORK@</TargetFramework>

<!-- <GenerateAssemblyInfo>true</GenerateAssemblyInfo> -->
<!-- <OutputPath>$(SolutionDir)$(Configuration)\</OutputPath> -->
<!-- <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> -->
<!-- <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> -->
<!-- <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies> -->
<TargetFrameworks>@PROJECT_DOTNET_TARGET_FRAMEWORKS@</TargetFrameworks>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
</Project>
13 changes: 2 additions & 11 deletions libs/UGridNET/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ project(
# target name
set(TARGET_NAME ${PROJECT_NAME})

set(APP_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/App.config)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/App.config.in
${APP_CONFIG}
@ONLY
)

set(NUGET_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/NuGet.config)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/NuGet.config
${NUGET_CONFIG}
COPYONLY
)

set(PROJECT_DOTNET_TARGET_FRAMEWORKS ${GLOB_LIB_DOTNET_TARGET_FRAMEWORK})
set(DIRECTORY_BUILD_PROPS ${CMAKE_CURRENT_BINARY_DIR}/Directory.Build.props)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/Directory.Build.props.in
Expand Down Expand Up @@ -49,7 +43,6 @@ execute_process(
add_library(
${TARGET_NAME}
SHARED
${APP_CONFIG}
${NUGET_CONFIG}
${DIRECTORY_PACKAGES_PROPS}
${DIRECTORY_BUILD_PROPS}
Expand All @@ -59,9 +52,7 @@ add_library(
set_target_properties(
${TARGET_NAME}
PROPERTIES
DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK}
DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION}
DOTNET_TARGET_FRAMEWORK "${GLOB_LIB_DOTNET_TARGET_FRAMEWORK}"
DOTNET_SDK ${GLOB_DOTNET_SDK}
VS_DOTNET_REFERENCES "System"
VS_PACKAGE_REFERENCES "${PACKAGE_REFERENCES}"
)
37 changes: 36 additions & 1 deletion libs/UGridNET/nuget/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Configure the nuspec files
project(
UGridNET.NuGetPack
VERSION ${CMAKE_PROJECT_VERSION}
DESCRIPTION "Configures and conditionally generates the UGridNET NuGet package"
LANGUAGES NONE
)

set(TARGET_NAME ${PROJECT_NAME})

string(SUBSTRING ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION} 1 -1 DOTNET_TARGET_FRAMEWORK_VERSION_WITHOUT_V_PREFIX)

Expand All @@ -12,8 +20,21 @@ if(${GIT_FOUND})
endif()
endif()

# Add dependencies and files to nuspec ocnfig template
execute_process(
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/configure_nuspec.py
--template ${CMAKE_CURRENT_SOURCE_DIR}/Deltares.UGridNET.nuspec.in
--destination ${CMAKE_CURRENT_BINARY_DIR}/Deltares.UGridNET.nuspec.preconfig
--dotnet_target_frameworks ${GLOB_LIB_DOTNET_TARGET_FRAMEWORK}
OUTPUT_VARIABLE PACKAGE_REFERENCES
RESULT_VARIABLE RETURN_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL LAST
)

# Then substitute the CMake variables
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Deltares.UGridNET.nuspec.in
${CMAKE_CURRENT_BINARY_DIR}/Deltares.UGridNET.nuspec.preconfig
${CMAKE_CURRENT_BINARY_DIR}/Deltares.UGridNET.nuspec
@ONLY
)
Expand All @@ -31,3 +52,17 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/README.md
COPYONLY
)

if(PACK_NUPKG_LOCALLY)
add_custom_target(
${TARGET_NAME} ALL
DEPENDS
"$<TARGET_NAME:UGridCSharpWrapper>"
"$<TARGET_NAME:UGridNET>"
COMMAND ${NUGET_EXECUTABLE} pack ${CMAKE_CURRENT_BINARY_DIR}/Deltares.UGridNET.nuspec
-OutputDirectory ${CMAKE_CURRENT_BINARY_DIR}/packed
-Properties Configuration=Release
-Verbosity detailed
COMMENT "Executing NuGet pack"
)
endif()
7 changes: 0 additions & 7 deletions libs/UGridNET/nuget/Deltares.UGridNET.nuspec.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
<readme>README.md</readme>

<dependencies>
<group targetFramework=".NETFramework@DOTNET_TARGET_FRAMEWORK_VERSION_WITHOUT_V_PREFIX@" />
</dependencies>
</metadata>
<files>
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\dll\Release\UGridNET.dll" target="lib\@GLOB_DOTNET_TARGET_FRAMEWORK@\UGridNET.dll" />
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\SWIG\Release\UGridCSharpWrapper.dll" target="runtimes\win-x64\native\" />
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\SWIG\Release\UGridCSharpWrapper.lib" target="runtimes\win-x64\native\" />
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\SWIG\Release\UGridCSharpWrapper.exp" target="runtimes\win-x64\native\" />
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\nuget\Deltares.UGridNET.targets" target="build\@GLOB_DOTNET_TARGET_FRAMEWORK@\" />
<file src="@CMAKE_BINARY_DIR@\libs\UGridNET\nuget\README.md" target="" />
</files>
</package>
4 changes: 2 additions & 2 deletions libs/UGridNET/nuget/Deltares.UGridNET.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="UGridNETPostBuild" AfterTargets="Build">
<ItemGroup>
<_FilesToCopyUGridNET Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\**\*"/>
<_FilesToCopyUGridNET Include="$(MSBuildThisFileDirectory)..\..\..\runtimes\win-x64\native\**\*"/>
</ItemGroup>
<Copy SourceFiles="@(_FilesToCopyUGridNET)" DestinationFolder="$(OutDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
</Target>
<Target Name="UGridNETClean" AfterTargets="Clean">
<ItemGroup>
<_OriginalFilesUGridNET Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\**\*"/>
<_OriginalFilesUGridNET Include="$(MSBuildThisFileDirectory)..\..\..\runtimes\win-x64\native\**\*"/>
<_FilesToCleanUGridNET Include="$(OutDir)\win-x64\native\%(_OriginalFilesUGridNET.RecursiveDir)%(_OriginalFilesUGridNET.FileName)%(_OriginalFilesUGridNET.Extension)"/>
</ItemGroup>
<Delete Files="@(_FilesToCleanUGridNET)"/>
Expand Down
20 changes: 18 additions & 2 deletions libs/UGridNET/post_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ project(

set(TARGET_NAME ${PROJECT_NAME})


set(COPY_COMMANDS)

foreach(LIB_DOTNET_TARGET_FRAMEWORK ${GLOB_LIB_DOTNET_TARGET_FRAMEWORK})
list(
APPEND
COPY_COMMANDS
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET>/${LIB_DOTNET_TARGET_FRAMEWORK}")
endforeach()

foreach(TEST_DOTNET_TARGET_FRAMEWORK ${GLOB_TEST_DOTNET_TARGET_FRAMEWORK})
list(
APPEND
COPY_COMMANDS
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET.Tests>/${TEST_DOTNET_TARGET_FRAMEWORK}")
endforeach()

add_custom_target(
${TARGET_NAME} ALL
DEPENDS
"$<TARGET_NAME:UGridCSharpWrapper>"
"$<TARGET_NAME:UGridNET>"
"$<TARGET_NAME:UGridNET.Tests>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET.Tests>"
${COPY_COMMANDS}
COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNET> and $<TARGET_FILE_DIR:UGridNET.Tests>"
)
2 changes: 1 addition & 1 deletion libs/UGridNET/pre_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_custom_target(
-Force
-NoHttpCache
-Verbosity detailed
-ConfigFile ${CMAKE_CURRENT_BINARY_DIR}/../test/NuGet.config
-ConfigFile ${CMAKE_CURRENT_BINARY_DIR}/../dll/NuGet.config
COMMAND ${NUGET_EXECUTABLE} restore ${CMAKE_CURRENT_BINARY_DIR}/../test/UGridNET.Tests.sln
-Force
-NoHttpCache
Expand Down
16 changes: 4 additions & 12 deletions libs/UGridNET/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ project(
# target name
set(TARGET_NAME ${PROJECT_NAME})

set(APP_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/App.config)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/App.config.in
${APP_CONFIG}
@ONLY
)

set(NUGET_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/NuGet.config)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/NuGet.config
${NUGET_CONFIG}
COPYONLY
)

set(PROJECT_DOTNET_TARGET_FRAMEWORKS ${GLOB_TEST_DOTNET_TARGET_FRAMEWORK})
set(DIRECTORY_BUILD_PROPS ${CMAKE_CURRENT_BINARY_DIR}/Directory.Build.props)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../config/Directory.Build.props.in
Expand All @@ -46,9 +40,9 @@ execute_process(
COMMAND_ERROR_IS_FATAL LAST
)

add_library(${TARGET_NAME}
add_library(
${TARGET_NAME}
SHARED
${APP_CONFIG}
${NUGET_CONFIG}
${DIRECTORY_PACKAGES_PROPS}
${DIRECTORY_BUILD_PROPS}
Expand All @@ -60,9 +54,7 @@ target_link_libraries(${TARGET_NAME} PRIVATE "$<TARGET_NAME:UGridNET>")
set_target_properties(
${TARGET_NAME}
PROPERTIES
DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK}
DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION}
DOTNET_TARGET_FRAMEWORK "${GLOB_TEST_DOTNET_TARGET_FRAMEWORK}"
DOTNET_SDK ${GLOB_DOTNET_SDK}
VS_DOTNET_REFERENCES "System;System.Runtime.CompilerServices.Unsafe"
VS_PACKAGE_REFERENCES "${PACKAGE_REFERENCES}"
)
4 changes: 2 additions & 2 deletions libs/UGridNET/test/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="NUnit" Version="4.2.0" />
<PackageVersion Include="NUnit.ConsoleRunner" Version="3.18.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit.ConsoleRunner" Version="3.18.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion libs/UGridNET/test/src/UGridNETTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TestMesh1DReadAndInquire()
{
int result = -1;

const string filePath = "..\\..\\..\\..\\..\\tests\\data\\AllUGridEntities.nc";
const string filePath = "..\\..\\..\\..\\..\\..\\tests\\data\\AllUGridEntities.nc";
int fileMode = -1;

result = UGrid.ug_file_read_mode(ref fileMode);
Expand Down
Loading

0 comments on commit 74e1e31

Please sign in to comment.