CMake: dotnet rework

.Net: update runtime csproj.in
This commit is contained in:
Corentin Le Molgat
2020-03-05 14:38:02 +01:00
parent 5b6079a6e5
commit 8fee57d205
7 changed files with 65 additions and 46 deletions

View File

@@ -17,6 +17,14 @@ if(UNIX AND NOT APPLE)
list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE64")
endif()
# Setup Dotnet
find_program (DOTNET_EXECUTABLE NAMES dotnet)
if(NOT DOTNET_EXECUTABLE)
message(FATAL_ERROR "Check for dotnet Program: not found")
else()
message(STATUS "Found dotnet Program: ${DOTNET_EXECUTABLE}")
endif()
# Generate Protobuf .Net sources
set(PROTO_DOTNETS)
file(GLOB_RECURSE proto_dotnet_files RELATIVE ${PROJECT_SOURCE_DIR}
@@ -26,7 +34,7 @@ file(GLOB_RECURSE proto_dotnet_files RELATIVE ${PROJECT_SOURCE_DIR}
"ortools/util/*.proto"
)
list(REMOVE_ITEM proto_dotnet_files "ortools/constraint_solver/demon_profiler.proto")
foreach(PROTO_FILE ${proto_dotnet_files})
foreach(PROTO_FILE IN LISTS proto_dotnet_files)
#message(STATUS "protoc proto(dotnet): ${PROTO_FILE}")
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
@@ -47,12 +55,6 @@ foreach(PROTO_FILE ${proto_dotnet_files})
endforeach()
add_custom_target(Dotnet${PROJECT_NAME}_proto DEPENDS ${PROTO_DOTNETS} ortools::ortools)
# Setup Dotnet
find_program (DOTNET_CLI NAMES dotnet)
# CMake will remove all '-D' prefix (i.e. -DUSE_FOO become USE_FOO)
#get_target_property(FLAGS ortools::ortools COMPILE_DEFINITIONS)
set(FLAGS -DUSE_BOP -DUSE_GLOP -DABSL_MUST_USE_RESULT)
# Create the native library
add_library(google-ortools-native SHARED "")
set_target_properties(google-ortools-native PROPERTIES
@@ -64,7 +66,6 @@ if(APPLE)
elseif(UNIX)
set_target_properties(google-ortools-native PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}")
# Swig wrap all libraries
set(OR_TOOLS_DOTNET Google.OrTools)
@@ -77,7 +78,8 @@ endforeach()
## .Net Runtime Package ##
############################
file(COPY tools/doc/orLogo.png DESTINATION dotnet)
file(COPY ortools/dotnet/Directory.Build.props DESTINATION dotnet)
set(DOTNET_PACKAGES_DIR "../packages")
configure_file(ortools/dotnet/Directory.Build.props.in dotnet/Directory.Build.props)
# Build or retrieve .snk file
if(DEFINED ENV{DOTNET_SNK})
@@ -91,8 +93,7 @@ else()
set(OR_TOOLS_DOTNET_SNK CreateSigningKey)
add_custom_command(OUTPUT dotnet/or-tools.snk
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ortools/dotnet/${OR_TOOLS_DOTNET_SNK} ${OR_TOOLS_DOTNET_SNK}
COMMAND
${DOTNET_CLI} run
COMMAND ${DOTNET_EXECUTABLE} run
--project ${OR_TOOLS_DOTNET_SNK}/${OR_TOOLS_DOTNET_SNK}.csproj
/or-tools.snk
COMMENT "Generate or-tools.snk using CreateSigningKey project"
@@ -110,45 +111,69 @@ elseif(WIN32)
else()
message(FATAL_ERROR "Unsupported system !")
endif()
set(OR_TOOLS_DOTNET_NATIVE Google.OrTools.runtime.${RUNTIME_IDENTIFIER})
set(OR_TOOLS_DOTNET_NATIVE ${OR_TOOLS_DOTNET}.runtime.${RUNTIME_IDENTIFIER})
add_custom_target(dotnet_native
DEPENDS
dotnet/or-tools.snk
Dotnet${PROJECT_NAME}_proto
${dotnet_native_targets}
${PROJECT_BINARY_DIR}/dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
COMMAND ${CMAKE_COMMAND} -E make_directory packages
COMMAND ${DOTNET_CLI} build -c Release /p:Platform=x64 ${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
COMMAND ${DOTNET_CLI} pack -c Release ${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
file(GENERATE OUTPUT dotnet/replace_runtime.cmake
CONTENT
"FILE(READ ${PROJECT_SOURCE_DIR}/ortools/dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj.in input)
STRING(REPLACE \"@PROJECT_VERSION@\" \"${PROJECT_VERSION}\" input \"\${input}\")
STRING(REPLACE \"@RUNTIME_IDENTIFIER@\" \"${RUNTIME_IDENTIFIER}\" input \"\${input}\")
STRING(REPLACE \"@OR_TOOLS_DOTNET@\" \"${OR_TOOLS_DOTNET}\" input \"\${input}\")
STRING(REPLACE \"@OR_TOOLS_DOTNET_NATIVE@\" \"${OR_TOOLS_DOTNET_NATIVE}\" input \"\${input}\")
STRING(REPLACE \"@ortools@\" \"$<TARGET_FILE:${PROJECT_NAME}>\" input \"\${input}\")
STRING(REPLACE \"@native@\" \"$<TARGET_FILE:google-ortools-native>\" input \"\${input}\")
FILE(WRITE ${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj \"\${input}\")"
)
add_custom_command(
OUTPUT dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
COMMAND ${CMAKE_COMMAND} -E make_directory ${OR_TOOLS_DOTNET_NATIVE}
COMMAND ${CMAKE_COMMAND} -P $<$<BOOL:${GENERATOR_IS_MULTI_CONFIG}>:$<CONFIG>/>replace_runtime.cmake
WORKING_DIRECTORY dotnet
)
configure_file(
ortools/dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj.in
dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
@ONLY)
add_custom_target(dotnet_native ALL
DEPENDS
dotnet/or-tools.snk
Dotnet${PROJECT_NAME}_proto
google-ortools-native
dotnet/${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
COMMAND ${CMAKE_COMMAND} -E make_directory packages
COMMAND ${DOTNET_EXECUTABLE} build -c Release /p:Platform=x64 ${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
COMMAND ${DOTNET_EXECUTABLE} pack -c Release ${OR_TOOLS_DOTNET_NATIVE}/${OR_TOOLS_DOTNET_NATIVE}.csproj
WORKING_DIRECTORY dotnet
)
# Main Target
file(GENERATE OUTPUT dotnet/$<$<BOOL:${GENERATOR_IS_MULTI_CONFIG}>:$<CONFIG>/>replace.cmake
CONTENT
"FILE(READ ${PROJECT_SOURCE_DIR}/ortools/dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj.in input)
STRING(REPLACE \"@PROJECT_VERSION@\" \"${PROJECT_VERSION}\" input \"\${input}\")
STRING(REPLACE \"@OR_TOOLS_DOTNET@\" \"${OR_TOOLS_DOTNET}\" input \"\${input}\")
STRING(REPLACE \"@DOTNET_PACKAGES_DIR@\" \"${PROJECT_BINARY_DIR}/dotnet/packages\" input \"\${input}\")
FILE(WRITE ${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj \"\${input}\")"
)
add_custom_command(
OUTPUT dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
COMMAND ${CMAKE_COMMAND} -E make_directory ${OR_TOOLS_DOTNET}
COMMAND ${CMAKE_COMMAND} -P $<$<BOOL:${GENERATOR_IS_MULTI_CONFIG}>:$<CONFIG>/>replace.cmake
WORKING_DIRECTORY dotnet
)
add_custom_target(dotnet_package ALL
DEPENDS
dotnet/or-tools.snk
dotnet_native
${PROJECT_BINARY_DIR}/dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
COMMAND ${DOTNET_CLI} build -c Release /p:Platform=x64 ${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
COMMAND ${DOTNET_CLI} pack -c Release ${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
COMMAND ${DOTNET_EXECUTABLE} build -c Release /p:Platform=x64 ${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
COMMAND ${DOTNET_EXECUTABLE} pack -c Release ${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
BYPRODUCTS
dotnet/packages
WORKING_DIRECTORY dotnet
)
configure_file(
ortools/dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj.in
dotnet/${OR_TOOLS_DOTNET}/${OR_TOOLS_DOTNET}.csproj
@ONLY)
# Test
if(BUILD_TESTING)
#add_subdirectory(examples/dotnet)

View File

@@ -4,8 +4,7 @@ set_property(SOURCE knapsack_solver.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE knapsack_solver.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.Algorithms
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_algorithms
TYPE OBJECT
LANGUAGE csharp

View File

@@ -4,8 +4,7 @@ set_property(SOURCE routing.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE routing.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.ConstraintSolver
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_constraint_solver
TYPE OBJECT
LANGUAGE csharp

View File

@@ -4,8 +4,7 @@ set_property(SOURCE graph.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE graph.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.Graph
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_graph
TYPE OBJECT
LANGUAGE csharp

View File

@@ -4,8 +4,7 @@ set_property(SOURCE linear_solver.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE linear_solver.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.LinearSolver
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_linear_solver
TYPE OBJECT
LANGUAGE csharp

View File

@@ -4,8 +4,7 @@ set_property(SOURCE sat.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE sat.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.Sat
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_sat
TYPE OBJECT
LANGUAGE csharp

View File

@@ -4,8 +4,7 @@ set_property(SOURCE sorted_interval_list.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE sorted_interval_list.i PROPERTY COMPILE_OPTIONS
-namespace ${OR_TOOLS_DOTNET}.Util
-dllimport google-ortools-native
)
-dllimport google-ortools-native)
swig_add_library(dotnet_util
TYPE OBJECT
LANGUAGE csharp