################################################################################
#                        Copyright 2018 Ryan M. Richard                        #
#       Licensed 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.                        #
################################################################################

include_guard()

include(unit_testing/cpp_dummy_cxx_library)

## Writes out a C++ package that uses CMake naively.
#
# For our purposes a naive usage of CMake amounts to not writing a
# ``XXX-config.cmake`` file upon installation. This function will generate the
# source code and the ``CMakeLists.txt`` for such a package. The source code
# will be generated by :ref:`cpp_dummy_cxx_library-label`.
#
# :param src: An identifier which, after this call, will store the path to the
#     directory containing the source code.
# :param prefix: The path where the directory containing the files should live.
#
# :kwargs:
#
#     * *NAME* (``option``) - The name of the dependency. Defaults to "dummy".
function(_cpp_naive_cxx_package _cncp_src _cncp_prefix)
    cmake_parse_arguments(_cncp "" "NAME" "" "${ARGN}")
    if("${_cncp_NAME}" STREQUAL "")
        set(_cncp_NAME dummy)
    endif()

    #Write the source
    set(${_cncp_src} ${_cncp_prefix}/${_cncp_NAME})
    set(${_cncp_src} ${${_cncp_src}} PARENT_SCOPE)
    _cpp_dummy_cxx_library(${${_cncp_src}})

    #Write the CMakeLists.txt
    _cpp_write_list(
        ${${_cncp_src}}
        NAME ${_cncp_NAME}
        CONTENTS "add_library(${_cncp_NAME} a.cpp)"
        "install("
        "   TARGETS ${_cncp_NAME}"
        "   LIBRARY DESTINATION \${CMAKE_INSTALL_PREFIX}/lib"
        "   ARCHIVE DESTINATION \${CMAKE_INSTALL_PREFIX}/lib"
        ")"
        "install(FILES a.hpp DESTINATION \${CMAKE_INSTALL_PREFIX}/include)"
    )
endfunction()
