cmake_minimum_required(VERSION 3.2.2)
PROJECT (H4H5_LIB_EXAMPLES C CXX)

#
# Copyright by The HDF Group.
# All rights reserved.
#
# This file is part of H4H5TOOLS. The full H4H5TOOLS copyright notice,
# including terms governing use, modification, and redistribution, is
# contained in the COPYING file, which can be found at the root of the
# source code distribution tree. The copyright notice can also be found
# at https://www.hdfgroup.org/licenses.  If you do not have access to
# either file, you may request a copy from help@hdfgroup.org.
#

#-----------------------------------------------------------------------------
# Build Example
#-----------------------------------------------------------------------------
add_executable (h4toh5example ${H4H5_LIB_EXAMPLES_SOURCE_DIR}/h4toh5example.c)
TARGET_C_PROPERTIES (h4toh5example ${LIB_TYPE} " " " ")
target_link_libraries (h4toh5example PRIVATE ${H4H5_SRC_LIB_TARGET} ${LINK_LIBS})

#-- Copy all the dat files from the test directory into the source directory
add_custom_command (
     TARGET     h4toh5example
     POST_BUILD
     COMMAND    ${CMAKE_COMMAND}
     ARGS       -E copy_if_different ${H4H5_LIB_EXAMPLES_SOURCE_DIR}/sds_lib_test.hdf "${PROJECT_BINARY_DIR}/sds_lib_test.hdf"
)

if (BUILD_TESTING)
  # Remove any output file left over from previous test run
  add_test (
      NAME h4toh5example-clearall-objects
      COMMAND    ${CMAKE_COMMAND}
          -E remove
          sds_lib_test.h5
  )

  add_test (NAME h4toh5example COMMAND $<TARGET_FILE:h4toh5example>)
  set_tests_properties (h4toh5example PROPERTIES DEPENDS h4toh5example-clearall-objects)
endif ()
