add_library(spinscale SHARED
	src/qutex.cpp
	src/lockerAndInvokerBase.cpp
	src/componentThread.cpp
	src/component.cpp
)

# Conditionally add qutexAcquisitionHistoryTracker.cpp only when debug locks
# are enabled, since the tracker is only referenced under CONFIG_ENABLE_DEBUG_LOCKS.
if(ENABLE_DEBUG_LOCKS)
	target_sources(spinscale PRIVATE src/qutexAcquisitionHistoryTracker.cpp)
endif()

# Ensure Boost uses dynamic linking (project-wide setting should handle this,
# but being explicit here for clarity)
target_compile_definitions(spinscale PRIVATE BOOST_ALL_DYN_LINK)
target_compile_features(spinscale PUBLIC cxx_std_20)

target_include_directories(spinscale PUBLIC
	${CMAKE_CURRENT_SOURCE_DIR}/include
	${PROJECT_SOURCE_DIR}/include
	${PROJECT_SOURCE_DIR}/smocore/include
	${PROJECT_BINARY_DIR}/include
	${Boost_INCLUDE_DIRS}
)

# Link against required dependencies for shared library
# Boost::system is PUBLIC because componentThread.h exposes Boost.Asio types
find_package(Threads REQUIRED)
target_link_libraries(spinscale PUBLIC
	Threads::Threads
	Boost::system
	Boost::log
)

# Verify Boost dynamic dependencies after build (only if script exists)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake)
	add_custom_command(TARGET spinscale POST_BUILD
		COMMAND ${CMAKE_COMMAND} -DVERIFY_FILE="$<TARGET_FILE:spinscale>"
			-P ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake
		COMMENT "Verifying Boost dynamic dependencies for spinscale"
	)
else()
	message(WARNING "VerifyBoostDynamic.cmake not found - cannot verify Boost dependencies for spinscale")
endif()
