
# Next two lines are used for development
set(WORKFLOW_DIRECTORY  "${CMAKE_SOURCE_DIR}/simulation-workflows")
add_compile_definitions(WORKFLOW_DIRECTORY="${WORKFLOW_DIRECTORY}")

set(truchas_sources
  Metadata.cxx
  Registrar.cxx
  utility/AttributeUtils.cxx
  utility/MaterialAttributeUtils.cxx
  utility/ModelUtils.cxx
)

set(truchas_headers
  Metadata.h
  Registrar.h
  utility/AttributeUtils.h
  utility/MaterialAttributeUtils.h
  utility/ModelUtils.h
)

set(operations
  Create
  Export
  ImportModel
  LegacyRead
)

# Operations which have XML descriptions in separate files
# need to have it encoded as a string in a header.
foreach (operation ${operations})
  smtk_encode_file("${CMAKE_CURRENT_SOURCE_DIR}/operations/${operation}.sbt"
  HEADER_OUTPUT header_name)
  list(APPEND truchas_sources operations/${operation}.cxx)
  list(APPEND truchas_headers operations/${operation}.h)
  list(APPEND operation_dependencies ${header_name})
endforeach()
add_custom_target(truchas_generated_headers DEPENDS ${operation_dependencies})

add_library(smtkTruchas ${truchas_sources})

add_dependencies(smtkTruchas truchas_generated_headers)

target_link_libraries(smtkTruchas
  LINK_PUBLIC
    smtkCore
    nlohmann_json
    Boost::filesystem
    ${__dependencies}
)

target_compile_definitions(smtkTruchas
  PRIVATE "WORKFLOWS_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}/simulation-workflows\"")

target_include_directories(smtkTruchas
  PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_VERSION}>
  PRIVATE
    ${Boost_INCLUDE_DIRS}
    ${Python3_INCLUDE_DIR}
)

generate_export_header(smtkTruchas EXPORT_FILE_NAME Exports.h)

# add_subdirectory(examples)

# Install the header files
smtk_get_kit_name(name dir_prefix)

install(
  FILES
    ${truchas_headers}
    ${CMAKE_CURRENT_BINARY_DIR}/Exports.h
  DESTINATION
    ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_VERSION}/${dir_prefix})

# Install the library and exports
install(
  TARGETS smtkTruchas
  EXPORT  ${PROJECT_NAME}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_VERSION}/${dir_prefix})

add_subdirectory(pybind11)

if (ParaView_FOUND AND Qt5_FOUND AND TARGET smtkQtExt)
  add_subdirectory(qt)
endif()

if (ENABLE_TESTING)
  add_subdirectory(testing)
endif()

if (Qt5_FOUND AND BUILD_EXAMPLES)
  add_subdirectory(examples)
endif()
