
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fno-rtti")
add_compile_options(-Wno-undefined-var-template)
add_compile_options(-Wno-inconsistent-missing-override)
endif()

if(${MSVC}) 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /we4541 /std:c++17")
endif()

if(${EXL_BUILD_OGL} OR ${EXL_BUILD_ENGINE})
set(EXL_REFLANG_ENABLED ON)
else()
set(EXL_REFLANG_ENABLED OFF)
endif()

set(EXL_DEPS_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(EXL_COMPILER_DEFINITIONS -DTRACE_LEAKS -DNOMINMAX -DBOOST_FLYWEIGHT_EXPLICIT_INIT -DEXL_NAME_EXPLICIT_INIT)
set(EXL_COMPILER_DEFINITIONS ${EXL_COMPILER_DEFINITIONS} -DEXL_THREADAWARE)
set(EXL_COMPILER_DEFINITIONS ${EXL_COMPILER_DEFINITIONS} -DEXL_TYPE_ENABLED)

set(EXL_COMPILER_SYS_DEFINITIONS)
if(MSVC)
  set(EXL_COMPILER_SYS_DEFINITIONS ${EXL_COMPILER_SYS_DEFINITIONS} -DMSVC_COMPILER)
  if(${MSVC}) 
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
  endif()
endif()

if(EXL_BUILD_FOR_UE4)
  add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
endif()


if(${EXL_BUILD_SHARED})
  SET(LIBRARY_TYPE SHARED)
  SET(LIBRARY_DEPS_VISIBILITY PRIVATE)
  set(EXL_COMPILER_DEFINITIONS ${EXL_COMPILER_DEFINITIONS} -DEXL_SHARED_LIBRARY)
  if(${MSVC})
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275")
  endif()
else()
  SET(LIBRARY_TYPE STATIC)
  SET(LIBRARY_DEPS_VISIBILITY PUBLIC)
endif()

if(${EXL_REFLANG_ENABLED})
  if(${CMAKE_SYSTEM_NAME} MATCHES "Windows"
  OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    set(EXL_CAN_BUILD_REFLANG ON)
    set(EXL_REFLANG_EXE_PATH $<TARGET_FILE:eXl_reflang>)
  else()
    set(EXL_CAN_BUILD_REFLANG OFF)
    SET(EXL_REFLANG_EXE_PATH "" CACHE PATH "Path to eXl_reflang")
  endif()
endif()