Skip to content

Commit

Permalink
Fix post build custom command incompatibility with DOTNET_SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed committed Aug 29, 2024
1 parent 29d80bf commit eb0e1cd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 65 deletions.
17 changes: 2 additions & 15 deletions cmake/cached_globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@ string(TIMESTAMP GLOB_CURRENT_YEAR "%Y")
set(GLOB_CURRENT_YEAR ${GLOB_CURRENT_YEAR} CACHE STRING "Current year")

if(WIN32 AND BUILD_DOTNET_WRAPPER)
# set(GLOB_DOTNET_TARGET_FRAMEWORK "net462" CACHE STRING ".NET target framework")
# set(GLOB_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.2" CACHE STRING ".NET target framework version")
# set(GLOB_CSHARP_LANGUAGE_VERSION "6" CACHE STRING "C# Compiler Options for language feature rules")

# set(GLOB_DOTNET_TARGET_FRAMEWORK "net472" CACHE STRING ".NET target framework")
# set(GLOB_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2" CACHE STRING ".NET target framework version")
# set(GLOB_CSHARP_LANGUAGE_VERSION "7.3" CACHE STRING "C# Compiler Options for language feature rules")

#set(GLOB_DOTNET_TARGET_FRAMEWORK "netstandard2.0" CACHE STRING ".NET target framework")
set(GLOB_DOTNET_TARGET_FRAMEWORK "net481" CACHE STRING ".NET target framework")
set(GLOB_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8.1" CACHE STRING ".NET target framework version")
set(GLOB_CSHARP_LANGUAGE_VERSION "7.3" CACHE STRING "C# Compiler Options for language feature rules")

# set(GLOB_DOTNET_TARGET_FRAMEWORK "net40" CACHE STRING ".NET target framework")
# set(GLOB_DOTNET_TARGET_FRAMEWORK_VERSION "v4.0.0" CACHE STRING ".NET target framework version")
# set(GLOB_CSHARP_LANGUAGE_VERSION "4" CACHE STRING "C# Compiler Options for language feature rules")

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")
set(GLOB_DOTNET_TARGET_PLATFORM "x64" CACHE STRING ".NET target platform")
endif()
8 changes: 5 additions & 3 deletions libs/UGridNET/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set(TOOLS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/tools)
add_subdirectory(SWIG)

# default .NET Framework
set(CMAKE_DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK})
set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION})
set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
# set(CMAKE_DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK})
# set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION})
# set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")

#set(CMAKE_CSharp_FLAGS "${CMAKE_CSharp_FLAGS} /platform:${GLOB_DOTNET_TARGET_PLATFORM}")
#set(CMAKE_CSharp_FLAGS "/langversion:${GLOB_CSHARP_LANGUAGE_VERSION}")
Expand All @@ -21,3 +21,5 @@ add_subdirectory(dll)
# Add the UGridNET tests
add_subdirectory(test)

add_subdirectory(post_build)

26 changes: 4 additions & 22 deletions libs/UGridNET/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,10 @@ execute_process(

set_target_properties(
${TARGET_NAME}
PROPERTIES
PROPERTIES
DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK}
DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION}
DOTNET_SDK ${GLOB_DOTNET_SDK}
VS_DOTNET_REFERENCES "System"
VS_PACKAGE_REFERENCES "System.Buffers_4.5.1;System.Memory_4.5.5"
)

# Copy UGridCSWrapper
# when CMAKE_DOTNET_SDK is set to "Microsoft.NET.Sdk", cmake does not like add_custom_command anymore
# add_custom_command(
# TARGET ${TARGET_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET>"
# COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNET>"
# )
# workaround instead of add_custom_command with POST_BUILD, use a custom target with a dependency
# to make sure the dll to copy is built first

# set(POST_BUILD_TARGET_NAME ${TARGET_NAME}_POST_BUILD)
# add_custom_target(
# ${POST_BUILD_TARGET_NAME} ALL
# COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNET>"
# COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNET>"
# )
# add_dependencies(${POST_BUILD_TARGET_NAME} ${TARGET_NAME})

#add_dependencies(${TARGET_NAME} UGridCSharpWrapper)
14 changes: 14 additions & 0 deletions libs/UGridNET/post_build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project(
UGridNETPostBuildCommands
LANGUAGES NONE
)

set(TARGET_NAME ${PROJECT_NAME})

add_custom_target(
${TARGET_NAME} ALL
DEPENDS UGridCSharpWrapper UGridNET UGridNETTests
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:UGridNETTests>"
COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNET> and $<TARGET_FILE_DIR:UGridNETTests>"
)
31 changes: 7 additions & 24 deletions libs/UGridNET/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,11 @@ execute_process(
)

set_target_properties(
${TARGET_NAME} PROPERTIES
VS_DOTNET_REFERENCES "System;System.Runtime.CompilerServices.Unsafe"
VS_PACKAGE_REFERENCES "NUnit_4.2.0;NUnit.ConsoleRunner_3.18.1;NUnit3TestAdapter_4.6.0"
${TARGET_NAME}
PROPERTIES
DOTNET_TARGET_FRAMEWORK ${GLOB_DOTNET_TARGET_FRAMEWORK}
DOTNET_TARGET_FRAMEWORK_VERSION ${GLOB_DOTNET_TARGET_FRAMEWORK_VERSION}
DOTNET_SDK ${GLOB_DOTNET_SDK}
VS_DOTNET_REFERENCES "System;System.Runtime.CompilerServices.Unsafe"
VS_PACKAGE_REFERENCES "NUnit_4.2.0;NUnit.ConsoleRunner_3.18.1;NUnit3TestAdapter_4.6.0"
)

# Copy UGridCSWrapper
# when CMAKE_DOTNET_SDK is set to "Microsoft.NET.Sdk", cmake does not like add_custom_command anymore
# add_custom_command(
# TARGET ${TARGET_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNETTests>"
# COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNETTests>"
# )
# workaround instead of add_custom_command with POST_BUILD, use a custom target with a dependency
# to make sure the dll to copy is built first

# set(POST_BUILD_TARGET_NAME ${TARGET_NAME}_POST_BUILD)
# add_custom_target(
# ${POST_BUILD_TARGET_NAME} ALL
# COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:UGridCSharpWrapper>" "$<TARGET_FILE_DIR:UGridNETTests>"
# COMMENT "Copy $<TARGET_FILE:UGridCSharpWrapper> to $<TARGET_FILE_DIR:UGridNETTests>"
# )
# add_dependencies(${POST_BUILD_TARGET_NAME} ${TARGET_NAME})

#add_dependencies(${TARGET_NAME} UGridCSharpWrapper)
2 changes: 1 addition & 1 deletion libs/UGridNET/test/src/UGridNETTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void TestMesh1DReadAndInquire()
result = UGridCSharpWrapper.ug_file_open(file_path, file_mode, ref file_id);
Assert.That(result, Is.EqualTo(0));

Console.WriteLine("Hello dikkie dik!");
Console.WriteLine("Hoi dikkie dik!!!");

This comment has been minimized.

Copy link
@lucacarniato

lucacarniato Aug 30, 2024

Contributor

As dflowfm? comment in dutch??

Console.WriteLine(file_id);
Console.WriteLine(file_mode);

Expand Down

0 comments on commit eb0e1cd

Please sign in to comment.