# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

if(GPUSPATIAL_BUILD_TESTS)
  enable_testing()

  add_executable(gpuspatial_testing_test gpuspatial_testing_test.cc)
  target_link_libraries(gpuspatial_testing_test PRIVATE geoarrow GTest::gtest_main
                                                        GTest::gmock_main gpuspatial)

  add_executable(array_stream_test main.cc array_stream_test.cc array_stream.cc)
  target_link_libraries(array_stream_test
                        PRIVATE cuda
                                GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial
                                GEOS::geos
                                Arrow::arrow_static
                                Parquet::parquet_static)

  add_executable(loader_test array_stream.cc main.cc loader_test.cu)
  target_link_libraries(loader_test
                        PRIVATE cuda
                                GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial
                                GEOS::geos
                                Arrow::arrow_static
                                Parquet::parquet_static)
  target_include_directories(loader_test PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
  target_compile_options(loader_test
                         PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda
                                 --expt-relaxed-constexpr>)

  add_executable(index_test main.cc index_test.cu)
  target_link_libraries(index_test
                        PRIVATE cuda
                                GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial
                                GEOS::geos)
  target_compile_options(index_test
                         PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda
                                 --expt-relaxed-constexpr>)
  add_executable(refiner_test main.cc array_stream.cc refiner_test.cu)
  target_link_libraries(refiner_test
                        PRIVATE cuda
                                GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial
                                GEOS::geos
                                Arrow::arrow_static
                                Parquet::parquet_static)
  target_compile_options(refiner_test
                         PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda
                                 --expt-relaxed-constexpr>)

  add_executable(relate_test main.cc array_stream.cc relate_test.cu)
  target_link_libraries(relate_test
                        PRIVATE cuda
                                GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial
                                GEOS::geos
                                nanoarrow::nanoarrow
                                Arrow::arrow_static
                                Parquet::parquet_static)
  target_compile_options(relate_test
                         PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda
                                 --expt-relaxed-constexpr>)

  add_executable(c_wrapper_test main.cc c_wrapper_test.cc array_stream.cc)
  target_link_libraries(c_wrapper_test
                        PRIVATE GTest::gtest_main
                                GTest::gmock_main
                                gpuspatial_c
                                GEOS::geos
                                Arrow::arrow_static
                                Parquet::parquet_static)

  include(GoogleTest)

  gtest_discover_tests(gpuspatial_testing_test)
  gtest_discover_tests(array_stream_test)
  gtest_discover_tests(loader_test)
  gtest_discover_tests(relate_test)
  gtest_discover_tests(c_wrapper_test)
endif()
