Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update curses detection for Autotools and CMake #1052

Merged
merged 12 commits into from
Mar 12, 2024
79 changes: 47 additions & 32 deletions config/sst_check_curses.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,58 @@ AC_DEFUN([SST_CHECK_CURSES],
sst_check_curses_happy="yes"

AC_ARG_WITH([curses],
[AS_HELP_STRING([--with-ncurses@<:@=DIR@:>@],
[Use ncurses library found in DIR])])
[AS_HELP_STRING([--with-ncurses@<:@=DIR or EXEC@:>@],
[Use ncurses library found in DIR or associated with the ncursesN-config utility specified by EXEC])])

AS_IF([test "$with_curses" = "no"], [sst_check_curses_happy="no"])

CPPFLAGS_saved="$CPPFLAGS"
LDFLAGS_saved="$LDFLAGS"

dnl Use user-defined curses library
AS_IF([test "$sst_check_curses_happy" = "yes"], [
AS_IF([test ! -z "$with_curses" -a "$with_curses" != "yes"],
[CURSES_CPPFLAGS="-I$with_curses/include"
CPPFLAGS="$CURSES_CPPFLAGS $CPPFLAGS"
CURSES_LDFLAGS="-L$with_curses/lib"
CURSES_LIBS="-lncurses",
LDFLAGS="$CURSES_LDFLAGS $LDFLAGS"],
[CURSES_CPPFLAGS=
CURSES_CPPFLAGS_LDFLAGS=
CURSES_LIBS=])])

dnl Check for curses.h header
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([curses.h], [], [sst_check_curses_happy="no"])
AC_LANG_POP([C++])

dnl Check that library is usable
AS_IF([test "$sst_check_curses_happy" != "no"],
[AC_CHECK_LIB([ncursesw], [wprintw], [CURSES_LIBS="-lncursesw"],
[AC_CHECK_LIB([ncurses], [wprintw], [CURSES_LIBS="-lncurses"],
[AC_CHECK_LIB([curses], [wprintw], [CURSES_LIBS="-lcurses"], [sst_check_curses_happy = "no"])])])
])

CPPFLAGS="$CPPFLAGS_saved"
LDFLAGS="$LDFLAGS_saved"
NCURSES_CONFIG_EXE="no"

dnl check if user provided a specific ncursesN-config
AS_IF([test ! -d "$with_curses"],
[AS_IF([test -x "$with_curses"],
[NCURSES_CONFIG_EXE=$with_curses])])

dnl test ncursesN-config
AS_IF([test $NCURSES_CONFIG_EXE = "no"],
[AS_IF([test -n "$with_curses"],
[AC_PATH_PROGS([NCURSES_CONFIG_EXE], ["ncurses6-config" "ncurses5.4-config" "ncurses5-config"], ["no"], ["$with_curses/bin"])],
[AC_PATH_PROGS([NCURSES_CONFIG_EXE], ["ncurses6-config" "ncurses5.4-config" "ncurses5-config"], ["no"])])])

dnl don't continue if ncursesN-config can't be found rather than look for the
dnl specific libraries
AS_IF([test $NCURSES_CONFIG_EXE = "no"],
[
CURSES_CPPFLAGS=
CURSES_LIBS=
sst_check_curses_happy="no"
],
[
dnl Older versions only have --libs, not --libs-only-l and --libs-only-L,
dnl which combines the two. Ideally, CURSES_LDFLAGS (sstinfo_x_LDFLAGS)
dnl contains --libs-only-L and CURSES_LIBS (sstinfo_x_LDADD) contains
dnl --libs-only-l, but rather than complicated logic testing the above,
dnl combining everything into LDADD seems acceptable..
CURSES_CPPFLAGS=`$NCURSES_CONFIG_EXE --cflags`
CURSES_LIBS=`$NCURSES_CONFIG_EXE --libs`

CPPFLAGS_saved="$CPPFLAGS"
LDFLAGS_saved="$LDFLAGS"

CPPFLAGS="$CPPFLAGS $CURSES_CPPFLAGS"
LDFLAGS="$LDFLAGS $CURSES_LIBS"

dnl Check for specific header
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([ncurses.h], [], [sst_check_curses_happy="no"])
AC_LANG_POP([C++])

CPPFLAGS="$CPPFLAGS_saved"
LDFLAGS="$LDFLAGS_saved"
]
)

AC_SUBST([CURSES_CPPFLAGS])
AC_SUBST([CURSES_LDFLAGS])
AC_SUBST([CURSES_LIBS])
AS_IF([test "x$sst_check_curses_happy" = "xyes"], [AC_DEFINE([HAVE_CURSES], [1], [Defines whether we have the curses library])])
AM_CONDITIONAL([USE_CURSES], [test "x$sst_check_curses_happy" = "xyes"])
Expand Down
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ SST_CHECK_MPI([], [AC_MSG_ERROR([Could not find MPI package])])
SST_CHECK_PYTHON([], [AC_MSG_ERROR([Could not find Python, this is required for SST to build])])
SST_CHECK_LIBZ([have_zlib="yes"],[have_zlib="no"],[AC_MSG_ERROR([zlib was requested but could not be found.])])
SST_CHECK_CURSES()
dnl AC_MSG_ERROR([Could not find curses, this is required for utility sst-info to build])])
SST_CHECK_BACKTRACE()
SST_CHECK_HDF5()
SST_CHECK_MEM_POOL()
Expand Down Expand Up @@ -228,6 +227,7 @@ echo "Configuration Information (Dependencies):"
echo ""

printf "%38s : %s (%s)\n" "Found Python" "$PYTHON_EXE" "$PYTHON_VERSION"

if test "x$sst_check_hdf5_happy" = "xyes" ; then
printf "%38s : Yes\n" "HDF5 Support"
else
Expand All @@ -240,9 +240,9 @@ else
fi

if test "x$sst_check_curses_happy" = "xyes" ; then
printf "%38s : Yes\n" "curses library"
printf "%38s : %s %s\n" "curses library" "$CURSES_LIBS"
else
printf "%38s : No\n" "curses library"
printf "%38s : Not found\n" "curses library"
fi

echo "-------------------------------------------------------"
13 changes: 13 additions & 0 deletions experimental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ if(NOT SST_DISABLE_ZLIB)
find_package(ZLIB)
endif()

option(SST_DISABLE_CURSES
"Use curses library (needed for interactive sst-info)" OFF)
if(NOT SST_DISABLE_CURSES)
# https://gitlab.kitware.com/cmake/cmake/-/issues/23236
set(CURSES_NEED_NCURSES 1)
find_package(Curses)
if(NOT CURSES_HAVE_NCURSES_H)
message(
FATAL_ERROR
"Curses was found, but the specific header <ncurses.h> was not")
endif()
endif()

option(SST_ENABLE_HDF5 "Use HDF5 library" OFF)
if(SST_ENABLE_HDF5)
find_package(HDF5 REQUIRED)
Expand Down
4 changes: 4 additions & 0 deletions experimental/cmake/sst.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ if(ZLIB_FOUND)
set(HAVE_LIBZ ON)
endif(ZLIB_FOUND)

if(CURSES_FOUND)
set(HAVE_CURSES ON)
endif(CURSES_FOUND)

check_include_file(execinfo.h HAVE_EXECINFO_H)
check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
check_include_file(mach/mach_time.h HAVE_MACH_MACH_TIME_H)
Expand Down
3 changes: 3 additions & 0 deletions experimental/cmake_configure_files/sst_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
/* Define to 1 if you have the <c_asm.h> header file. */
#cmakedefine HAVE_C_ASM_H 1

/* Defines whether we have the curses library */
#cmakedefine HAVE_CURSES 1

/* Define to 1 if you have the declaration of `cygwin_conv_path', and to 0 if
you don't. */
#cmakedefine HAVE_DECL_CYGWIN_CONV_PATH 1
Expand Down
7 changes: 7 additions & 0 deletions src/sst/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ if(Threads_FOUND)
target_link_libraries(sstsim.x PRIVATE Threads::Threads)
endif()

if(CURSES_FOUND)
target_link_libraries(sstinfo.x PRIVATE ${CURSES_LIBRARIES})
# Before means no chance of interfering with a system curses if a
# user-provided one was specified.
target_include_directories(sstinfo.x BEFORE PRIVATE ${CURSES_INCLUDE_DIRS})
endif()

add_executable(sst bootsst.cc)
target_link_libraries(sst PRIVATE sst-boot-lib sst-env-lib sst-config-lib)

Expand Down
3 changes: 1 addition & 2 deletions src/sst/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,8 @@ sstinfo_x_LDADD += $(LIBZ_LIBS)
endif

if USE_CURSES
AM_CPPFLAGS += $(CURSES_CFPPLAGS)
AM_CPPFLAGS += $(CURSES_CPPFLAGS)
sstinfo_x_LDADD += $(CURSES_LIBS)
sstinfo_x_LDFLAGS += $(CURSES_LDFLAGS)
endif

if USE_HDF5
Expand Down
5 changes: 5 additions & 0 deletions src/sst/core/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "sst/core/warnmacros.h"

DISABLE_WARN_DEPRECATED_REGISTER
// The Python header already defines this and should override one from the
// command line.
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#include <Python.h>
REENABLE_WARNING

Expand Down
Loading