Skip to content

Commit

Permalink
NetBSD fixes (indilib#2053)
Browse files Browse the repository at this point in the history
* Use CMAKE_DL_LIBS

This variable handles different operating systems correctly.
On some, like NetBSD, there is no libdl and the code is in libc.

* Handle NetBSD like FreeBSD

Fixes error about missing B576000 symbol.

* Only use mremap if MREMAP_MAYMOVE exists.

NetBSD has mremap, but no MREMAP_MAYMOVE.

* Add header for sockaddr_in.

* Link against librt for shm_*()

* Also include sys/ioct.h on NetBSD.

This should probably be done for other *BSDs too.
TODO: Add a cmake check for it?

* Always include stdarg.h

It's a C library standard header, and it's needed for va_*.

* Fix typo in macro check.

* Do not include netinet/in.h on Windows

also exclude Cygwin, unsure about that.

* Do not link against librt on macOS.
  • Loading branch information
0-wiz-0 authored May 19, 2024
1 parent 9195081 commit 560a072
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libs/alignment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ add_library(AlignmentDriver SHARED ${AlignmentDriver_SRC})
set_target_properties(AlignmentDriver PROPERTIES COMPILE_FLAGS "-fPIC")

IF(APPLE)
target_link_libraries(AlignmentDriver dl -L/usr/local/lib ${GSL_LIBRARIES})
target_link_libraries(AlignmentDriver ${CMAKE_DL_LIBS} -L/usr/local/lib ${GSL_LIBRARIES})
ELSE()
# Force linking all referenced libraries because of libgsl is not linked against cblas library on Linux
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")
target_link_libraries(AlignmentDriver dl ${GSL_LIBRARIES}
target_link_libraries(AlignmentDriver ${CMAKE_DL_LIBS} ${GSL_LIBRARIES}
$<$<PLATFORM_ID:CYGWIN>:indidriver>
)
ENDIF()
Expand Down
3 changes: 3 additions & 0 deletions libs/indicore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ if(UNIX)
list(APPEND ${PROJECT_NAME}_SOURCES
sharedblob_parse.cpp
shm_open_anon.c)
if(UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_NAME} rt)
endif()
endif()

target_compile_definitions(${PROJECT_NAME}
Expand Down
4 changes: 2 additions & 2 deletions libs/indicore/indicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <string.h>
#include <time.h>

#ifdef __linux__
#if defined(__linux__) || defined(__NetBSD__)
#include <sys/ioctl.h>
#endif

Expand Down Expand Up @@ -793,7 +793,7 @@ int tty_connect(const char *device, int bit_rate, int word_size, int parity, int
case 57600: bps = B57600; break;
case 115200: bps = B115200; break;
case 230400: bps = B230400; break;
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
case 460800: bps = B460800; break;
case 576000: bps = B576000; break;
case 921600: bps = B921600; break;
Expand Down
2 changes: 0 additions & 2 deletions libs/indicore/indidevapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@
*
*/

#if defined(_WIN32) || defined(__CYGWIN__)
#include <stdarg.h>
#endif
#include "indiapi.h"
#include "lilxml.h"

Expand Down
2 changes: 1 addition & 1 deletion libs/indicore/sharedblob.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void * IDSharedBlobRealloc(void * ptr, size_t size)
int ret = ftruncate(sb->fd, reallocated);
if (ret == -1) return NULL;

#ifdef HAVE_MREMAP
#ifdef MREMAP_MAYMOVE
void * remaped = mremap(sb->mapstart, sb->allocated, reallocated, MREMAP_MAYMOVE);
if (remaped == MAP_FAILED) return NULL;

Expand Down
3 changes: 3 additions & 0 deletions libs/sockets/tcpsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <errno.h>
#include <chrono>
#include <algorithm>
#if !defined(_WIN32) && !defined(__CYGWIN__)
#include <netinet/in.h>
#endif

// SocketAddress
const char *SocketAddress::unixDomainPrefix = "localhost:";
Expand Down

0 comments on commit 560a072

Please sign in to comment.