cmake_minimum_required(VERSION 3.10)

# Variables defined externally. They should be set using the "cmake" command.
#
# CMAKE_BUILD_TYPE: the type of the build. It can be "Debug" or "Release".

set(BUILD_TYPE_DEBUG "Debug")
set(BUILD_TYPE_RELEASE "Release")

project(grm)

set(CMAKE_DEBUG_POSTFIX "")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Start compiler settings.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
	message("Using GNU compiler: setting strong requirements for building.")
	add_compile_options(
		-Wall -Wextra -pedantic -Wconversion -Wsuggest-override
		-Werror=suggest-override -Wformat=2
	)
	if(CMAKE_BUILD_TYPE STREQUAL BUILD_TYPE_DEBUG)
		add_compile_options(-g)
	endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
	message("Using Clang compiler: setting strong requirements for building.")
	add_compile_options(
		-Weverything -Wno-reserved-identifier -Wno-c++98-compat
		-Wno-reserved-macro-identifier -Wno-c++98-compat-pedantic
		-Wno-missing-noreturn -Wno-padded -Wno-unsafe-buffer-usage
		-Wno-double-promotion -Wno-unused-function -Wno-old-style-cast
		-Wno-switch-default -Wno-global-constructors -Wno-exit-time-destructors
	)
	if(CMAKE_BUILD_TYPE STREQUAL BUILD_TYPE_DEBUG)
		add_compile_options(-g)
	endif()
else()
	message("Compiler used: ${CMAKE_CXX_COMPILER_ID}")
	message("No extra options added.")
endif()
# End compiler settings.

# We can use `#include "grm/grm.hpp`.
include_directories(src)

# We generate the grm static library.
file(GLOB_RECURSE grm_sources "src/grm/*cpp")
file(GLOB_RECURSE grm_headers "src/grm/*hpp")
add_library(grm STATIC ${grm_headers} ${grm_sources})
set_target_properties(grm PROPERTIES LINKER_LANGUAGE CXX)

# We generate grm-to-json.
file(GLOB_RECURSE grm_to_json_sources "src/bin/grm-to-json/*cpp")
file(GLOB_RECURSE grm_to_json_headers "src/bin/grm-to-json/*hpp")
add_executable(grm_to_json ${grm_to_json_headers} ${grm_to_json_sources})
set_target_properties(grm_to_json PROPERTIES OUTPUT_NAME "grm-to-json")
target_link_libraries(grm_to_json grm)

# We generate grm-definition-to-json.
file(
	GLOB_RECURSE grm_definition_to_json_sources
	"src/bin/grm-definition-to-json/*cpp"
)
file(
	GLOB_RECURSE grm_definition_to_json_headers
	"src/bin/grm-definition-to-json/*hpp"
)
add_executable(
	grm_definition_to_json ${grm_definition_to_json_headers}
	${grm_definition_to_json_sources}
)
set_target_properties(
	grm_definition_to_json PROPERTIES OUTPUT_NAME "grm-definition-to-json"
)
target_link_libraries(grm_definition_to_json grm)
