cmake_minimum_required(VERSION 3.16)

file(READ src/version.h version)
string(REGEX MATCH "#define VERSION_MAJOR +([0-9]+).*#define VERSION_MINOR +([0-9]+).*#define VERSION_REV +([0-9]+)" _ ${version})
set(PROJECT_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")
message("PROJECT_VERSION=${PROJECT_VERSION}")

project(instvpm VERSION ${PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)

add_compile_definitions(
   WIN32
   _CRT_SECURE_NO_WARNINGS
   __LP64__
)

set_source_files_properties(
   src/instvpm/InstallVPinMAME.rc LANGUAGE RC
)

add_executable(instvpm WIN32
   src/instvpm/Globals.cpp
   src/instvpm/Globals.h
   src/instvpm/resource.h
   src/instvpm/InstallVPinMAME.cpp
   src/instvpm/TestVPinMAME.cpp
   src/instvpm/TestVPinMAME.h
   src/instvpm/Utils.cpp
   src/instvpm/Utils.h

   src/instvpm/InstallVPinMAME.rc
   src/win32com/VPinMAME.idl
)

set(OPT_COMMON /Ob2 /O2 /Oi /fp:fast /fp:except- /Ot /GF /GS- /Gy /GR- /Oy /GT /GL /EHsc)

target_compile_options(instvpm PUBLIC
   $<$<CONFIG:RELEASE>:$<$<COMPILE_LANGUAGE:CXX>:${OPT_COMMON}>>
   $<$<CONFIG:DEBUG>:$<$<COMPILE_LANGUAGE:CXX>:/EHsc>>
   $<$<CONFIG:RELEASE>:$<$<COMPILE_LANGUAGE:C>:${OPT_COMMON}>>
   $<$<CONFIG:DEBUG>:$<$<COMPILE_LANGUAGE:C>:/EHsc>>
)

target_include_directories(instvpm PUBLIC
   ${CMAKE_CURRENT_BINARY_DIR}/$(IntDir)
)

target_link_libraries(instvpm
   version.lib
)

target_link_options(instvpm PUBLIC
   /MANIFESTUAC:uiaccess='false'
   /MANIFESTUAC:level='highestAvailable'
   $<$<CONFIG:RELEASE>:/LTCG>
   $<$<CONFIG:RELEASE>:/DYNAMICBASE:NO>
)

set_target_properties(instvpm PROPERTIES
   VS_DPI_AWARE "On"
   RUNTIME_OUTPUT_NAME "Setup64"
   MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:DEBUG>:Debug>"
)
