# This file should only be included when using Pthreads

SET(LIB_NAME OpenThreads)
SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})

ADD_LIBRARY(${LIB_NAME}
    ${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
    ${LIB_PUBLIC_HEADERS}
	PThread.c++
	PThreadBarrier.c++
	PThreadBarrierPrivateData.h
	PThreadCondition.c++
	PThreadConditionPrivateData.h
	PThreadMutex.c++
	PThreadMutexPrivateData.h
	PThreadPrivateData.h
	../common/Version.cpp
)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    OPTION(TWO_PARAM_sched_setaffinity "Set to ON to use the two parameter sched_setaffinity (required on older rev's of RedHat)" OFF)
    IF(TWO_PARAM_sched_setaffinity)
      ADD_DEFINITIONS(-DCOMPILE_USING_TWO_PARAM_sched_setaffinity)
    ENDIF(TWO_PARAM_sched_setaffinity)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(OPENTHREADS_SONAMES)
  SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
ENDIF(OPENTHREADS_SONAMES)

TARGET_LINK_LIBRARIES(${LIB_NAME}
	${CMAKE_THREAD_LIBS_INIT}
)

# Since we're building different platforms binaries in 
# their respective directories, we need to set the 
# link directory so it can find this location.
LINK_DIRECTORIES(
	${CMAKE_CURRENT_BINARY_DIR}
)

INSTALL(
	TARGETS OpenThreads
	ARCHIVE DESTINATION lib${LIB_POSTFIX}
	LIBRARY DESTINATION lib${LIB_POSTFIX}
	RUNTIME DESTINATION bin
)
INSTALL(
	FILES ${OpenThreads_PUBLIC_HEADERS}
	DESTINATION include/OpenThreads
)

#commented out# INCLUDE(ModuleInstall OPTIONAL)
