if(NOT BUILD_CXX)
  return()
endif()

# Check primitive types
option(CHECK_TYPE "Check primitive type size" OFF)
if(CHECK_TYPE)
  include(CMakePushCheckState)
  cmake_push_check_state(RESET)
  set(CMAKE_EXTRA_INCLUDE_FILES "cstdint")
  include(CheckTypeSize)
  check_type_size("long" SIZEOF_LONG LANGUAGE CXX)
  message(STATUS "Found long size: ${SIZEOF_LONG}")
  check_type_size("long long" SIZEOF_LONG_LONG LANGUAGE CXX)
  message(STATUS "Found long long size: ${SIZEOF_LONG_LONG}")
  check_type_size("int64_t" SIZEOF_INT64_T LANGUAGE CXX)
  message(STATUS "Found int64_t size: ${SIZEOF_INT64_T}")

  check_type_size("unsigned long" SIZEOF_ULONG LANGUAGE CXX)
  message(STATUS "Found unsigned long size: ${SIZEOF_ULONG}")
  check_type_size("unsigned long long" SIZEOF_ULONG_LONG LANGUAGE CXX)
  message(STATUS "Found unsigned long long size: ${SIZEOF_ULONG_LONG}")
  check_type_size("uint64_t" SIZEOF_UINT64_T LANGUAGE CXX)
  message(STATUS "Found uint64_t size: ${SIZEOF_UINT64_T}")

  check_type_size("int *" SIZEOF_INT_P LANGUAGE CXX)
  message(STATUS "Found int * size: ${SIZEOF_INT_P}")
  cmake_pop_check_state()
endif()

if(WIN32)
  # target_link_libraries(${PROJECT_NAME} PUBLIC psapi.lib ws2_32.lib)
endif()

add_subdirectory(src/cc/)

# Install
install(
  EXPORT cspyTargets
  NAMESPACE cspy::
  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cspy
  COMPONENT Devel)
include(CMakePackageConfigHelpers)
configure_package_config_file(
  cmake/cspyConfig.cmake.in "${PROJECT_BINARY_DIR}/cspyConfig.cmake"
  INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cspy")
write_basic_package_version_file("${PROJECT_BINARY_DIR}/cspyConfigVersion.cmake"
                                 COMPATIBILITY SameMajorVersion)

install(
  FILES "${PROJECT_BINARY_DIR}/cspyConfig.cmake"
        "${PROJECT_BINARY_DIR}/cspyConfigVersion.cmake"
  DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cspy"
  COMPONENT Devel)
