Skip to content

Commit

Permalink
compile fixes on macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berger <[email protected]>
  • Loading branch information
chrberger committed Jun 25, 2024
1 parent 942ca33 commit 64209cf
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 99 deletions.
62 changes: 39 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ project(cluon-relay)

################################################################################
# Defining the relevant version of libcluon.
set(CLUON_COMPLETE cluon-complete-v0.0.140.hpp)
set(CLUON_COMPLETE cluon-complete-v0.0.146.hpp)

################################################################################
# Set the search path for .cmake files.
Expand All @@ -30,35 +30,51 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Build a static binary.
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
IF(NOT(APPLE))
# Build a static binary.
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
ENDIF()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(CMAKE_CXX_FLAGS "-D_DARWIN_C_SOURCE=1 ")
set(CMAKE_OSX_SYSROOT /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk)
endif()

# Add further warning levels.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-D_XOPEN_SOURCE=700 \
-D_FORTIFY_SOURCE=2 \
-O2 \
-fstack-protector \
-fomit-frame-pointer \
-pipe \
-Weffc++ \
-Wall -Wextra -Wshadow -Wdeprecated \
-Wdiv-by-zero -Wfloat-equal -Wfloat-conversion -Wsign-compare -Wpointer-arith \
-Wuninitialized -Wunreachable-code \
-Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-but-set-parameter -Wunused-but-set-variable \
-Wunused-value -Wunused-variable -Wunused-result \
-Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn")
-D_XOPEN_SOURCE=700 \
-D_FORTIFY_SOURCE=2 \
-O2 \
-fstack-protector \
-fomit-frame-pointer \
-pipe \
-Weffc++ \
-Wall -Wextra -Wshadow -Wdeprecated \
-Wdiv-by-zero -Wfloat-equal -Wfloat-conversion -Wsign-compare -Wpointer-arith \
-Wuninitialized -Wunreachable-code \
-Wunused -Wunused-function -Wunused-label -Wunused-parameter \
-Wunused-value -Wunused-variable -Wunused-result \
-Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn")

# Threads are necessary for linking the resulting binaries as UDPReceiver is running in parallel.
# assume built-in pthreads on MacOS
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LIBRARIES Threads::Threads)
IF(APPLE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
ELSE()
find_package(Threads REQUIRED)
set(LIBRARIES ${LIBRARIES} Threads::Threads)
ENDIF()

if(UNIX)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
find_package(LibRT REQUIRED)
set(LIBRARIES ${LIBRARIES} ${LIBRT_LIBRARIES})
include_directories(SYSTEM ${LIBRT_INCLUDE_DIR})
endif()
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
find_package(LibRT REQUIRED)
set(LIBRARIES ${LIBRARIES} ${LIBRT_LIBRARIES})
include_directories(SYSTEM ${LIBRT_INCLUDE_DIR})
endif()
endif()

################################################################################
Expand Down
Loading

0 comments on commit 64209cf

Please sign in to comment.