Skip to content

Commit

Permalink
pthreads: Fix CMake/Autotools to check for them
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Kamina authored and cary-ilm committed May 4, 2020
1 parent 2ef3d62 commit af8864d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
8 changes: 6 additions & 2 deletions IlmBase/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ if(Threads_FOUND)

# we have threads, but do we have posix semaphores for sem_init?
# should be in pthreads
if(NOT (APPLE OR WIN32))
check_include_files(semaphore.h ILMBASE_HAVE_SEMAPHORE_H)
if(NOT (APPLE OR (WIN32 AND (NOT MINGW))))
if(MINGW)
check_include_files("pthread_unistd.h;semaphore.h" ILMBASE_HAVE_SEMAPHORE_H)
else()
check_include_files(semaphore.h ILMBASE_HAVE_SEMAPHORE_H)
endif()
if(ILMBASE_HAVE_SEMAPHORE_H AND ILMBASE_HAVE_PTHREAD)
# should just be in libc, so no need for check_library_exists
set(CMAKE_REQUIRED_FLAGS ${CMAKE_THREAD_LIBS_INIT})
Expand Down
59 changes: 40 additions & 19 deletions IlmBase/m4/threads.m4
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,46 @@ if test "${enable_posix_sem:-yes}" != "no"; then
AC_CHECK_HEADERS([semaphore.h], [
AC_SEARCH_LIBS(sem_init, [posix4 pthread], [
AC_MSG_CHECKING([whether to use POSIX unnamed semaphores])
AC_RUN_IFELSE([
AC_LANG_PROGRAM([#include <semaphore.h>], [
sem_t mysem;
if (sem_init (&mysem, 1, 1) == 0)
{
if (sem_wait (&mysem) == 0)
{
sem_post (&mysem);
sem_destroy (&mysem);
return 0;
}
}
return 1;
])
], [
AC_MSG_RESULT([yes])
am_posix_sem_ok=yes], [
AC_MSG_RESULT([no (pshared not usable)])], [
AC_MSG_RESULT([no (cannot check usability when cross compiling)])])
if test "${cross_compiling}" == "yes"; then
AC_LINK_IFELSE([
AC_LANG_PROGRAM([#include <semaphore.h>], [
sem_t mysem;
if (sem_init (&mysem, 1, 1) == 0)
{
if (sem_wait (&mysem) == 0)
{
sem_post (&mysem);
sem_destroy (&mysem);
return 0;
}
}
return 1;
])
], [
AC_MSG_RESULT([yes])
am_posix_sem_ok=yes], [
AC_MSG_RESULT([no (pshared not usable)])])
else
AC_RUN_IFELSE([
AC_LANG_PROGRAM([#include <semaphore.h>], [
sem_t mysem;
if (sem_init (&mysem, 1, 1) == 0)
{
if (sem_wait (&mysem) == 0)
{
sem_post (&mysem);
sem_destroy (&mysem);
return 0;
}
}
return 1;
])
], [
AC_MSG_RESULT([yes])
am_posix_sem_ok=yes], [
AC_MSG_RESULT([no (pshared not usable)])], [
AC_MSG_RESULT([no (we are cross-compiling, and this test should have only tried to link, not run.))])])
fi
])
])
fi
Expand Down

0 comments on commit af8864d

Please sign in to comment.