cmake_minimum_required(VERSION 3.15)

project(binary_valentine_lib
	VERSION 0.1.0.0
	LANGUAGES CXX)

if (UNIX AND NOT APPLE)
	find_package(uring REQUIRED)
endif()

find_package(Boost 1.78 REQUIRED
	COMPONENTS filesystem locale system program_options)

include(../external/pe_bliss2/cmake/library_options.cmake)

add_library(binary_valentine_lib ${BINARY_VALENTINE_LIB_BUILD_TYPE})

target_include_directories(binary_valentine_lib PRIVATE ../external/html)

include(../external/pe_bliss2/cmake/output_options.cmake)
set_output_dirs(binary_valentine_lib)
set_msvc_runtime_library(binary_valentine_lib "${BINARY_VALENTINE_MSVC_RUNTIME_LIBRARY}")

target_include_directories(binary_valentine_lib PUBLIC include "${Boost_INCLUDE_DIRS}")

target_link_libraries(binary_valentine_lib
	PRIVATE
		buffers
		pe_bliss2
		utilities
		fmt-header-only
		pugixml
		utf8cpp
		Boost::filesystem
		Boost::locale
		Boost::program_options
	PUBLIC
		Boost::system
)

if (UNIX AND NOT APPLE)
	target_compile_definitions(binary_valentine_lib PUBLIC BOOST_ASIO_HAS_IO_URING)
	target_link_libraries(binary_valentine_lib PRIVATE uring)
endif()

target_compile_features(binary_valentine_lib PRIVATE cxx_std_20)

if (WIN32)
	target_compile_definitions(binary_valentine_lib PUBLIC _WIN32_WINNT=0x0601)
endif()

target_compile_definitions(binary_valentine_lib
	PUBLIC
		BOOST_ASIO_DISABLE_BOOST_SOURCE_LOCATION
		BOOST_ASIO_DISABLE_ERROR_LOCATION)

target_sources(binary_valentine_lib
	PUBLIC
		include/binary_valentine/rule_class.h
		include/binary_valentine/version.h
		include/binary_valentine/analysis/analysis_context.h
		include/binary_valentine/analysis/analysis_plan.h
		include/binary_valentine/analysis/analysis_plan_parse_helpers.h
		include/binary_valentine/analysis/analysis_plan_provider_interface.h
		include/binary_valentine/analysis/analysis_plan_runner.h
		include/binary_valentine/analysis/command_line_analysis_plan_provider.h
		include/binary_valentine/analysis/concurrent_analysis_executor.h
		include/binary_valentine/analysis/immutable_context.h
		include/binary_valentine/analysis/result_report_file.h
		include/binary_valentine/analysis/shared_context.h
		include/binary_valentine/analysis/xml_analysis_plan_provider.h
		include/binary_valentine/common/xml_loader.h
		include/binary_valentine/common/shared_data/program_path.h
		include/binary_valentine/common/shared_generator/common_generators.h
		include/binary_valentine/common/shared_generator/program_path_generator.h
		include/binary_valentine/core/async_data_generator.h
		include/binary_valentine/core/async_data_generator_interface.h
		include/binary_valentine/core/async_value_provider.h
		include/binary_valentine/core/async_value_provider_interface.h
		include/binary_valentine/core/combined_data_generator.h
		include/binary_valentine/core/combined_data_generator_interface.h
		include/binary_valentine/core/combined_dependency_helper.h
		include/binary_valentine/core/combined_rule.h
		include/binary_valentine/core/combined_rule_interface.h
		include/binary_valentine/core/combined_value_helper.h
		include/binary_valentine/core/combined_value_provider.h
		include/binary_valentine/core/compile_time_string.h
		include/binary_valentine/core/core_error.h
		include/binary_valentine/core/data_generator.h
		include/binary_valentine/core/data_generator_helpers.h
		include/binary_valentine/core/data_generator_interface.h
		include/binary_valentine/core/data_generator_list.h
		include/binary_valentine/core/embedded_resource_loader_generator.h
		include/binary_valentine/core/embedded_resource_loader_interface.h
		include/binary_valentine/core/entity_stream_provider_interface.h
		include/binary_valentine/core/file_embedded_resource_loader.h
		include/binary_valentine/core/generic_data_generator_interface.h
		include/binary_valentine/core/hash_combine.h
		include/binary_valentine/core/inaccessible_subject_entity.h
		include/binary_valentine/core/localizable_error.h
		include/binary_valentine/core/overloaded.h
		include/binary_valentine/core/reflection.h
		include/binary_valentine/core/rule.h
		include/binary_valentine/core/rule_class_mask.h
		include/binary_valentine/core/rule_detector_container.h
		include/binary_valentine/core/rule_detector_interface.h
		include/binary_valentine/core/rule_interface.h
		include/binary_valentine/core/rule_list.h
		include/binary_valentine/core/rule_selector.h
		include/binary_valentine/core/scoped_guard.h
		include/binary_valentine/core/subject_entity_interface.h
		include/binary_valentine/core/time_tracker.h
		include/binary_valentine/core/transparent_hash.h
		include/binary_valentine/core/user_error.h
		include/binary_valentine/core/value.h
		include/binary_valentine/core/value_cache.h
		include/binary_valentine/core/value_helper.h
		include/binary_valentine/core/value_interface.h
		include/binary_valentine/core/value_provider.h
		include/binary_valentine/core/value_providers_span.h
		include/binary_valentine/core/value_provider_interface.h
		include/binary_valentine/executable/executable_extra_rule_detector.h
		include/binary_valentine/file/async_file.h
		include/binary_valentine/file/async_target_enumerator.h
		include/binary_valentine/file/file_entity.h
		include/binary_valentine/file/file_entity_stream_provider.h
		include/binary_valentine/file/file_loader.h
		include/binary_valentine/json/json_printer.h
		include/binary_valentine/output/configurable_result_report_factory.h
		include/binary_valentine/output/entity_in_memory_report_interface.h
		include/binary_valentine/output/exception_formatter.h
		include/binary_valentine/output/filtering_report_output.h
		include/binary_valentine/output/format_args_helper.h
		include/binary_valentine/output/internal_report_arg_names.h
		include/binary_valentine/output/internal_report_messages.h
		include/binary_valentine/output/in_memory_output_creator.h
		include/binary_valentine/output/in_memory_report.h
		include/binary_valentine/output/in_memory_report_creator_type.h
		include/binary_valentine/output/in_memory_report_output.h
		include/binary_valentine/output/issue_tracking_output.h
		include/binary_valentine/output/multiple_report_output.h
		include/binary_valentine/output/realtime_report_creator_type.h
		include/binary_valentine/output/result_report_interface.h
		include/binary_valentine/output/rule_report.h
		include/binary_valentine/output/rule_report_helper.h
		include/binary_valentine/output/terminal_output_creator.h
		include/binary_valentine/output/terminal_report_output.h
		include/binary_valentine/output/unformatted_common_output_report.h
		include/binary_valentine/output/format/html_report_output_format.h
		include/binary_valentine/output/format/output_format_executor.h
		include/binary_valentine/output/format/output_format_interface.h
		include/binary_valentine/output/format/sarif_output_format.h
		include/binary_valentine/output/format/text_output_format.h
		include/binary_valentine/pe/pe_format_detector.h
		include/binary_valentine/pe/pe_rule_reports.h
		include/binary_valentine/pe/combined_rule/combined_cross_signature_check_rule.h
		include/binary_valentine/pe/combined_rule/combined_dll_import_names_case_rule.h
		include/binary_valentine/pe/combined_rule/combined_version_info_rule.h
		include/binary_valentine/pe/data/basic_pe_info.h
		include/binary_valentine/pe/data/import_based_info.h
		include/binary_valentine/pe/data/main_pe_icon.h
		include/binary_valentine/pe/data/manifest_info.h
		include/binary_valentine/pe/data/version_info_list.h
		include/binary_valentine/pe/generator/authenticode_generator.h
		include/binary_valentine/pe/generator/basic_dotnet_info_generator.h
		include/binary_valentine/pe/generator/basic_pe_info_generator.h
		include/binary_valentine/pe/generator/debug_directory_generator.h
		include/binary_valentine/pe/generator/delay_import_directory_generator.h
		include/binary_valentine/pe/generator/export_directory_generator.h
		include/binary_valentine/pe/generator/icon_info_generator.h
		include/binary_valentine/pe/generator/import_based_info_generator.h
		include/binary_valentine/pe/generator/import_directory_generator.h
		include/binary_valentine/pe/generator/load_config_directory_generator.h
		include/binary_valentine/pe/generator/manifest_generator.h
		include/binary_valentine/pe/generator/pe_generators.h
		include/binary_valentine/pe/generator/pe_image_generator.h
		include/binary_valentine/pe/generator/resource_directory_generator.h
		include/binary_valentine/pe/generator/rich_header_generator.h
		include/binary_valentine/pe/generator/security_directory_generator.h
		include/binary_valentine/pe/generator/vc_feature_generator.h
		include/binary_valentine/pe/generator/version_info_generator.h
		include/binary_valentine/pe/helpers/error_helpers.h
		include/binary_valentine/pe/helpers/input_async_stream_buffer.h
		include/binary_valentine/pe/helpers/section_helpers.h
		include/binary_valentine/pe/helpers/version_helpers.h
		include/binary_valentine/pe/rule/ansi_import_rule.h
		include/binary_valentine/pe/rule/application_manifest_rule.h
		include/binary_valentine/pe/rule/authenticode_error_descriptions.h
		include/binary_valentine/pe/rule/authenticode_rule.h
		include/binary_valentine/pe/rule/cet_rule.h
		include/binary_valentine/pe/rule/checksum_rule.h
		include/binary_valentine/pe/rule/cross_resource_version_info_rule.h
		include/binary_valentine/pe/rule/debug_directory_format_rule.h
		include/binary_valentine/pe/rule/debug_directory_rule.h
		include/binary_valentine/pe/rule/directory_sections_rule.h
		include/binary_valentine/pe/rule/dotnet_header_format_rule.h
		include/binary_valentine/pe/rule/export_directory_format_rule.h
		include/binary_valentine/pe/rule/export_rule.h
		include/binary_valentine/pe/rule/flow_guards_rule.h
		include/binary_valentine/pe/rule/image_errors_rule.h
		include/binary_valentine/pe/rule/import_format_rule.h
		include/binary_valentine/pe/rule/load_config_directory_format_rule.h
		include/binary_valentine/pe/rule/load_config_flags_rule.h
		include/binary_valentine/pe/rule/main_icon_rule.h
		include/binary_valentine/pe/rule/manifest_assembly_version_rule.h
		include/binary_valentine/pe/rule/manifest_format_rule.h
		include/binary_valentine/pe/rule/not_recommended_import_rule.h
		include/binary_valentine/pe/rule/pe_file_format_rule.h
		include/binary_valentine/pe/rule/pe_rules.h
		include/binary_valentine/pe/rule/relocs_rule.h
		include/binary_valentine/pe/rule/resource_directory_format_rule.h
		include/binary_valentine/pe/rule/rich_data_rule.h
		include/binary_valentine/pe/rule/safeseh_rule.h
		include/binary_valentine/pe/rule/sections_rule.h
		include/binary_valentine/pe/rule/security_cookie_rule.h
		include/binary_valentine/pe/rule/security_directory_format_rule.h
		include/binary_valentine/pe/rule/simple_flags_rule.h
		include/binary_valentine/pe/rule/vc_feature_rule.h
		include/binary_valentine/pe/rule/version_info_format_rule.h
		include/binary_valentine/pe/rule/version_info_rule.h
		include/binary_valentine/pe/shared_data/api_sets.h
		include/binary_valentine/pe/shared_data/not_recommended_imports.h
		include/binary_valentine/pe/shared_data/winapi_library_list.h
		include/binary_valentine/pe/shared_generator/api_sets_map_generator.h
		include/binary_valentine/pe/shared_generator/full_winapi_map_generator.h
		include/binary_valentine/pe/shared_generator/not_recommended_imports_generator.h
		include/binary_valentine/pe/shared_generator/pe_shared_generators.h
		include/binary_valentine/progress/progress_report_interface.h
		include/binary_valentine/progress/terminal_progress_report.h
		include/binary_valentine/resource/en.h
		include/binary_valentine/string/case_conv.h
		include/binary_valentine/string/embedded_resource_loader.h
		include/binary_valentine/string/embedded_resource_provider.h
		include/binary_valentine/string/encoding.h
		include/binary_valentine/string/resource_helper.h
		include/binary_valentine/string/resource_loader_interface.h
		include/binary_valentine/string/resource_provider_interface.h
		include/binary_valentine/string/rule_report_resource_helper.h
		include/binary_valentine/thread/concurrent_io_processing_service.h
		include/binary_valentine/thread/multi_executor_concurrent_io_processing_service.h
	PRIVATE
		src/analysis/analysis_context.cpp
		src/analysis/analysis_plan.cpp
		src/analysis/analysis_plan_parse_helpers.cpp
		src/analysis/analysis_plan_runner.cpp
		src/analysis/command_line_analysis_plan_provider.cpp
		src/analysis/concurrent_analysis_executor.cpp
		src/analysis/immutable_context.cpp
		src/analysis/result_report_file.cpp
		src/analysis/shared_context.cpp
		src/analysis/xml_analysis_plan_provider.cpp
		src/common/xml_loader.cpp
		src/common/shared_generator/common_generators.cpp
		src/common/shared_generator/program_path_generator.cpp
		src/core/async_value_provider.cpp
		src/core/combined_dependency_helper.cpp
		src/core/combined_value_provider.cpp
		src/core/core_error.cpp
		src/core/data_generator_list.cpp
		src/core/embedded_resource_loader_generator.cpp
		src/core/file_embedded_resource_loader.cpp
		src/core/rule_detector_container.cpp
		src/core/rule_list.cpp
		src/core/rule_selector.cpp
		src/core/subject_entity_interface.cpp
		src/core/time_tracker.cpp
		src/core/user_error.cpp
		src/core/value_cache.cpp
		src/core/value_provider.cpp
		src/executable/executable_extra_rule_detector.cpp
		src/file/async_file.cpp
		src/file/async_target_enumerator.cpp
		src/file/file_entity_stream_provider.cpp
		src/file/file_loader.cpp
		src/output/configurable_result_report_factory.cpp
		src/output/exception_formatter.cpp
		src/output/filtering_report_output.cpp
		src/output/format_args_helper.cpp
		src/output/in_memory_report_output.cpp
		src/output/issue_tracking_output.cpp
		src/output/multiple_report_output.cpp
		src/output/terminal_report_output.cpp
		src/output/unformatted_common_output_report.cpp
		src/output/format/html_report_output_format.cpp
		src/output/format/output_format_executor.cpp
		src/output/format/output_format_interface.cpp
		src/output/format/sarif_output_format.cpp
		src/output/format/text_output_format.cpp
		src/pe/pe_format_detector.cpp
		src/pe/combined_rule/combined_cross_signature_check_rule.cpp
		src/pe/combined_rule/combined_dll_import_names_case_rule.cpp
		src/pe/combined_rule/combined_version_info_rule.cpp
		src/pe/data/version_info_list.cpp
		src/pe/generator/authenticode_generator.cpp
		src/pe/generator/basic_dotnet_info_generator.cpp
		src/pe/generator/basic_pe_info_generator.cpp
		src/pe/generator/debug_directory_generator.cpp
		src/pe/generator/delay_import_directory_generator.cpp
		src/pe/generator/export_directory_generator.cpp
		src/pe/generator/icon_info_generator.cpp
		src/pe/generator/import_based_info_generator.cpp
		src/pe/generator/import_directory_generator.cpp
		src/pe/generator/load_config_directory_generator.cpp
		src/pe/generator/manifest_generator.cpp
		src/pe/generator/pe_generators.cpp
		src/pe/generator/pe_image_generator.cpp
		src/pe/generator/resource_directory_generator.cpp
		src/pe/generator/rich_header_generator.cpp
		src/pe/generator/security_directory_generator.cpp
		src/pe/generator/vc_feature_generator.cpp
		src/pe/generator/version_info_generator.cpp
		src/pe/helpers/input_async_stream_buffer.cpp
		src/pe/helpers/section_helpers.cpp
		src/pe/rule/ansi_import_rule.cpp
		src/pe/rule/application_manifest_rule.cpp
		src/pe/rule/authenticode_error_descriptions.cpp
		src/pe/rule/authenticode_rule.cpp
		src/pe/rule/cet_rule.cpp
		src/pe/rule/checksum_rule.cpp
		src/pe/rule/cross_resource_version_info_rule.cpp
		src/pe/rule/debug_directory_format_rule.cpp
		src/pe/rule/debug_directory_rule.cpp
		src/pe/rule/directory_sections_rule.cpp
		src/pe/rule/dotnet_header_format_rule.cpp
		src/pe/rule/export_directory_format_rule.cpp
		src/pe/rule/export_rule.cpp
		src/pe/rule/flow_guards_rule.cpp
		src/pe/rule/image_errors_rule.cpp
		src/pe/rule/import_format_rule.cpp
		src/pe/rule/load_config_directory_format_rule.cpp
		src/pe/rule/load_config_flags_rule.cpp
		src/pe/rule/main_icon_rule.cpp
		src/pe/rule/manifest_assembly_version_rule.cpp
		src/pe/rule/manifest_format_rule.cpp
		src/pe/rule/not_recommended_import_rule.cpp
		src/pe/rule/pe_file_format_rule.cpp
		src/pe/rule/pe_rules.cpp
		src/pe/rule/relocs_rule.cpp
		src/pe/rule/resource_directory_format_rule.cpp
		src/pe/rule/rich_data_rule.cpp
		src/pe/rule/safeseh_rule.cpp
		src/pe/rule/sections_rule.cpp
		src/pe/rule/security_cookie_rule.cpp
		src/pe/rule/security_directory_format_rule.cpp
		src/pe/rule/simple_flags_rule.cpp
		src/pe/rule/vc_feature_rule.cpp
		src/pe/rule/version_info_format_rule.cpp
		src/pe/rule/version_info_rule.cpp
		src/pe/shared_data/api_sets.cpp
		src/pe/shared_generator/api_sets_map_generator.cpp
		src/pe/shared_generator/full_winapi_map_generator.cpp
		src/pe/shared_generator/not_recommended_imports_generator.cpp
		src/pe/shared_generator/pe_shared_generators.cpp
		src/progress/progress_report_interface.cpp
		src/progress/terminal_progress_report.cpp
		src/string/case_conv.cpp
		src/string/embedded_resource_loader.cpp
		src/string/encoding.cpp
		src/string/resource_helper.cpp
		src/string/rule_report_resource_helper.cpp
)

if(MSVC)
	target_compile_options(binary_valentine_lib PRIVATE "/MP")
endif()
