Browse Source

Enable GCC/Clang support for multithreading with pthread library.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
d29d5f188e
1 changed files with 6 additions and 6 deletions
  1. 6 6
      CMake/Modules/Urho3D-CMake-common.cmake

+ 6 - 6
CMake/Modules/Urho3D-CMake-common.cmake

@@ -499,6 +499,10 @@ else ()
             # Reduce GCC optimization level from -O3 to -O2 for stability in RELEASE build configuration
             # Reduce GCC optimization level from -O3 to -O2 for stability in RELEASE build configuration
             set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
+        else ()
+            # Not Android and not Emscripten and not MinGW derivative
+            set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")     # This will emit '-DREENTRANT' to compiler and '-lpthread' to linker on Linux and Mac OSX platform
+            set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") # However, it may emit other equivalent compiler define and/or linker flag on other *nix platforms
         endif ()
         endif ()
         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
@@ -1201,13 +1205,13 @@ macro (define_dependency_libs TARGET)
         if (WIN32)
         if (WIN32)
             list (APPEND LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
             list (APPEND LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
         elseif (APPLE)
         elseif (APPLE)
-            list (APPEND LIBS dl pthread)
+            list (APPEND LIBS dl)
         elseif (ANDROID)
         elseif (ANDROID)
             list (APPEND LIBS dl log android)
             list (APPEND LIBS dl log android)
         else ()
         else ()
             # Linux
             # Linux
             if (NOT EMSCRIPTEN)
             if (NOT EMSCRIPTEN)
-                list (APPEND LIBS dl pthread rt)
+                list (APPEND LIBS dl rt)
             endif ()
             endif ()
             if (RPI)
             if (RPI)
                 list (APPEND ABSOLUTE_PATH_LIBS ${BCM_VC_LIBRARIES})
                 list (APPEND ABSOLUTE_PATH_LIBS ${BCM_VC_LIBRARIES})
@@ -1219,8 +1223,6 @@ macro (define_dependency_libs TARGET)
     if (${TARGET} MATCHES Civetweb|kNet|Urho3D)
     if (${TARGET} MATCHES Civetweb|kNet|Urho3D)
         if (WIN32)
         if (WIN32)
             list (APPEND LIBS ws2_32)
             list (APPEND LIBS ws2_32)
-        elseif (NOT ANDROID AND NOT EMSCRIPTEN)
-            list (APPEND LIBS pthread)
         endif ()
         endif ()
     endif ()
     endif ()
 
 
@@ -1239,8 +1241,6 @@ macro (define_dependency_libs TARGET)
             if (URHO3D_MINIDUMPS)
             if (URHO3D_MINIDUMPS)
                 list (APPEND LIBS dbghelp)
                 list (APPEND LIBS dbghelp)
             endif ()
             endif ()
-        elseif (NOT ANDROID AND NOT EMSCRIPTEN)
-            list (APPEND LIBS pthread)
         endif ()
         endif ()
 
 
         # Graphics
         # Graphics