瀏覽代碼

cmake: Update platform-specific flags

- Update the platform-specific flags in the "os-specific.cmake" file for Linux and DragonFly BSD.
- Add new files "dragonfly.cmake" and "linux.cmake" in the "os-specific" directory to define the flags for DragonFly BSD and Linux, respectively.
- Add a new file "macos.cmake" in the "os-specific" directory to define the flags for Mac OS X.
- Update the "defs.cmake" file to print the availability of fast lock.
Xenofon Karamanos 9 月之前
父節點
當前提交
6235369e1d
共有 5 個文件被更改,包括 174 次插入103 次删除
  1. 24 14
      cmake/defs.cmake
  2. 10 89
      cmake/os-specific.cmake
  3. 46 0
      cmake/os-specific/dragonfly.cmake
  4. 53 0
      cmake/os-specific/linux.cmake
  5. 41 0
      cmake/os-specific/macos.cmake

+ 24 - 14
cmake/defs.cmake

@@ -132,29 +132,39 @@ endif()
 # Locking mechanism macro
 # -----------------------
 
-option(FAST_LOCK "Use fast locking" ON)
+option(USE_FAST_LOCK "Use fast locking if available" ON)
 # Fast-lock not available for all platforms like mips Check the system processor
-if(CMAKE_SYSTEM_PROCESSOR MATCHES
-   "i386|x86_64|sparc64|sparc|arm6|arm7|ppc|ppc64|alpha|mips2|mips64"
-)
-  set(USE_FAST_LOCK YES)
-elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
-  set(USE_FAST_LOCK YES)
-  target_compile_definitions(common INTERFACE NOSMP) # memory barriers not
-                                                     # implemented for arm
-elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
-  set(USE_FAST_LOCK NO)
-  target_compile_definitions(common INTERFACE MIPS_HAS_LLSC) # likely
-  target_compile_definitions(common INTERFACE NOSMP) # very likely
+# type and set USE_FAST_LOCK accordingly
+#
+if(USE_FAST_LOCK)
+  if(CMAKE_SYSTEM_PROCESSOR MATCHES
+     "i386|x86_64|sparc64|sparc|arm6|arm7|ppc|ppc64|alpha|mips2|mips64"
+  )
+    set(USE_FAST_LOCK YES)
+  elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
+    set(USE_FAST_LOCK YES)
+    target_compile_definitions(common INTERFACE NOSMP) # memory barriers not
+                                                       # implemented for arm
+  elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
+    set(USE_FAST_LOCK NO)
+    target_compile_definitions(common INTERFACE MIPS_HAS_LLSC) # likely
+    target_compile_definitions(common INTERFACE NOSMP) # very likely
+  elseif()
+    message(
+      STATUS
+        "Fast locking not available for this platform, disabling USE_FAST_LOCK"
+    )
+    set(USE_FAST_LOCK NO)
+  endif()
 endif()
 
 # Add definitions if USE_FAST_LOCK is YES
+message(STATUS "Fast lock available: ${USE_FAST_LOCK}")
 if(USE_FAST_LOCK)
   target_compile_definitions(
     common INTERFACE FAST_LOCK ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024
   )
 endif()
-message(STATUS "Fast lock: ${USE_FAST_LOCK}")
 
 # List of locking methods in option
 set(locking_methods USE_FUTEX USE_PTHREAD_MUTEX USE_POSIX_SEM USE_SYSV_SEM)

+ 10 - 89
cmake/os-specific.cmake

@@ -4,94 +4,15 @@
 # The flags are then used by the other libraries and executables
 cmake_minimum_required(VERSION 3.10)
 
-# Linux specific flags
+set(OS_SPECIFIC_DIR "${CMAKE_SOURCE_DIR}/cmake/os-specific")
 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
-  message(STATUS "Configuring for Linux")
-  target_compile_definitions(common INTERFACE
-                HAVE_GETHOSTBYNAME2
-                HAVE_UNION_SEMUN
-                HAVE_SCHED_YIELD
-                HAVE_MSG_NOSIGNAL
-                HAVE_MSGHDR_MSG_CONTROL
-                HAVE_ALLOCA_H
-                HAVE_TIMEGM
-                HAVE_SCHED_SETSCHEDULER
-                HAVE_IP_MREQN
-                )
-  if(${RAW_SOCKS})
-    target_compile_definitions(common INTERFACE
-                USE_RAW_SOCKS
-                )
-  endif()
-  
-  message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
-  if(NOT ${USE_FAST_LOCK})
-    target_compile_definitions(common INTERFACE
-                USE_PTHREAD_MUTEX
-                )
-    target_link_libraries(common INTERFACE pthread)
-
-  else()
-    # Check if lock_method is posix or pthread
-    if(LOCK_METHOD STREQUAL "USE_POSIX_SEM" OR LOCK_METHOD STREQUAL "USE_PTHREAD_MUTEX" )
-      message(STATUS "Using ${LOCK_METHOD} for locks")
-      target_link_libraries(common INTERFACE pthread)
-    endif()
-
-  endif()
-
-  if(NOT DEFINED ${NO_SELECT})
-    target_compile_definitions(common INTERFACE
-                HAVE_SELECT
-                )
-  endif()
-
-  if(NOT DEFINED ${NO_EPOLL})
-    target_compile_definitions(common INTERFACE
-                HAVE_EPOLL
-                )
-  endif()
-
-  if(NOT DEFINED ${NO_SIGIO})
-    target_compile_definitions(common INTERFACE
-                HAVE_SIGIO_RT 
-                SIGINFO64_WORKAROUND
-                )
-  endif()
-
-endif()
-
-# DragonFly BSD specific flags
-if(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
-  message(STATUS "Configuring for DragonFly BSD")
-  target_compile_definitions(common INTERFACE
-                HAVE_SOCKADDR_SA_LEN
-                HAVE_GETHOSTBYNAME2
-                HAVE_UNION_SEMUN
-                HAVE_SCHED_YIELD
-                HAVE_MSGHDR_MSG_CONTROL
-                HAVE_CONNECT_ECONNRESET_BUG
-                HAVE_TIMEGM
-                HAVE_NETINET_IN_SYSTM
-                )
-  message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
-  if(NOT ${USE_FAST_LOCK})
-    target_compile_definitions(common INTERFACE
-                USE_PTHREAD_MUTEX
-                )
-    target_link_libraries(common INTERFACE pthread)
-  endif()
-
-  if(NOT DEFINED ${NO_KQUEUE})
-    target_compile_definitions(common INTERFACE
-                HAVE_KQUEUE
-                )
-  endif()
-
-  if(NOT DEFINED ${NO_SELECT})
-    target_compile_definitions(common INTERFACE
-                HAVE_SELECT
-                )
-  endif()
-  
+  include(${OS_SPECIFIC_DIR}/linux.cmake)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
+  # DragonFly BSD specific flags
+  include(${OS_SPECIFIC_DIR}/dragonfly.cmake)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  # Mac OS X specific flags
+  include(${OS_SPECIFIC_DIR}/darwin.cmake)
+elseif()
+  message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
 endif()

+ 46 - 0
cmake/os-specific/dragonfly.cmake

@@ -0,0 +1,46 @@
+# Linux specific flags
+message(STATUS "Configuring for Linux")
+target_compile_definitions(
+  common
+  INTERFACE HAVE_GETHOSTBYNAME2
+            HAVE_UNION_SEMUN
+            HAVE_SCHED_YIELD
+            HAVE_MSG_NOSIGNAL
+            HAVE_MSGHDR_MSG_CONTROL
+            HAVE_ALLOCA_H
+            HAVE_TIMEGM
+            HAVE_SCHED_SETSCHEDULER
+            HAVE_IP_MREQN
+)
+if(${RAW_SOCKS})
+  target_compile_definitions(common INTERFACE USE_RAW_SOCKS)
+endif()
+
+message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
+if(NOT ${USE_FAST_LOCK})
+  target_compile_definitions(common INTERFACE USE_PTHREAD_MUTEX)
+  target_link_libraries(common INTERFACE pthread)
+else()
+  # Check if lock_method is posix or pthread
+  if(LOCK_METHOD STREQUAL "USE_POSIX_SEM" OR LOCK_METHOD STREQUAL
+                                             "USE_PTHREAD_MUTEX"
+  )
+    message(STATUS "Using ${LOCK_METHOD} for locks")
+    target_link_libraries(common INTERFACE pthread)
+  endif()
+
+endif()
+
+if(NOT DEFINED ${NO_SELECT})
+  target_compile_definitions(common INTERFACE HAVE_SELECT)
+endif()
+
+if(NOT DEFINED ${NO_EPOLL})
+  target_compile_definitions(common INTERFACE HAVE_EPOLL)
+endif()
+
+if(NOT DEFINED ${NO_SIGIO})
+  target_compile_definitions(
+    common INTERFACE HAVE_SIGIO_RT SIGINFO64_WORKAROUND
+  )
+endif()

+ 53 - 0
cmake/os-specific/linux.cmake

@@ -0,0 +1,53 @@
+# Linux specific flags
+message(STATUS "Configuring for Linux")
+target_compile_definitions(
+  common
+  INTERFACE HAVE_GETHOSTBYNAME2
+            HAVE_UNION_SEMUN
+            HAVE_SCHED_YIELD
+            HAVE_MSG_NOSIGNAL
+            HAVE_MSGHDR_MSG_CONTROL
+            HAVE_ALLOCA_H
+            HAVE_TIMEGM
+            HAVE_SCHED_SETSCHEDULER
+            HAVE_IP_MREQN
+)
+if(${RAW_SOCKS})
+  target_compile_definitions(common INTERFACE USE_RAW_SOCKS)
+endif()
+
+message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
+if(NOT ${USE_FAST_LOCK})
+  target_compile_definitions(common INTERFACE USE_PTHREAD_MUTEX)
+  target_link_libraries(common INTERFACE pthread)
+else()
+  # Check if lock_method is posix or pthread
+  if(LOCK_METHOD STREQUAL "USE_POSIX_SEM" OR LOCK_METHOD STREQUAL
+                                             "USE_PTHREAD_MUTEX"
+  )
+    message(STATUS "Using ${LOCK_METHOD} for locks")
+    target_link_libraries(common INTERFACE pthread)
+  endif()
+
+endif()
+
+if(NOT DEFINED ${NO_SELECT})
+  target_compile_definitions(common INTERFACE HAVE_SELECT)
+endif()
+
+# TODO introduce check for epoll
+if(NOT DEFINED ${NO_EPOLL})
+  target_compile_definitions(common INTERFACE HAVE_EPOLL)
+endif()
+
+# TODO introduce check for sigio
+if(NOT DEFINED ${NO_SIGIO})
+  target_compile_definitions(
+    common INTERFACE HAVE_SIGIO_RT SIGINFO64_WORKAROUND
+  )
+endif()
+
+# TODO introduce check for futex
+if(NOT DEFINED ${USE_FUTEX})
+  target_compile_definitions(common INTERFACE USE_FUTEX)
+endif()

+ 41 - 0
cmake/os-specific/macos.cmake

@@ -0,0 +1,41 @@
+message(
+  STATUS
+    "Configuring for Darwin (Apple stationary operating systems (macOS, OS X, etc.)"
+)
+
+target_compile_definitions(
+  common
+  INTERFACE HAVE_SOCKADDR_SA_LEN
+            HAVE_GETHOSTBYNAME2
+            HAVE_UNION_SEMUN
+            HAVE_SCHED_YIELD
+            USE_ANON_MMAP
+            NDEBUG # NDEBUG used to turn off assert (assert wants to call
+            # eprintf which doesn't seem to be defined in any shared lib
+            HAVE_CONNECT_ECONNRESET_BUG
+            HAVE_TIMEGM
+            USE_SIGWAIT
+            HAVE_IP_MREQN
+)
+
+target_link_libraries(common INTERFACE resolv)
+
+message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
+if(NOT ${USE_FAST_LOCK})
+  target_compile_definitions(common INTERFACE USE_PTHREAD_MUTEX USE_SYSV_SEM)
+endif()
+
+set(CMAKE_MODULE_LINKER_FLAGS
+    "${CMAKE_MODULE_LINKER_FLAGS} -bundle -flat_namespace -undefined suppress"
+)
+set(CMAKE_SHARED_LINKER_FLAGS
+    "${CMAKE_SHARED_LINKER_FLAGS} -dynamiclib -flat_namespace -undefined suppress"
+)
+
+if(NOT DEFINED ${NO_SELECT})
+  target_compile_definitions(common INTERFACE HAVE_SELECT)
+endif()
+
+if(NOT DEFINED ${NO_KQUEUE})
+  target_compile_definitions(common INTERFACE HAVE_KQUEUE)
+endif()