cmake_minimum_required(VERSION 3.0) #emulate a target 3rd party library folders SET(3RDPARTY_ROOT "/tmp/3rdparty") MACRO(DETECT_USRSCTPLIB issueError) #status messages MESSAGE(STATUS "Looking for usrsctp") MESSAGE(STATUS "Before calling UNSET: USRSCTP_INCLUDE_PATH: ${USRSCTP_INCLUDE_PATH}") MESSAGE(STATUS "Before calling UNSET: USRSCTP_LIBRARY_PATH: ${USRSCTP_LIBRARY_PATH}") #unset the variables UNSET(USRSCTP_INCLUDE_PATH) UNSET(USRSCTP_LIBRARY_PATH) UNSET(USRSCTP_INCLUDE_PATH CACHE) UNSET(USRSCTP_LIBRARY_PATH CACHE) MESSAGE(STATUS "After calling UNSET, before FIND_XXX: USRSCTP_INCLUDE_PATH: ${USRSCTP_INCLUDE_PATH}") MESSAGE(STATUS "After calling UNSET, before FIND_XXX: USRSCTP_LIBRARY_PATH: ${USRSCTP_LIBRARY_PATH}") #attempt the find FIND_PATH(USRSCTP_INCLUDE_PATH NAMES usrsctp.h PATHS ${3RDPARTY_ROOT}/install/include NO_DEFAULT_PATH) FIND_LIBRARY(USRSCTP_LIBRARY_PATH NAMES usrsctp PATHS ${3RDPARTY_ROOT}/install/lib NO_DEFAULT_PATH) MESSAGE(STATUS "After calling FIND_XXX: USRSCTP_INCLUDE_PATH: ${USRSCTP_INCLUDE_PATH}") MESSAGE(STATUS "After calling FIND_XXX: USRSCTP_LIBRARY_PATH: ${USRSCTP_LIBRARY_PATH}") IF(USRSCTP_INCLUDE_PATH) SET(USRSCTP_FOUND 1 CACHE STRING "Set to 1 if usrsctp is found, 0 otherwise") MESSAGE(STATUS "Looking for usrsctp headers - found") ELSE(USRSCTP_INCLUDE_PATH) IF(${issueError} MATCHES "1") SET(USRSCTP_FOUND 0 CACHE STRING "Set to 1 if usrsctp is found, 0 otherwise") MESSAGE(FATAL_ERROR "Looking for usrsctp headers - not found") ELSE(${issueError} MATCHES "1") SET(USRSCTP_FOUND 0) ENDIF(${issueError} MATCHES "1") ENDIF(USRSCTP_INCLUDE_PATH) IF(USRSCTP_LIBRARY_PATH) SET(USRSCTP_FOUND 1 CACHE STRING "Set to 1 if usrsctp is found, 0 otherwise") MESSAGE(STATUS "Looking for usrsctp library - found") ELSE(USRSCTP_LIBRARY_PATH) IF(${issueError} MATCHES "1") SET(USRSCTP_FOUND 0 CACHE STRING "Set to 1 if usrsctp is found, 0 otherwise") MESSAGE(FATAL_ERROR "Looking for usrsctp library - not found") ELSE(${issueError} MATCHES "1") SET(USRSCTP_FOUND 0) ENDIF(${issueError} MATCHES "1") ENDIF(USRSCTP_LIBRARY_PATH) ENDMACRO(DETECT_USRSCTPLIB) #try to detect first, tolerate failures DETECT_USRSCTPLIB("0") IF(NOT ${USRSCTP_FOUND}) #ok, lib not there, try to build it MESSAGE(STATUS "usrsctp library not found. Try to build it...") #emulate the build EXECUTE_PROCESS(COMMAND mkdir -p ${3RDPARTY_ROOT}/install/include ${3RDPARTY_ROOT}/install/lib) EXECUTE_PROCESS(COMMAND touch ${3RDPARTY_ROOT}/install/include/usrsctp.h) EXECUTE_PROCESS(COMMAND touch ${3RDPARTY_ROOT}/install/lib/libusrsctp.a) #try to find it again, this time with errors DETECT_USRSCTPLIB("1") #done MARK_AS_ADVANCED(USRSCTP_FOUND) ELSE(NOT ${USRSCTP_FOUND}) #found, done MARK_AS_ADVANCED(USRSCTP_FOUND) ENDIF(NOT ${USRSCTP_FOUND})