# Vortex packaging wrapper; upstream source is unchanged.
cmake_minimum_required(VERSION 3.16)
project(tinyexpr-plusplus VERSION 1.2.0 LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
option(TINYEXPR_THREADS "Build the Emscripten pthread variant" OFF)
add_library(tinyexpr-plusplus STATIC tinyexpr.cpp)
add_library(tinyexpr-plusplus::tinyexpr-plusplus ALIAS tinyexpr-plusplus)
set_target_properties(tinyexpr-plusplus PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_features(tinyexpr-plusplus PUBLIC cxx_std_20)
target_include_directories(tinyexpr-plusplus PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/tinyexpr-plusplus>)
if(EMSCRIPTEN)
    # The parser catches arithmetic and syntax errors internally.
    target_compile_options(tinyexpr-plusplus PUBLIC -fexceptions)
    target_link_options(tinyexpr-plusplus PUBLIC -fexceptions)
    if(TINYEXPR_THREADS)
        target_compile_options(tinyexpr-plusplus PUBLIC -pthread)
        target_link_options(tinyexpr-plusplus PUBLIC -pthread)
    endif()
endif()
install(TARGETS tinyexpr-plusplus EXPORT tinyexpr-plusplus-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES tinyexpr.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinyexpr-plusplus)
install(EXPORT tinyexpr-plusplus-targets NAMESPACE tinyexpr-plusplus::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tinyexpr-plusplus)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tinyexpr-plusplus-config.cmake
    "include(\"\${CMAKE_CURRENT_LIST_DIR}/tinyexpr-plusplus-targets.cmake\")\n")
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/tinyexpr-plusplus-config-version.cmake
    COMPATIBILITY ExactVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyexpr-plusplus-config.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/tinyexpr-plusplus-config-version.cmake
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tinyexpr-plusplus)
