- set(HAVE_SEM_OPEN 0)
- endif()
-
- if(HAVE_SEM_INIT_LIB)
- execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_init.c -lpthread -o sem_init
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- RESULT_VARIABLE HAVE_SEM_INIT_run OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
-
- # Test sem_init by compiling:
- if(HAVE_SEM_INIT_compil)
- set(HAVE_SEM_INIT 0)
- message(STATUS "Warning: sem_init not compilable")
- message(STATUS "HAVE_SEM_INIT_comp_output: ${HAVE_SEM_OPEN_comp_output}")
- else()
- set(HAVE_SEM_INIT 1)
- message(STATUS "sem_init is compilable")
- endif()
-
- # If we're not crosscompiling, we check by executing the program:
- if (HAVE_SEM_INIT AND NOT CMAKE_CROSSCOMPILING)
- execute_process(COMMAND ./sem_init
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- RESULT_VARIABLE HAVE_SEM_INIT_run
- OUTPUT_VARIABLE var_compil
- )
- if (NOT HAVE_SEM_INIT_run)
- set(HAVE_SEM_INIT 1)
- message(STATUS "sem_init is executable")
- else()
- set(HAVE_SEM_INIT 0)
- if(EXISTS "${CMAKE_BINARY_DIR}/sem_init")
- message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!")
- else()
- message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!")
- endif()
- message(STATUS "Warning: sem_init not executable")
- message(STATUS "Compilation output: '${var_compil}'")
- message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}")
- endif()
- endif()
- file(REMOVE sem_init)
- endif()
-
- if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT)
- message(FATAL_ERROR "Semaphores are not usable (neither sem_open nor sem_init is both compilable and executable), but they are mandatory to threads (you may need to mount /dev).")
- endif()
-
- ### Test that we have a way to timewait for semaphores
-
- if(HAVE_SEM_TIMEDWAIT_LIB)
-
- execute_process(
- COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_timedwait.c -lpthread"
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run
- )
-
- if(HAVE_SEM_TIMEDWAIT_run)
- set(HAVE_SEM_TIMEDWAIT 0)
- message(STATUS "timedwait not compilable")
- else()
- set(HAVE_SEM_TIMEDWAIT 1)
- message(STATUS "timedwait is compilable")
- endif()
- endif()
-
- ### HAVE_MUTEX_TIMEDLOCK
-
- if(HAVE_MUTEX_TIMEDLOCK_LIB)
-
- execute_process(
- COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_mutex_timedlock.c -lpthread"
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- OUTPUT_VARIABLE HAVE_MUTEX_TIMEDLOCK_run
- )
-
- if(HAVE_MUTEX_TIMEDLOCK_run)
- set(HAVE_MUTEX_TIMEDLOCK 0)
- message(STATUS "timedlock not compilable")
- else()
- message(STATUS "timedlock is compilable")
- set(HAVE_MUTEX_TIMEDLOCK 1)
- endif()