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

install(
	FILES
		algorithm.hpp
		array.hpp
		assert.hpp
		bit.hpp
		bounds.hpp
		bstring.hpp
		buffer.hpp
		buildinfo.hpp
		byteswap.hpp
		concepts.hpp
		def.hpp
		defer.hpp
		defines.hpp
		error.hpp
		fmt.hpp
		hardware.hpp
		hashmap.hpp
		heapmgr.hpp
		iterator.hpp
		math.hpp
		memops.hpp
		memory.hpp
		new.hpp
		optional.hpp
		point.hpp
		random.hpp
		ranges.hpp
		serialize.hpp
		size.hpp
		stacktrace.hpp
		std.hpp
		stddef.hpp
		string.hpp
		stringview.hpp
		strongint.hpp
		strops.hpp
		trace.hpp
		typeinfo.hpp
		types.hpp
		typetraits.hpp
		units.hpp
		uuid.hpp
		vec.hpp
		vector.hpp
		writer.hpp
	DESTINATION
		include/ox/std
)

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

if(OX_RUN_TESTS)
	add_subdirectory(test)
endif()
