if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
	# enable warnings
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunsafe-buffer-usage")
endif()


if(OX_USE_STDLIB AND OX_ENABLE_TRACEHOOK)
	add_library(
		OxTraceHook SHARED
			tracehook.cpp
	)
else()
	add_library(
		OxTraceHook
			tracehook.cpp
	)
endif()

target_compile_definitions(
	OxTraceHook PUBLIC
		$<$<BOOL:${OX_BARE_METAL}>:OX_BARE_METAL>
		$<$<BOOL:${OX_USE_STDLIB}>:OX_USE_STDLIB>
		$<$<BOOL:${OX_NODEBUG}>:OX_NODEBUG>
)

add_library(
	OxStd
		assert.cpp
		bit.cpp
		buffer.cpp
		buildinfo.cpp
		byteswap.cpp
		concepts.cpp
		fmt.cpp
		heapmgr.cpp
		istreamreader.cpp
		math.cpp
		memops.cpp
		random.cpp
		reader.cpp
		substitutes.cpp
		stacktrace.cpp
		string.cpp
		stringview.cpp
		strops.cpp
		trace.cpp
		typetraits.cpp
		uuid.cpp
		vec.cpp
)

if(NOT MSVC)
	target_compile_options(OxStd PRIVATE -Wsign-conversion)
	target_compile_options(OxStd PRIVATE -Wconversion)
	if(${OX_OS_LINUX} AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
		target_compile_options(OxStd PUBLIC -export-dynamic)
		#target_link_options(OxStd PUBLIC -W1,-E)
	elseif(${OX_OS_FREEBSD})
		target_link_libraries(
			OxStd PUBLIC
				execinfo
		)
	endif()
endif()

if(NOT OX_BARE_METAL)
	set_property(
		TARGET
			OxStd
		PROPERTY
			POSITION_INDEPENDENT_CODE ON
	)
endif()

target_compile_definitions(
	OxStd PUBLIC
		$<$<BOOL:${OX_USE_STDLIB}>:OX_USE_STDLIB>
		$<$<BOOL:${OX_NODEBUG}>:OX_NODEBUG>
)

if(NOT WIN32)
	target_link_libraries(
		OxStd PUBLIC
			$<$<CXX_COMPILER_ID:GNU>:$<$<BOOL:${OX_USE_STDLIB}>:dl>>
	)
endif()
target_link_libraries(
	OxStd PUBLIC
		$<$<CXX_COMPILER_ID:GNU>:gcc>
		OxTraceHook
		CityHash
)

target_include_directories(
	OxStd PUBLIC
		../../../include
)

target_include_directories(
	OxTraceHook PUBLIC
		../../../include
)

install(
	TARGETS OxStd OxTraceHook
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib
)

if(OX_RUN_TESTS)
	add_subdirectory(test)
endif()
