#===============================================================================
# Chrono project configuration file
#
# This file is automatically generated when Chrono is configured and contains
# information on how the project was configured.  It can be used by third party
# projects in their own CMakeLists files to find the Chrono package and obtain
# information on how to link to the Chrono libraries.
#
# In the call to find_package(), the following Chrono components can be
# requested (case insensitive): Cascade, Cosimulation, Irrlicht, Matlab,
# Multicore, Gpu, PardisoMKL, PardisoProject, Postprocess, Python, Vehicle.  
# A component can be requested either as required or optional
# (see the CMake documentation for find_package).
# 
# Variables set by this script:
# CHRONO_FOUND
#       set to true if Chrono and all required components were found
# CHRONO_C_FLAGS
# CHRONO_CXX_FLAGS
#       C and C++ compilation flags
# CHRONO_INCLUDE_DIRS
#       additional paths for included headers
# CHRONO_LIBRARIES
#       list of required libraries (with full path)
# CHRONO_LINKER_FLAGS
#       additional linker flags
# CHRONO_DLLS
#       list of all DLL dependencies (with full path)
# CHRONO_DATA_DIR
#       path to the Chrono data directory
# CHRONO_VEHICLE_DATA_DIR
#       path to the Chrono::Vehicle data directory
# CHRONO_FSI_DATA_DIR
#       path to the Chrono::FSI data directory
#
# In addition, for each requested component [COMPONENT], the following variable
# is set to true (ON) or false (OFF):
# CHRONO_[COMPONENT]_FOUND
#
# Other variables:
# CHRONO_SSE_FOUND
#       set to true is SSE support is available
#       CHRONO_CXX_FLAGS includes all required flags
# CHRONO_AVX_FOUND
#       set to true is AVX support is available
#       CHRONO_CXX_FLAGS includes all required flags
#===============================================================================

if (CHRONO_CONFIG_INCLUDED)
  return()
endif()
set(CHRONO_CONFIG_INCLUDED TRUE)

message(STATUS "Finding package Chrono...")

#-------------------------------------------------------------------------------
# Initialize output variables with settings for the main Chrono::Engine
#-------------------------------------------------------------------------------

set(CHRONO_CXX_FLAGS " -std=c++14  -Xclang -fopenmp  -march=native -msse4.2  -march=native -mavx2  -march=native -mfma ")
set(CHRONO_C_FLAGS "  -Xclang -fopenmp  -march=native -msse4.2  -march=native -mavx2  -march=native -mfma ")

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  set(CHRONO_LINKER_FLAGS "")
else()
  set(CHRONO_LINKER_FLAGS "-L/Users/yangfeng/Desktop/chrono/xcode/lib")
endif()

list(APPEND CHRONO_INCLUDE_DIRS "/Users/yangfeng/Desktop/chrono/src;/Users/yangfeng/Desktop/chrono/src/chrono;/Users/yangfeng/Desktop/chrono/src/chrono/collision/bullet;/Users/yangfeng/Desktop/chrono/src/chrono/collision/gimpact;/Users/yangfeng/Desktop/chrono/src/chrono_thirdparty/HACD;/Users/yangfeng/Desktop/chrono/src/chrono_thirdparty/HACDv2;/Users/yangfeng/Desktop/chrono/xcode;/Users/yangfeng/include/eigen3;/usr/local/include")
list(APPEND CHRONO_LIBRARIES "/usr/local/lib/libomp.dylib")
list(APPEND CHRONO_LIB_NAMES "ChronoEngine")
list(APPEND CHRONO_DLLS "")
list(APPEND CHRONO_DLL_NAMES "ChronoEngine.dll")

set(CHRONO_DATA_DIR "/Users/yangfeng/Desktop/chrono/data/")
set(CHRONO_VEHICLE_DATA_DIR "/Users/yangfeng/Desktop/chrono/data/vehicle/")
set(CHRONO_FSI_DATA_DIR "/Users/yangfeng/Desktop/chrono/data/fsi/")
set(SYNCHRONO_DATA_DIR "/Users/yangfeng/Desktop/chrono/data/synchrono/")

set(CHRONO_SSE_FOUND "1")
set(CHRONO_AVX_FOUND "1")

#-------------------------------------------------------------------------------
# Local variables specifying which Chrono modules are enabled
#-------------------------------------------------------------------------------

set(Chrono_HAS_cascade OFF)
set(Chrono_HAS_cosimulation OFF)
set(Chrono_HAS_irrlicht TRUE)
set(Chrono_HAS_matlab OFF)
set(Chrono_HAS_pardisomkl OFF)
set(Chrono_HAS_mumps OFF)
set(Chrono_HAS_multicore OFF)
set(Chrono_HAS_opengl OFF)
set(Chrono_HAS_postprocess TRUE)
set(Chrono_HAS_python OFF)
set(Chrono_HAS_vehicle TRUE)
set(Chrono_HAS_fsi OFF)
set(Chrono_HAS_gpu OFF)
set(Chrono_HAS_sensor OFF)
set(Chrono_HAS_pardisoproject OFF)
set(Chrono_HAS_synchrono OFF)

#-------------------------------------------------------------------------------
# Loop over the list of requested components
#-------------------------------------------------------------------------------

foreach(COMPONENT ${Chrono_FIND_COMPONENTS})

  string(TOLOWER ${COMPONENT} COMPONENT_LOWER)
  string(TOUPPER ${COMPONENT} COMPONENT_UPPER)

  # Report the name of the component that was requested and whether it was
  # required or optional.

  if(Chrono_FIND_REQUIRED_${COMPONENT})
    set(COMPONENT_REQ_TYPE "REQUIRED")
  else()
    set(COMPONENT_REQ_TYPE "OPTIONAL")
  endif()
  message(STATUS "   Requested component ${COMPONENT} (${COMPONENT_REQ_TYPE})")

  if(NOT Chrono_HAS_${COMPONENT_LOWER})

    # The component is not available. Stop if it is required.
    set(CHRONO_${COMPONENT_UPPER}_FOUND OFF)

    if(Chrono_FIND_REQUIRED_${COMPONENT})
       message("Chrono was not configured with support for the REQUIRED component ${COMPONENT}")
       set(Chrono_FOUND OFF)
       return()
    else()
       message("Chrono was not configured with support for the OPTIONAL component ${COMPONENT}")
    endif()

  else()

    # The component is available. Append to output variables.
    set(CHRONO_${COMPONENT_UPPER}_FOUND ON)

    if(${COMPONENT_UPPER} MATCHES "MULTICORE")

      set(CHRONO_CXX_FLAGS "${CHRONO_CXX_FLAGS} ")
      set(CHRONO_C_FLAGS "${CHRONO_C_FLAGS} ")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_multicore")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_multicore.dll")

    elseif(${COMPONENT_UPPER} MATCHES "OPENGL")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_opengl")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_LIBRARIES "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/OpenGL.framework")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_opengl.dll")
      list(APPEND CHRONO_DLLS "")
      list(APPEND CHRONO_DLLS "")

    elseif(${COMPONENT_UPPER} MATCHES "IRRLICHT")

      set(CHRONO_CXX_FLAGS "${CHRONO_CXX_FLAGS} ")
      set(CHRONO_C_FLAGS "${CHRONO_C_FLAGS} ")

      list(APPEND CHRONO_INCLUDE_DIRS "/usr/local/include/irrlicht")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_irrlicht")
      list(APPEND CHRONO_LIBRARIES "/usr/local/lib/libIrrlicht.a")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_irrlicht.dll")
      list(APPEND CHRONO_DLLS "")

    elseif(${COMPONENT_UPPER} MATCHES "VEHICLE")

      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_vehicle")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_vehicle.dll")
      list(APPEND CHRONO_LIB_NAMES "ChronoModels_vehicle")
      list(APPEND CHRONO_DLL_NAMES "ChronoModels_vehicle.dll")

      if(${Chrono_HAS_irrlicht})
        list(APPEND CHRONO_LIB_NAMES "ChronoEngine_vehicle_irrlicht")
        list(APPEND CHRONO_DLL_NAMES "ChronoEngine_vehicle_irrlicht.dll")
      endif()

    elseif(${COMPONENT_UPPER} MATCHES "FSI")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_fsi")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_fsi.dll")

    elseif(${COMPONENT_UPPER} MATCHES "SENSOR")
      set(CHRONO_CXX_FLAGS "${CHRONO_CXX_FLAGS} ")
      set(CHRONO_C_FLAGS "${CHRONO_C_FLAGS} ")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_sensor")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_sensor.dll")
      list(APPEND CHRONO_DLLS "")
      list(APPEND CHRONO_DLLS "")

    elseif(${COMPONENT_UPPER} MATCHES "SYNCHRONO")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_synchrono")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_synchrono.dll")

    elseif(${COMPONENT_UPPER} MATCHES "GPU")

      set(CHRONO_CXX_FLAGS "${CHRONO_CXX_FLAGS} ")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_gpu")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_gpu.dll")

    elseif(${COMPONENT_UPPER} MATCHES "PARDISOMKL")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LINKER_FLAGS "")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_pardisomkl")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_pardisomkl.dll")

    elseif(${COMPONENT_UPPER} MATCHES "MUMPS")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LINKER_FLAGS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_mumps")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_mumps.dll")
      list(APPEND CHRONO_DLLS "")

    elseif(${COMPONENT_UPPER} MATCHES "POSTPROCESS")

      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_postprocess")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_postprocess.dll")

    elseif(${COMPONENT_UPPER} MATCHES "CASCADE")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_cascade")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_cascade.dll")

    elseif(${COMPONENT_UPPER} MATCHES "COSIMULATION")

      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_cosimulation")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_cosimulation.dll")

    elseif(${COMPONENT_UPPER} MATCHES "PYTHON")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "_ChronoEngine_python_core")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_pyparser")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_pyparser.dll")

      if(${Chrono_HAS_irrlicht})
        list(APPEND CHRONO_LIB_NAMES "_ChronoEngine_python_irrlicht")
      endif()

    elseif(${COMPONENT_UPPER} MATCHES "MATLAB")

      list(APPEND CHRONO_INCLUDE_DIRS "")
      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_matlab")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_matlab.dll")

    elseif(${COMPONENT_UPPER} MATCHES "PARDISOPROJECT")

      list(APPEND CHRONO_LIB_NAMES "ChronoEngine_pardisoproject")
      list(APPEND CHRONO_LIBRARIES "")
      list(APPEND CHRONO_DLL_NAMES "ChronoEngine_pardisoproject.dll")

    endif()

  endif()

endforeach()

#-------------------------------------------------------------------------------
# Loop over list of Chrono library names and find the actual libraries.
#-------------------------------------------------------------------------------

foreach(lib ${CHRONO_LIB_NAMES})
  set(onelib "${lib}-NOTFOUND")
  find_library(onelib ${lib}
    PATHS "/Users/yangfeng/Desktop/chrono/xcode/lib"
    PATH_SUFFIXES "Release"
    NO_DEFAULT_PATH
  )
  if(NOT onelib)
    message("Library '${lib}' in package Chrono is not installed properly")
  else()
    list(APPEND CHRONO_LIBRARIES "${onelib}")
  endif()
endforeach()

mark_as_advanced(FORCE onelib)

#-------------------------------------------------------------------------------
# Loop over list of Chrono DLL names and find the actual DLLs
#-------------------------------------------------------------------------------

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

  foreach(dll ${CHRONO_DLL_NAMES})
    set(onedll "${dll}-NOTFOUND")
    find_file(onedll ${dll}
      PATHS "/Users/yangfeng/Desktop/chrono/xcode/bin"
      PATH_SUFFIXES "Release"
      NO_DEFAULT_PATH
    )
    if(NOT onedll)
      message("DLL '${dll}' in package Chrono is not installed properly")
    else()
      list(APPEND CHRONO_DLLS "${onedll}")
    endif()
  endforeach()

  mark_as_advanced(FORCE onedll)

else()

  # If not on Windows, clear the lists of DLLs
  set(CHRONO_DLL_NAMES "")
  set(CHRONO_DLLS "")

endif()

#-------------------------------------------------------------------------------
# Report the exported variables
#-------------------------------------------------------------------------------

message(STATUS "   CHRONO_CXX_FLAGS         (Compiler flags): ${CHRONO_CXX_FLAGS}")
message(STATUS "   CHRONO_C_FLAGS           (Compiler flags): ${CHRONO_C_FLAGS}")
message(STATUS "   CHRONO_LINKER_FLAGS      (Linker flags): ${CHRONO_LINKER_FLAGS}")
message(STATUS "   CHRONO_INCLUDE_DIRS      (Chrono include directories): ${CHRONO_INCLUDE_DIRS}")
message(STATUS "   CHRONO_LIB_NAMES         (Chrono library names): ${CHRONO_LIB_NAMES}")
message(STATUS "   CHRONO_LIBRARIES         (Chrono libraries): ${CHRONO_LIBRARIES}")
message(STATUS "   CHRONO_DLL_NAMES         (Chrono DLL names): ${CHRONO_DLL_NAMES}")
message(STATUS "   CHRONO_DLLS              (Chrono DLLs): ${CHRONO_DLLS}")
message(STATUS "   CHRONO_DATA_DIR          (Path to Chrono data folder): ${CHRONO_DATA_DIR}")
message(STATUS "   CHRONO_VEHICLE_DATA_DIR  (Path to Chrono::Vehicle data folder): ${CHRONO_VEHICLE_DATA_DIR}")
message(STATUS "   CHRONO_FSI_DATA_DIR      (Path to Chrono::FSI data folder): ${CHRONO_FSI_DATA_DIR}")

#===============================================================================
# Provide a CMake function which adds a custom command (COPY_DLLS), invoked
# pre-build to copy all DLLs specified in the input list to the appropriate
# folder for the current VS configuration.
#
# The input list must contain a list of DLLs with full paths, such as that
# returned by the ChronoConfig script.
#
# Note that EXECUTABLE_OUTPUT_PATH must be defined (even if it's simply
# CMAKE_BINARY_DIR or PROJECT_BINARY_DIR)
#===============================================================================

function(add_DLL_copy_command DLL_LIST)

    # Return now if not windows
    if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
      return()
    endif()

    # Remove duplicates in the input list
    list(REMOVE_DUPLICATES DLL_LIST)

    message(STATUS "==== Add custom commands for copying DLLs ====")
    message(STATUS "DLL list...")

    # Create custom target for copying DLLs; add it to the default build target
    add_custom_target(COPY_DLLS ALL)

    # Add custom command to create the destination folder
    add_custom_command(TARGET COPY_DLLS PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E make_directory "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>/")

    # Loop over the list of all DLLs and create a custom command
    foreach(DLL ${DLL_LIST})
        message(STATUS "...${DLL}")

        # Create custom commands, invoked pre-build to copy DLLs to the appropriate
        # directory (depending on the configuration selected at build time in VS)
        add_custom_command(
            TARGET COPY_DLLS PRE_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
                "${DLL}"
                "${EXECUTABLE_OUTPUT_PATH}/$<CONFIGURATION>/"
        )
    endforeach()

    message("Attention: Only RELEASE DLLs are copied automatically.")
    message("           You must manually copy the DLLs for other configurations.")
endfunction()
