cmake_minimum_required(VERSION 3.16)

file(READ src/version.c version)
string(REGEX MATCH "[0-9\\.]+" PROJECT_VERSION ${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)

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

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>"
)
