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
)

install(
	FILES
		algorithm.hpp
		array.hpp
		assert.hpp
		bit.hpp
		bounds.hpp
		istring.hpp
		buffer.hpp
		buildinfo.hpp
		byteswap.hpp
		concepts.hpp
		conv.hpp
		def.hpp
		defer.hpp
		defines.hpp
		error.hpp
		fmt.hpp
		hardware.hpp
		hash.hpp
		hashmap.hpp
		heapmgr.hpp
		ignore.hpp
		iterator.hpp
		math.hpp
		maybeview.hpp
		memops.hpp
		memory.hpp
		new.hpp
		optional.hpp
		pair.hpp
		point.hpp
		random.hpp
		ranges.hpp
		serialize.hpp
		size.hpp
		smallmap.hpp
		stacktrace.hpp
		std.hpp
		stddef.hpp
		string.hpp
		stringliteral.hpp
		stringview.hpp
		strongint.hpp
		strconv.hpp
		stringparam.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()
