# This file is automatically generated from cmake.toml - DO NOT EDIT
# See https://github.com/build-cpp/cmkr for more information

cmake_minimum_required(VERSION 3.15)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
	message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build")
endif()

# Regenerate CMakeLists.txt automatically in the root project
set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
	set(CMKR_ROOT_PROJECT ON)

	# Bootstrap cmkr
	include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
	if(CMKR_INCLUDE_RESULT)
		cmkr()
	endif()

	# Enable folder support
	set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

# Create a configure-time dependency on cmake.toml to improve IDE support
if(CMKR_ROOT_PROJECT)
	configure_file(cmake.toml cmake.toml COPYONLY)
endif()

project(steamtwice-proj)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

set(ASMJIT_STATIC ON CACHE BOOL "" FORCE)

if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")

    # Statically compile runtime
    string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
    string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
    string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")

    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
    message(NOTICE "Building in Release mode")
endif()

include(FetchContent)

message(STATUS "Fetching bddisasm (v1.34.10)...")
FetchContent_Declare(bddisasm
	GIT_REPOSITORY
		"https://github.com/bitdefender/bddisasm"
	GIT_TAG
		v1.34.10
)
FetchContent_MakeAvailable(bddisasm)

message(STATUS "Fetching safetyhook (e175896c67abf49360acafe8879205a138fe6b2b)...")
FetchContent_Declare(safetyhook
	GIT_REPOSITORY
		"https://github.com/cursey/safetyhook"
	GIT_TAG
		e175896c67abf49360acafe8879205a138fe6b2b
)
FetchContent_MakeAvailable(safetyhook)

# Target steamtwice
set(CMKR_TARGET steamtwice)
set(steamtwice_SOURCES "")

list(APPEND steamtwice_SOURCES
	steamtwice.cpp
)

list(APPEND steamtwice_SOURCES
	cmake.toml
)

set(CMKR_SOURCES ${steamtwice_SOURCES})
add_library(steamtwice SHARED)

if(steamtwice_SOURCES)
	target_sources(steamtwice PRIVATE ${steamtwice_SOURCES})
endif()

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${steamtwice_SOURCES})

target_compile_definitions(steamtwice PUBLIC
	_WINSOCKAPI_
)

target_compile_features(steamtwice PUBLIC
	cxx_std_20
)

target_compile_options(steamtwice PUBLIC
	"/MP"
)

target_link_libraries(steamtwice PUBLIC
	safetyhook
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)

