#============================================================================= # CMake configuration file for the Chrono CSharp module # # Cannot be used stand-alone (it's loaded by CMake config. file in parent dir.) #============================================================================= option(CH_ENABLE_MODULE_CSHARP "Enable the Chrono CSharp module" OFF) # Return now if this module is not enabled if(NOT CH_ENABLE_MODULE_CSHARP) mark_as_advanced(FORCE SWIG_EXECUTABLE) return() endif() message(STATUS "\n==== Chrono CSharp module ====\n") mark_as_advanced(CLEAR SWIG_EXECUTABLE) #----------------------------------------------------------------------------- # Enable debugging CMake output #----------------------------------------------------------------------------- set(DBG_SCRIPT false) #----------------------------------------------------------------------------- # Find SWIG #----------------------------------------------------------------------------- if (POLICY CMP0122) # from 3.21 only cmake_policy(SET CMP0122 NEW) endif() message(STATUS "Find SWIG") find_package(SWIG REQUIRED COMPONENTS csharp) if(SWIG_FOUND) message(STATUS " SWIG version: ${SWIG_VERSION}") message(STATUS " SWIG csharp found? ${SWIG_csharp_FOUND}") message(STATUS " SWIG executable: ${SWIG_EXECUTABLE}") endif() include(${SWIG_USE_FILE}) # Set location of SWIG-generated files. set(CHRONO_SWIG_OUTDIR "${PROJECT_BINARY_DIR}/chrono_csharp") # Set SWIG flags. Disable selected SWIG warnings # set(CMAKE_SWIG_FLAGS "-c++;-w401,503,833") if(DBG_SCRIPT) message(STATUS "SWIG_USE_FILE: ${SWIG_USE_FILE}") message(STATUS "CMAKE_SWIG_OUTDIR: ${CMAKE_SWIG_OUTDIR}") endif() #----------------------------------------------------------------------------- set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE) # Output library destination if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(LIB_OUT_DIR ${EXECUTABLE_OUTPUT_PATH}) else() set(LIB_OUT_DIR "${PROJECT_BINARY_DIR}/lib") endif() #----------------------------------------------------------------------------- # Post build duplicate removal - for windows and unix (untested) #----------------------------------------------------------------------------- # Checks againt the binary directory (core) and removes duplicates in the glob directory (each module) function(add_csharp_postbuild_command target_name glob_dir binary_dir) if(WIN32) # Windows-specific command add_custom_command( TARGET ${target_name} POST_BUILD #COMMAND ${CMAKE_COMMAND} -E echo "Removing duplicate .cs files from ${target_name} (Windows)" COMMAND for %%f in ("${binary_dir}\\*.cs") do ( if exist "${glob_dir}\\%%~nxf" ( ${CMAKE_COMMAND} -E remove "${glob_dir}\\%%~nxf" ) ) COMMENT "Removed all detected duplicate .cs files wrapped from ${target_name}" ) else() # Unix (possibly MacOS) specific command add_custom_command( TARGET ${target_name} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Removing duplicate .cs files from ${target_name} (Unix-like)" COMMAND for f in \"${binary_dir}\"/*.cs; do ( if [ -f \"${glob_dir}\"/$(basename \"$f\") ]; then ( ${CMAKE_COMMAND} -E remove \"${glob_dir}\"/$(basename \"$f\") ) ) done COMMENT "Removed all detected duplicate .cs files wrapped from ${target_name}" ) endif() endfunction() #----------------------------------------------------------------------------- # Wrapper for CORE Chrono module #----------------------------------------------------------------------------- message(STATUS "Add C# CORE module") set(CMAKE_SWIG_OUTDIR "${CHRONO_SWIG_OUTDIR}/core") # Set interface file. set(INTERFACE_FILE_CORE ChModuleCore_csharp.i) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set_source_files_properties(${INTERFACE_FILE_CORE} PROPERTIES COMPILE_FLAGS "-D_WIN32") endif() if(MSVC) set_source_files_properties(${INTERFACE_FILE_CORE} PROPERTIES COMPILE_OPTIONS "-w833") endif() set_source_files_properties(${INTERFACE_FILE_CORE} PROPERTIES CPLUSPLUS ON) # Create the SWIG module. swig_add_library(Chrono_csharp_core LANGUAGE csharp SOURCES ${INTERFACE_FILE_CORE}) target_link_libraries(Chrono_csharp_core PRIVATE Chrono_core) set_target_properties(Chrono_csharp_core PROPERTIES PROJECT_LABEL "Chrono_csharp_core" OUTPUT_NAME "Chrono_csharp_core" LIBRARY_OUTPUT_DIRECTORY "${LIB_OUT_DIR}" SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE ) if(MSVC) # remove warning for unreachable code generated by SWIG target_compile_options(Chrono_csharp_core PRIVATE "/wd4702") endif() add_dependencies(Chrono_csharp_core Chrono_core) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") install(TARGETS Chrono_csharp_core EXPORT ChronoTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) else() install(TARGETS Chrono_csharp_core EXPORT ChronoTargets LIBRARY DESTINATION lib) endif() if(DBG_SCRIPT) message(STATUS "Module name: Chrono_csharp_core") message(STATUS "SWIG_REAL_NAME: Chrono_csharp_core") endif() #----------------------------------------------------------------------------- # MODULE for the postprocess csharp wrapper. #----------------------------------------------------------------------------- if(CH_ENABLE_MODULE_POSTPROCESS) message(STATUS "Add C# POSTPROCESS module") set(CMAKE_SWIG_OUTDIR "${CHRONO_SWIG_OUTDIR}/postprocess") # Interface files set(INTERFACE_FILE_POSTPROCESS ChModulePostprocess_csharp.i) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set_source_files_properties(${INTERFACE_FILE_POSTPROCESS} PROPERTIES COMPILE_FLAGS "-D_WIN32") endif() set_source_files_properties(${INTERFACE_FILE_POSTPROCESS} PROPERTIES CPLUSPLUS ON) if(MSVC) set_source_files_properties(${INTERFACE_FILE_POSTPROCESS} PROPERTIES COMPILE_OPTIONS "-w401,503") endif() # Create the SWIG module. swig_add_library(Chrono_csharp_postprocess LANGUAGE csharp SOURCES ${INTERFACE_FILE_POSTPROCESS}) target_link_libraries(Chrono_csharp_postprocess PRIVATE Chrono_core Chrono_postprocess) # Ensure that the .cs library files are generated in the bin/ directory. set_target_properties(Chrono_csharp_postprocess PROPERTIES PROJECT_LABEL "Chrono_csharp_postprocess" OUTPUT_NAME "Chrono_csharp_postprocess" LIBRARY_OUTPUT_DIRECTORY "${LIB_OUT_DIR}" SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE ) target_compile_definitions(Chrono_csharp_postprocess PRIVATE "CH_IGNORE_DEPRECATED") target_compile_definitions(Chrono_csharp_postprocess PRIVATE "IGNORE_DEPRECATED_WARNING") add_dependencies(Chrono_csharp_postprocess Chrono_core) add_dependencies(Chrono_csharp_postprocess Chrono_postprocess) add_dependencies(Chrono_csharp_postprocess Chrono_csharp_core) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") install(TARGETS Chrono_csharp_postprocess EXPORT ChronoTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) else() install(TARGETS Chrono_csharp_postprocess EXPORT ChronoTargets LIBRARY DESTINATION lib) endif() if (DBG_SCRIPT) message("Module name: Chrono_csharp_postprocess") message("SWIG_REAL_NAME: Chrono_csharp_postprocess") endif() #------------------------------------------------------Remove duplicates #Uncomment for use # # Custom command to remove duplicate .cs files from the vehicle directory and log the actions # set(GLOB_DIR ${CMAKE_SWIG_OUTDIR}) # set(BINARY_DIR ${PROJECT_BINARY_DIR}/chrono_csharp/core) # # # Call the function for the vehicle module # add_csharp_postbuild_command(Chrono_csharp_postprocess ${GLOB_DIR} ${BINARY_DIR}) # #------------------------------------------------------Remove duplicates endif() #----------------------------------------------------------------------------- # MODULE for the irrlicht csharp wrapper. #----------------------------------------------------------------------------- if(CH_ENABLE_MODULE_IRRLICHT) message(STATUS "Add C# IRRLICHT module") set(CMAKE_SWIG_OUTDIR "${CHRONO_SWIG_OUTDIR}/irrlicht") # Interface files set(INTERFACE_FILE_IRRLICHT ChModuleIrrlicht_csharp.i) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set_source_files_properties(${INTERFACE_FILE_IRRLICHT} PROPERTIES COMPILE_FLAGS "-D_WIN32") endif() set_source_files_properties(${INTERFACE_FILE_IRRLICHT} PROPERTIES CPLUSPLUS ON) if(MSVC) set_source_files_properties(${INTERFACE_FILE_IRRLICHT} PROPERTIES COMPILE_OPTIONS "-w401,503") endif() # Create the SWIG module. swig_add_library(Chrono_csharp_irrlicht LANGUAGE csharp SOURCES ${INTERFACE_FILE_IRRLICHT}) find_package(Irrlicht QUIET REQUIRED) target_link_libraries(Chrono_csharp_irrlicht PRIVATE Chrono_core Chrono_irrlicht Irrlicht::Irrlicht) # Ensure that the PYD library file is generated in the bin/ directory. set_target_properties(Chrono_csharp_irrlicht PROPERTIES PROJECT_LABEL "Chrono_csharp_irrlicht" OUTPUT_NAME "Chrono_csharp_irrlicht" LIBRARY_OUTPUT_DIRECTORY "${LIB_OUT_DIR}" SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE ) target_compile_definitions(Chrono_csharp_irrlicht PRIVATE "CH_IGNORE_DEPRECATED") target_compile_definitions(Chrono_csharp_irrlicht PRIVATE "IGNORE_DEPRECATED_WARNING") add_dependencies(Chrono_csharp_irrlicht Chrono_core) add_dependencies(Chrono_csharp_irrlicht Chrono_irrlicht) add_dependencies(Chrono_csharp_irrlicht Chrono_csharp_core) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") install(TARGETS Chrono_csharp_irrlicht EXPORT ChronoTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) else() install(TARGETS Chrono_csharp_irrlicht EXPORT ChronoTargets LIBRARY DESTINATION lib) endif() if (DBG_SCRIPT) message("Module name: Chrono_csharp_irrlicht") message("SWIG_REAL_NAME: Chrono_csharp_irrlicht") endif() endif() #----------------------------------------------------------------------------- # Wrapper for VEHICLE Chrono module #----------------------------------------------------------------------------- if(CH_ENABLE_MODULE_VEHICLE AND CH_ENABLE_MODULE_VEHICLE_MODELS) if (CH_ENABLE_MODULE_IRRLICHT) #Append the CHRONO_IRRLICHT flag, for vehicle visual irrlicht set(CMAKE_SWIG_FLAGS "${CMAKE_SWIG_FLAGS};-DCHRONO_IRRLICHT") endif() if (HAVE_OPENCRG) set(CMAKE_SWIG_FLAGS "${CMAKE_SWIG_FLAGS};-DHAVE_OPENCRG") endif() message(STATUS "Add C# VEHICLE module") set(CMAKE_SWIG_OUTDIR "${CHRONO_SWIG_OUTDIR}/vehicle") # Set interface file. set(INTERFACE_FILE_VEHICLE ChModuleVehicle_csharp.i) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set_source_files_properties(${INTERFACE_FILE_VEHICLE} PROPERTIES COMPILE_FLAGS "-D_WIN32") endif() set_source_files_properties(${INTERFACE_FILE_VEHICLE} PROPERTIES CPLUSPLUS ON) if(MSVC) set_source_files_properties(${INTERFACE_FILE_VEHICLE} PROPERTIES COMPILE_OPTIONS "-w401,503,833") endif() # Create the SWIG module. swig_add_library(Chrono_csharp_vehicle LANGUAGE csharp SOURCES ${INTERFACE_FILE_VEHICLE}) target_link_libraries(Chrono_csharp_vehicle PRIVATE Chrono_core Chrono_vehicle ChronoModels_vehicle) if (CH_ENABLE_MODULE_IRRLICHT) find_package(Irrlicht QUIET REQUIRED) target_link_libraries(Chrono_csharp_vehicle PRIVATE Chrono_irrlicht Chrono_vehicle_irrlicht Irrlicht::Irrlicht) endif() if (CH_ENABLE_MODULE_POSTPROCESS) target_link_libraries(Chrono_csharp_vehicle PRIVATE Chrono_postprocess) endif() set_target_properties(Chrono_csharp_vehicle PROPERTIES PROJECT_LABEL "Chrono_csharp_vehicle" OUTPUT_NAME "Chrono_csharp_vehicle" LIBRARY_OUTPUT_DIRECTORY "${LIB_OUT_DIR}" SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE ) target_compile_definitions(Chrono_csharp_vehicle PRIVATE "CH_IGNORE_DEPRECATED") if (HAVE_OPENCRG) target_compile_definitions(Chrono_csharp_vehicle PRIVATE "HAVE_OPENCRG") endif() add_dependencies(Chrono_csharp_vehicle Chrono_core Chrono_vehicle ChronoModels_vehicle) add_dependencies(Chrono_csharp_vehicle Chrono_csharp_core) if (CH_ENABLE_MODULE_IRRLICHT) add_dependencies(Chrono_csharp_vehicle Chrono_csharp_irrlicht) endif() if (CH_ENABLE_MODULE_POSTPROCESS) add_dependencies(Chrono_csharp_vehicle Chrono_csharp_postprocess) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") install(TARGETS Chrono_csharp_vehicle EXPORT ChronoTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) else() install(TARGETS Chrono_csharp_vehicle EXPORT ChronoTargets LIBRARY DESTINATION lib) endif() if (DBG_SCRIPT) message(STATUS "Module name: Chrono_csharp_vehicle") message(STATUS "SWIG_REAL_NAME: Chrono_csharp_vehicle") endif() #------------------------------------------------------Remove duplicates #Uncomment for use # # Custom command to remove duplicate .cs files from the vehicle directory and log the actions # set(GLOB_DIR ${CMAKE_SWIG_OUTDIR}) # set(BINARY_DIR ${PROJECT_BINARY_DIR}/chrono_csharp/core) # # # Call the function for the vehicle module # add_csharp_postbuild_command(Chrono_csharp_vehicle ${GLOB_DIR} ${BINARY_DIR}) # #------------------------------------------------------Remove duplicates endif() #------------------------------------------------------------------------------- # Install files #------------------------------------------------------------------------------- # Swig generated files install(DIRECTORY ${CMAKE_SWIG_OUTDIR}/ DESTINATION include/chrono_csharp FILES_MATCHING PATTERN "*.cs") if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") install(DIRECTORY ${CMAKE_SOURCE_DIR}/template_project_csharp/ DESTINATION "template_project_csharp") else() install(DIRECTORY ${CMAKE_SOURCE_DIR}/template_project_csharp/ DESTINATION "share/chrono/template_project_csharp") endif()