diff --git a/cmake/dotnet.cmake b/cmake/dotnet.cmake index a492ede071..5341c72d2e 100644 --- a/cmake/dotnet.cmake +++ b/cmake/dotnet.cmake @@ -2,9 +2,68 @@ if(NOT BUILD_DOTNET) return() endif() +if(NOT TARGET ortools::ortools) + message(FATAL_ERROR "Java: missing ortools TARGET") +endif() + find_package(SWIG) +include(UseSWIG) + +# Generate Protobuf .Net sources +set(PROTO_DOTNETS) +file(GLOB_RECURSE proto_dotnet_files RELATIVE ${PROJECT_SOURCE_DIR} + "ortools/constraint_solver/*.proto" + "ortools/linear_solver/*.proto" + "ortools/sat/*.proto" + "ortools/util/*.proto" + ) +list(REMOVE_ITEM proto_dotnet_files "ortools/constraint_solver/demon_profiler.proto") +foreach(PROTO_FILE ${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) + set(PROTO_DOTNET ${PROJECT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME}.pb.cs) + #message(STATUS "protoc dotnet: ${PROTO_DOTNET}") + add_custom_command( + OUTPUT ${PROTO_DOTNET} + COMMAND protobuf::protoc + "--proto_path=${PROJECT_SOURCE_DIR}" + "--csharp_out=${PROJECT_BINARY_DIR}" + "--csharp_opt=file_extension=.pb.cs" + ${PROTO_FILE} + DEPENDS ${PROTO_FILE} protobuf::protoc + COMMENT "Running C++ protocol buffer compiler on ${PROTO_FILE}" + VERBATIM) + list(APPEND PROTO_DOTNETS ${PROTO_DOTNET}) +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) +if(USE_COINOR) + list(APPEND FLAGS + "-DUSE_CBC" + "-DUSE_CLP" + ) +endif() +list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}") + +foreach(SUBPROJECT constraint_solver linear_solver sat graph algorithms data) + #add_subdirectory(ortools/${SUBPROJECT}/csharp) +endforeach() + +# Main Target +add_custom_target(dotnet_package ALL + DEPENDS ${PROJECT_NAME}.csproj + COMMAND ${CMAKE_COMMAND} -E remove_directory packages + COMMAND ${DOTNET_CLI} package ${PROJECT_NAME}.csproj + ) + +# Test if(BUILD_TESTING) add_subdirectory(examples/dotnet) endif() diff --git a/cmake/java.cmake b/cmake/java.cmake index 39619dbd87..0020729268 100644 --- a/cmake/java.cmake +++ b/cmake/java.cmake @@ -2,14 +2,68 @@ if(NOT BUILD_JAVA) return() endif() -find_package(SWIG REQUIRED) -find_package(JAVA REQUIRED) -find_package(JNI REQUIRED) - if(NOT TARGET ortools::ortools) message(FATAL_ERROR "Java: missing ortools TARGET") endif() +find_package(SWIG REQUIRED) +include(UseSWIG) + +# Generate Protobuf java sources +set(PROTO_JAVAS) +file(GLOB_RECURSE proto_java_files RELATIVE ${PROJECT_SOURCE_DIR} + "ortools/constraint_solver/*.proto" + "ortools/linear_solver/*.proto" + "ortools/sat/*.proto" + "ortools/util/*.proto" + ) +list(REMOVE_ITEM proto_java_files "ortools/constraint_solver/demon_profiler.proto") +foreach(PROTO_FILE ${proto_java_files}) + #message(STATUS "protoc proto(java): ${PROTO_FILE}") + get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY) + get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE) + set(PROTO_JAVA ${PROJECT_BINARY_DIR}/java/com/google/${PROTO_DIR}/${PROTO_NAME}.java) + #message(STATUS "protoc java: ${PROTO_JAVA}") + add_custom_command( + OUTPUT ${PROTO_JAVA} + COMMAND protobuf::protoc + "--proto_path=${PROJECT_SOURCE_DIR}" + "--java_out=${PROJECT_BINARY_DIR}/java" + ${PROTO_FILE} + DEPENDS ${PROTO_FILE} protobuf::protoc + COMMENT "Running C++ protocol buffer compiler on ${PROTO_FILE}" + VERBATIM) + list(APPEND PROTO_JAVAS ${PROTO_JAVA}) +endforeach() +add_custom_target(Java${PROJECT_NAME}_proto DEPENDS ${PROTO_JAVAS} ortools::ortools) + +# Setup Java +find_package(JAVA 1.8 REQUIRED COMPONENTS Development) +find_package(JNI REQUIRED) + +# 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) +if(USE_COINOR) + list(APPEND FLAGS + "-DUSE_CBC" + "-DUSE_CLP" + ) +endif() +list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}") + +foreach(SUBPROJECT constraint_solver linear_solver sat graph algorithms data) + #add_subdirectory(ortools/${SUBPROJECT}/java) +endforeach() + +# Main Target +add_custom_target(java_package ALL + DEPENDS pom.xml + COMMAND ${CMAKE_COMMAND} -E remove_directory dist + COMMAND ${Java_JAVAC_EXECUTABLE} pom.xml + ) + +# Test if(BUILD_TESTING) add_subdirectory(examples/java) endif() diff --git a/cmake/python.cmake b/cmake/python.cmake index 083558263e..a3f345d12a 100644 --- a/cmake/python.cmake +++ b/cmake/python.cmake @@ -53,7 +53,13 @@ endif() # 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 -DUSE_CBC -DUSE_CLP -DMUST_USE_RESULT) +set(FLAGS -DUSE_BOP -DUSE_GLOP -DABSL_MUST_USE_RESULT) +if(USE_COINOR) + list(APPEND FLAGS + "-DUSE_CBC" + "-DUSE_CLP" + ) +endif() list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}") foreach(SUBPROJECT constraint_solver linear_solver sat graph algorithms data) @@ -167,10 +173,11 @@ function(search_python_module MODULE_NAME) endfunction() # Look for python module wheel +search_python_module(setuptools) search_python_module(wheel) # Main Target -add_custom_target(bdist ALL +add_custom_target(python_package ALL DEPENDS setup.py Py${PROJECT_NAME}_proto COMMAND ${CMAKE_COMMAND} -E remove_directory dist COMMAND ${PYTHON_EXECUTABLE} setup.py bdist bdist_wheel @@ -189,7 +196,7 @@ if(BUILD_TESTING) set(VENV_BIN_DIR ${VENV_DIR}/bin) endif() # make a virtualenv to install our python package in it - add_custom_command(TARGET bdist POST_BUILD + add_custom_command(TARGET python_package POST_BUILD COMMAND ${VENV_EXECUTABLE} -p ${PYTHON_EXECUTABLE} ${VENV_DIR} COMMAND ${VENV_BIN_DIR}/python setup.py install COMMAND ${CMAKE_COMMAND} -E copy diff --git a/ortools/constraint_solver/python/CMakeLists.txt b/ortools/constraint_solver/python/CMakeLists.txt index ee66551a53..da2ae8a4aa 100644 --- a/ortools/constraint_solver/python/CMakeLists.txt +++ b/ortools/constraint_solver/python/CMakeLists.txt @@ -1,10 +1,4 @@ -# Setup SWIG -find_package(SWIG REQUIRED) -include(UseSWIG) - -# Setup Python -find_package(PythonInterp REQUIRED) -find_package(PythonLibs REQUIRED) +# depends on cmake/python.cmake set_property(SOURCE routing.i PROPERTY CPLUSPLUS ON) list(APPEND CMAKE_SWIG_FLAGS "-module;pywrapcp")