#*******************************************************************************
#**  This file is part of Qt Mocks.                                          ***
#**                                                                          ***
#**  Copyright (C) 2018, 2019, 2020, 2021                                    ***
#**  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
#**                                                                          ***
#**  This program is free software: you can redistribute it and/or modify it ***
#**  under the terms of the GNU Lesser General Public License as published   ***
#**  by the Free Software Foundation, either version 3 of the License, or    ***
#**  (at your option) any later version.                                     ***
#**                                                                          ***
#**  This program is distributed in the hope that it will be useful, but     ***
#**  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
#**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
#**  See the GNU Lesser General Public License for more details.             ***
#**                                                                          ***
#**  You should have received a copy of the GNU Lesser General Public License***
#**  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
#*******************************************************************************
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(Qt-Mocks
	VERSION 0.4.0
	DESCRIPTION "Mocking library using Qt Test inspired by Google Test."
	LANGUAGES CXX
)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX "d")

if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
	message(STATUS "Enabling Conan.io support.")
	include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
	conan_basic_setup()
endif (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")

option(${PROJECT_NAME}_BUILD_SHARED_LIBRARY "Enables building as a shared library, else static." ON)


if (${PROJECT_NAME}_BUILD_SHARED_LIBRARY)
	set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED")
else ()
	set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC")
endif (${PROJECT_NAME}_BUILD_SHARED_LIBRARY)

option(${PROJECT_NAME}_ENABLE_TESTS "Enables building and executing tests." OFF)

if (${PROJECT_NAME}_ENABLE_TESTS)
	include(CTest)
	enable_testing()
endif (${PROJECT_NAME}_ENABLE_TESTS)

set(${PROJECT_NAME}_COPYRIGHT_YEARS "\"2018 - 2021\"")
set(
	${PROJECT_NAME}_DESCRIPTION
	"A C++ Qt library for mocking using Qt Test inspired by Google Test."
)
set(${PROJECT_NAME}_HOMEPAGE_URL "http://source.schneiderman.me/qt-mocks/")

# Allow for packagers to supply the name of the library directory.
if (DEFINED LIB_INSTALL_DIR)
	message(STATUS "Using supplied library directory installation path.")
	set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR ${LIB_INSTALL_DIR})
else ()
	if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib32)
	elseif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib64)
	else ()
		set (${PROJECT_NAME}_LIBRARY_INSTALL_DIR lib)
	endif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
endif (DEFINED LIB_INSTALL_DIR)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
	add_compile_options("-Wall")
	add_compile_options("-Wextra")
	add_compile_options("-Wpedantic")
	add_compile_options("-Wconversion")
	add_compile_options("-Wfloat-equal")
	add_compile_options("-Werror")
	# Justification no-attributes: Seems to trigger a bug where it fails for enum class types.
	add_compile_options("-Wno-attributes")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
	message(WARNING "Compilations options not set.")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
	add_compile_options("/W4")
	add_compile_options("/utf-8")
	add_compile_options("/WX")
	add_compile_options("/WX")
	# Justification: This is flagging in third party libraries.
	add_compile_options("/wd26498")
	# Justification: This is flagging in third party libraries.
	add_compile_options("/wd26812")
	# Justification: This is flagging third party libraries.
	add_compile_options("/wd26495")
	# Justification: This is flagging third party libraries.
	add_compile_options("/wd26451")
endif()

add_subdirectory(src)

set(CPACK_PACKAGE_HOMEPAGE_URL ${${PROJECT_NAME}_HOMEPAGE_URL})
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
include(CPack)
