# 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.19)

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

set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
	set(CMKR_ROOT_PROJECT ON)

	# Bootstrap cmkr and automatically regenerate CMakeLists.txt
	include("../../cmake/cmkr.cmake" OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
	if(CMKR_INCLUDE_RESULT)
		cmkr()
	endif()

	# Enable folder support
	set_property(GLOBAL PROPERTY USE_FOLDERS ON)

	# Create a configure-time dependency on cmake.toml to improve IDE support
	set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cmake.toml)
endif()

# Options
option(LIBPL_ENABLE_CLI "" OFF)
option(LIBPL_ENABLE_TESTS "" OFF)
option(LIBWOLV_ENABLE_TESTS "" OFF)
option(ELFBUG_BUILD_TESTS "" OFF)

project(cross
	LANGUAGES
		C
		CXX
)

include("widgets/Qt.cmake")

if(ELFBUG_BUILD_TESTS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
    enable_testing()
endif()

# Packages
find_package(Threads REQUIRED)

# Subdirectory: widgets
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
	set(CMAKE_FOLDER "${CMAKE_FOLDER}/widgets")
else()
	set(CMAKE_FOLDER widgets)
endif()
add_subdirectory(widgets)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})

# Subdirectory: vendor
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
	set(CMAKE_FOLDER "${CMAKE_FOLDER}/vendor")
else()
	set(CMAKE_FOLDER vendor)
endif()
add_subdirectory(vendor)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})

if((CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$") AND ELFBUG_BUILD_TESTS) # elfbug-tests
	# Subdirectory: ElfBug/tests
	set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
	if(CMAKE_FOLDER)
		set(CMAKE_FOLDER "${CMAKE_FOLDER}/ElfBug/tests")
	else()
		set(CMAKE_FOLDER "ElfBug/tests")
	endif()
	add_subdirectory("ElfBug/tests")
	set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})

endif()
# Target: minidump
set(minidump_SOURCES
	cmake.toml
	"minidump/FileParser.cpp"
	"minidump/FileParser.h"
	"minidump/GotoDialog.cpp"
	"minidump/GotoDialog.h"
	"minidump/MainWindow.cpp"
	"minidump/MainWindow.h"
	"minidump/MainWindow.ui"
	"minidump/MiniDisassembly.cpp"
	"minidump/MiniDisassembly.h"
	"minidump/MiniHexDump.cpp"
	"minidump/MiniHexDump.h"
	"minidump/MiniMemoryMap.cpp"
	"minidump/MiniMemoryMap.h"
	"minidump/MiniThreads.cpp"
	"minidump/MiniThreads.h"
	"minidump/Navigation.cpp"
	"minidump/Navigation.h"
	"minidump/REToolSync.cpp"
	"minidump/REToolSync.h"
	"minidump/main.cpp"
	"minidump/udmp-utils.h"
)

qt_executable(minidump ${minidump_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${minidump_SOURCES})

target_compile_features(minidump PRIVATE
	cxx_std_20
)

if(NOT TARGET linux-pe)
	message(FATAL_ERROR "Target \"linux-pe\" referenced by \"minidump\" does not exist!")
endif()

if(NOT TARGET udmp-parser)
	message(FATAL_ERROR "Target \"udmp-parser\" referenced by \"minidump\" does not exist!")
endif()

target_link_libraries(minidump PRIVATE
	x64dbg::widgets
	httplib::httplib
	linux-pe
	udmp-parser
)

get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
	set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT minidump)
endif()

# Target: remote_table
set(remote_table_SOURCES
	cmake.toml
	"remote_table/JsonRpcClient.cpp"
	"remote_table/JsonRpcClient.h"
	"remote_table/MainWindow.cpp"
	"remote_table/MainWindow.h"
	"remote_table/MainWindow.ui"
	"remote_table/OverlayFrame.cpp"
	"remote_table/OverlayFrame.h"
	"remote_table/OverlayFrame.ui"
	"remote_table/RemoteTable.cpp"
	"remote_table/RemoteTable.h"
	"remote_table/TableRpcData.h"
	"remote_table/TableServer.cpp"
	"remote_table/TableServer.h"
	"remote_table/main.cpp"
)

qt_executable(remote_table ${remote_table_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${remote_table_SOURCES})

target_compile_features(remote_table PRIVATE
	cxx_std_20
)

target_link_libraries(remote_table PRIVATE
	x64dbg::widgets
	nlohmann_json::nlohmann_json
)

get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
	set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT remote_table)
endif()

# Target: release_notes
set(release_notes_SOURCES
	cmake.toml
	"release_notes/main.cpp"
)

qt_executable(release_notes ${release_notes_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${release_notes_SOURCES})

target_compile_features(release_notes PRIVATE
	cxx_std_20
)

target_include_directories(release_notes PRIVATE
	release_notes
)

target_link_libraries(release_notes PRIVATE
	x64dbg::widgets
)

get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
	set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT release_notes)
endif()

# Target: hex_viewer
set(hex_viewer_SOURCES
	cmake.toml
	"hex_viewer/CodeEditor.cpp"
	"hex_viewer/CodeEditor.h"
	"hex_viewer/DataTable.cpp"
	"hex_viewer/DataTable.h"
	"hex_viewer/File.cpp"
	"hex_viewer/File.h"
	"hex_viewer/GotoDialog.cpp"
	"hex_viewer/GotoDialog.h"
	"hex_viewer/MainWindow.cpp"
	"hex_viewer/MainWindow.h"
	"hex_viewer/MainWindow.ui"
	"hex_viewer/MiniHexDump.cpp"
	"hex_viewer/MiniHexDump.h"
	"hex_viewer/Navigation.cpp"
	"hex_viewer/Navigation.h"
	"hex_viewer/PatternHighlighter.cpp"
	"hex_viewer/PatternHighlighter.h"
	"hex_viewer/PatternLanguage.cpp"
	"hex_viewer/PatternLanguage.h"
	"hex_viewer/Styled.h"
	"hex_viewer/main.cpp"
)

qt_executable(hex_viewer ${hex_viewer_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${hex_viewer_SOURCES})

target_compile_features(hex_viewer PRIVATE
	cxx_std_20
)

target_include_directories(hex_viewer PRIVATE
	hex_viewer
)

if(NOT TARGET libpl)
	message(FATAL_ERROR "Target \"libpl\" referenced by \"hex_viewer\" does not exist!")
endif()

if(NOT TARGET libpl-gen)
	message(FATAL_ERROR "Target \"libpl-gen\" referenced by \"hex_viewer\" does not exist!")
endif()

target_link_libraries(hex_viewer PRIVATE
	x64dbg::widgets
	libpl
	libpl-gen
	fmt::fmt-header-only
)

get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
	set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT hex_viewer)
endif()

# Target: ElfBug
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$") # linux-x64
	set(ElfBug_SOURCES
		"ElfBug/ElfBug/api/elfbug_api.cpp"
		"ElfBug/ElfBug/api/elfbug_api.h"
		"ElfBug/ElfBug/core/Debugger.Loop.Process.cpp"
		"ElfBug/ElfBug/core/Debugger.Loop.Signal.cpp"
		"ElfBug/ElfBug/core/Debugger.Loop.Thread.cpp"
		"ElfBug/ElfBug/core/Debugger.Loop.cpp"
		"ElfBug/ElfBug/core/Debugger.cpp"
		"ElfBug/ElfBug/core/Debugger.h"
		"ElfBug/ElfBug/process/Breakpoint.cpp"
		"ElfBug/ElfBug/process/Memory.cpp"
		"ElfBug/ElfBug/process/Process.cpp"
		"ElfBug/ElfBug/process/Process.h"
		"ElfBug/ElfBug/process/ProcessArch.cpp"
		"ElfBug/ElfBug/process/ProcessArch.h"
		"ElfBug/ElfBug/thread/HardwareBreakpoint.cpp"
		"ElfBug/ElfBug/thread/Registers.cpp"
		"ElfBug/ElfBug/thread/Registers.h"
		"ElfBug/ElfBug/thread/Thread.cpp"
		"ElfBug/ElfBug/thread/Thread.h"
		"ElfBug/ElfBug/types/Breakpoint.h"
		"ElfBug/ElfBug/types/ElfBug.h"
		"ElfBug/ElfBug/types/Global.h"
		cmake.toml
	)

	add_library(ElfBug STATIC)

	target_sources(ElfBug PRIVATE ${ElfBug_SOURCES})
	source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ElfBug_SOURCES})

	target_compile_features(ElfBug PUBLIC
		cxx_std_17
	)

	target_include_directories(ElfBug PUBLIC
		ElfBug
	)

	target_link_libraries(ElfBug PUBLIC
		Threads::Threads
	)

endif()
# Target: debugger
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$") # linux-x64
	set(debugger_SOURCES
		cmake.toml
		"debugger/core/DbgAdapter.cpp"
		"debugger/core/DbgAdapter.h"
		"debugger/core/LinuxArchitecture.h"
		"debugger/gui/CPUStack.cpp"
		"debugger/gui/CPUStack.h"
		"debugger/gui/MainWindow.cpp"
		"debugger/gui/MainWindow.h"
		"debugger/main.cpp"
		"debugger/resources/icons.qrc"
	)

	qt_executable(debugger ${debugger_SOURCES})
	source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${debugger_SOURCES})

	target_compile_features(debugger PRIVATE
		cxx_std_20
	)

	target_include_directories(debugger PRIVATE
		debugger
	)

	if(NOT TARGET ElfBug)
		message(FATAL_ERROR "Target \"ElfBug\" referenced by \"debugger\" does not exist!")
	endif()

	target_link_libraries(debugger PRIVATE
		x64dbg::widgets
		ElfBug
	)

	get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
	if(NOT CMKR_VS_STARTUP_PROJECT)
		set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT debugger)
	endif()

endif()
