2
0
Эх сурвалжийг харах

cmake: Remove LOCK_METHOD as an option

- If USE_FAST_LOCK is set to ON, try to use FAST_LOCK. If not avalaible on platoform, fallback to a platform specific one.
- If USE_FAST_LOCK is set to OFF, fallback directly to platform specific one.
- Fix wrong IF(NOT <option>) evaluation
- CMake lint files
Xenofon Karamanos 7 сар өмнө
parent
commit
3cda5a83cc

+ 16 - 10
cmake/defs.cmake

@@ -137,6 +137,19 @@ endif()
 # -----------------------
 
 option(USE_FAST_LOCK "Use fast locking if available" ON)
+
+# TODO: Discuss if we need to expose this to the user to choose between
+# different locking methods
+
+# set(locking_methods FAST_LOCK USE_FUTEX USE_PTHREAD_MUTEX USE_POSIX_SEM
+#                     USE_SYSV_SEM)
+# set(LOCK_METHOD
+#     ""
+#     CACHE STRING "Locking method to use. Fast-lock if available is default")
+# # List of locking methods in option
+# set_property(CACHE LOCK_METHOD PROPERTY STRINGS ${locking_methods})
+# mark_as_advanced(LOCK_METHOD)
+
 # Fast-lock not available for all platforms like mips
 # Check the system processor type and set USE_FAST_LOCK accordingly
 if(USE_FAST_LOCK)
@@ -166,19 +179,14 @@ endif()
 # Add definitions if USE_FAST_LOCK is YES
 message(STATUS "Fast lock available: ${USE_FAST_LOCK}")
 if(USE_FAST_LOCK)
+  # If fast lock is available, add the definitions for it, else each OS will
+  # have its own locking method
   target_compile_definitions(common INTERFACE FAST_LOCK ADAPTIVE_WAIT
                                               ADAPTIVE_WAIT_LOOPS=1024)
 endif()
 
-# List of locking methods in option
-set(locking_methods USE_FUTEX USE_PTHREAD_MUTEX USE_POSIX_SEM USE_SYSV_SEM)
-set(LOCK_METHOD
-    USE_FUTEX
-    CACHE STRING "Locking method to use")
-set_property(CACHE LOCK_METHOD PROPERTY STRINGS ${locking_methods})
-
 # set(LOCKING_DEFINITION "${locking_method}")
-message(STATUS "Locking method: ${LOCK_METHOD}")
+# message(STATUS "Locking method: ${LOCK_METHOD}")
 
 # -----------------------
 # Setting all the flags from options
@@ -320,7 +328,6 @@ target_compile_definitions(
             # Absolute path this run is always /var/run/kamailio either for
             # local or system installs
             RUN_DIR="${RUN_PREFIX}/${RUN_DIR}"
-            ${LOCK_METHOD}
             # Module stuff?
             # PIC
             # TODO: We can use the generator expression to define extra flags
@@ -332,7 +339,6 @@ target_link_libraries(common INTERFACE common_compiler_flags)
 # -----------------------
 add_library(common_modules INTERFACE)
 target_compile_options(common_modules INTERFACE -fPIC)
-
 # TODO: Do we need all the option from common as well?
 target_link_libraries(common_modules INTERFACE common)
 

+ 5 - 7
cmake/os-specific/darwin.cmake

@@ -16,31 +16,29 @@ target_compile_definitions(
             HAVE_CONNECT_ECONNRESET_BUG
             HAVE_TIMEGM
             USE_SIGWAIT
-            HAVE_IP_MREQN
-)
+            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"
-)
+    "${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})
+if(NOT NO_SELECT)
   target_compile_definitions(common INTERFACE HAVE_SELECT)
 endif()
 
-if(NOT DEFINED ${NO_KQUEUE})
+if(NOT NO_KQUEUE)
   target_compile_definitions(common INTERFACE HAVE_KQUEUE)
 endif()
 
+# TODO: Chek if we need this in favor of GnuInstallDir alternative
 if(NOT DEFINED RUN_PREFIX)
   set(RUN_PREFIX "/var")
 endif()

+ 8 - 11
cmake/os-specific/dragonfly.cmake

@@ -10,37 +10,34 @@ target_compile_definitions(
             HAVE_ALLOCA_H
             HAVE_TIMEGM
             HAVE_SCHED_SETSCHEDULER
-            HAVE_IP_MREQN
-)
+            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"
-  )
+                                             "USE_PTHREAD_MUTEX")
     message(STATUS "Using ${LOCK_METHOD} for locks")
     target_link_libraries(common INTERFACE pthread)
   endif()
 
 endif()
 
-if(NOT DEFINED ${NO_SELECT})
+if(NOT NO_SELECT)
   target_compile_definitions(common INTERFACE HAVE_SELECT)
 endif()
 
-if(NOT DEFINED ${NO_EPOLL})
+if(NOT 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
-  )
+if(NOT NO_SIGIO_RT)
+  target_compile_definitions(common INTERFACE HAVE_SIGIO_RT
+                                              SIGINFO64_WORKAROUND)
 endif()

+ 4 - 9
cmake/os-specific/freebsd.cmake

@@ -1,7 +1,4 @@
-message(
-  STATUS
-    "Configuring for FreeBSD"
-)
+message(STATUS "Configuring for FreeBSD")
 
 target_compile_definitions(
   common
@@ -12,23 +9,21 @@ target_compile_definitions(
             HAVE_MSGHDR_MSG_CONTROL
             HAVE_CONNECT_ECONNRESET_BUG
             HAVE_TIMEGM
-            HAVE_IP_MREQN
-)
+            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)
 endif()
 
-if(NOT DEFINED ${NO_SELECT})
+if(NOT ${NO_SELECT})
   target_compile_definitions(common INTERFACE HAVE_SELECT)
 endif()
 
-if(NOT DEFINED ${NO_KQUEUE})
+if(NOT ${NO_KQUEUE})
   target_compile_definitions(common INTERFACE HAVE_KQUEUE)
 endif()
 

+ 17 - 19
cmake/os-specific/linux.cmake

@@ -10,44 +10,42 @@ target_compile_definitions(
             HAVE_ALLOCA_H
             HAVE_TIMEGM
             HAVE_SCHED_SETSCHEDULER
-            HAVE_IP_MREQN
-)
+            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)
+  message(
+    STATUS "FAST_LOCK not available on this platform, using: USE_PTHREAD_MUTEX")
 else()
+  # TODO: Check if this can be reached. Right now it is not possible to set
+  # LOCK_METHOD, only USE_FAST_LOCK. This branch is reached when USE_FAST_LOCK
+  # is set to true (meaning it is available on platform).
   # 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()
-
+  # 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})
+if(NOT NO_SELECT)
   target_compile_definitions(common INTERFACE HAVE_SELECT)
 endif()
 
 # TODO introduce check for epoll
-if(NOT DEFINED ${NO_EPOLL})
+if(NOT 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
-  )
+if(NOT NO_SIGIO_RT)
+  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()