# This is an update version of the CMake project file for the libe57 reference
# implementation, with support for Conan targets, to make the dependency
# management easier and reproducible on all the supported platforms
#
# Original   work Copyright 2010-2012   Roland Schwarz, Riegl LMS GmbH
# Modified work Copyright 2020-2024     Michele Adduci <adduci@tutanota.com>
#
# Permission is hereby granted, free of charge, to any person or organization
# obtaining a copy of the software and accompanying documentation covered by
# this license (the "Software") to use, reproduce, display, distribute, execute,
# and transmit the Software, and to prepare derivative works of the Software,
# and to permit third-parties to whom the Software is furnished to do so, all
# subject to the following:
#
# The copyright notices in the Software and this entire statement, including the
# above license grant, this restriction and the following disclaimer, must be
# included in all copies of the Software, in whole or in part, and all
# derivative works of the Software, unless such copies or derivative works are
# solely in the form of machine-executable object code generated by a source
# language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR
# ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Requirements: 
# * Xerces library: http://xerces.apache.org/ 
# * Boost library: http://www.boost.org
#
# Notes: Since there is not standard cmake module to find the xerces library we
# provide one with this distribution. It should be able to find the library from
# the XERCES_ROOT cmake variable. Standard layout, as with the binary packages
# from apache is assumed. If you find any errors or have suggestion to improve
# the build script: patches are most welcome!

cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)

# Enables the CMAKE_MSVC_RUNTIME_LIBRARY property on targets
cmake_policy(SET CMP0091 NEW)

project(openE57 VERSION 1.6.3 LANGUAGES C CXX DESCRIPTION "openE57 is a library for handling E57 files")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

option(BUILD_DOCS "Build documentation" FALSE)
option(BUILD_EXAMPLES "Build opene57 examples" FALSE)
option(BUILD_TOOLS "Build opene57 tools" FALSE)
option(BUILD_TESTS "Build opene57 tests" FALSE)
option(BUILD_SHARED_LIBS "Build opene57 shared libraries" FALSE)
option(BUILD_WITH_MT "Build the project with /MT when using Visual Studio" FALSE)

if(BUILD_SHARED_LIBS)
  message(FATAL_ERROR "Shared Libraries are not supported due to missing exported symbols")
else(BUILD_SHARED_LIBS)
  set(LIBRARY_TYPE STATIC)
endif()

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release")
endif()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)

# 
# Install Artifacts
#
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md
        DESTINATION .)

set(CPACK_PACKAGE_VENDOR "Michele Adduci <adduci@tutanota.com>")
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}")
set(CPACK_GENERATOR "ZIP")
set(CPACK_STRIP_FILES "TRUE")

include(CPack)
