From 5861516316ce64d40f0ed5288ffe6a73f98f014a Mon Sep 17 00:00:00 2001 From: Wander Lairson Costa Date: Wed, 12 Aug 2020 14:49:44 -0300 Subject: [PATCH] Clean up the code to build successfully on macOS This commit does some code cleanup to successfully build dali-core in macOS using the Apple provided clang compiler. The clang version shipped with macOS doesn't have the -Wno-class-memaccess and the -Wno-cast-function-type switches, so we test their existence before adding them to the compiler options. Mutex now has move constructor and assigment operator, so classes with mutexes members can use their defaults move operations. Classes holding references cannot have a default move assigment operator. Virtual functions overriding parent classes are now declared with the `override` keyword. MAXIMUM_TIME_DIFF_ALLOWED is a global internal variable nerver used, so it was removed. .gitignore was updated to include some artifacts from coc-nvim extension. Change-Id: I76201f867240a0822e7e202c2edcbfa07b2dffd6 --- .gitignore | 2 ++ automated-tests/src/dali/utc-Dali-Mutex.cpp | 15 +++++++++++++++ build/tizen/CMakeLists.txt | 19 +++++++++++++++++-- dali/devel-api/threading/mutex.cpp | 18 ++++++++++++++++++ dali/devel-api/threading/mutex.h | 10 ++++++++++ dali/internal/event/common/property-input-impl.h | 2 +- .../events/pan-gesture/pan-gesture-detector-impl.h | 2 +- .../events/pan-gesture/pan-gesture-recognizer.cpp | 1 - dali/internal/event/events/ray-test.h | 4 ++-- dali/internal/event/rendering/vertex-buffer-impl.cpp | 2 +- .../update/manager/frame-callback-processor.h | 2 +- dali/internal/update/manager/update-proxy-impl.h | 2 +- 12 files changed, 69 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2912c11..56258a1 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ libdali2-core.so* /packaging/home* compile_commands.json file-list.cmake +compile_commands.json +.clangd diff --git a/automated-tests/src/dali/utc-Dali-Mutex.cpp b/automated-tests/src/dali/utc-Dali-Mutex.cpp index edbd1cc..a15d26f 100644 --- a/automated-tests/src/dali/utc-Dali-Mutex.cpp +++ b/automated-tests/src/dali/utc-Dali-Mutex.cpp @@ -24,6 +24,7 @@ #include #include +#include using Dali::Mutex; using Dali::Thread; @@ -49,6 +50,20 @@ int UtcDaliMutexSingleThread(void) } DALI_TEST_EQUALS(false, mutex3.IsLocked(), TEST_LOCATION); + { + Mutex mutex4; + Mutex mutex5(std::move(mutex4)); // move constructor + Mutex::ScopedLock lock(mutex5); + DALI_TEST_EQUALS(true, mutex5.IsLocked(), TEST_LOCATION); + } + + { + Mutex mutex4, mutex5; + mutex5 = std::move(mutex4); // move assignment + Mutex::ScopedLock lock(mutex5); + DALI_TEST_EQUALS(true, mutex5.IsLocked(), TEST_LOCATION); + } + END_TEST; } diff --git a/build/tizen/CMakeLists.txt b/build/tizen/CMakeLists.txt index f174d4c..eb890c2 100644 --- a/build/tizen/CMakeLists.txt +++ b/build/tizen/CMakeLists.txt @@ -140,6 +140,8 @@ IF( WIN32 ) # WIN32 includes x64 as well according to the cmake doc. ELSEIF( UNIX ) + INCLUDE(CheckCXXCompilerFlag) + # Set up compiler flags and warnings ADD_COMPILE_OPTIONS( -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast ) @@ -149,8 +151,21 @@ ELSEIF( UNIX ) ADD_COMPILE_OPTIONS( -Werror ) ENDIF() - ADD_COMPILE_OPTIONS( -Wall -Wextra -Wno-unused-parameter -Wfloat-equal -Wno-class-memaccess -Wno-cast-function-type ) + ADD_COMPILE_OPTIONS( -Wall -Wextra -Wno-unused-parameter -Wfloat-equal ) + CHECK_CXX_COMPILER_FLAG(-Wno-class-memaccess HAVE_NO_CLASS_MEMACCESS) + IF (HAVE_NO_CLASS_MEMACCESS) + ADD_COMPILE_OPTIONS( -Wno-class-memaccess ) + ENDIF() + + CHECK_CXX_COMPILER_FLAG(-Wno-cast-function-type HAVE_NO_CAST_FUNCTION_TYPE) + IF (HAVE_NO_CAST_FUNCTION_TYPE) + ADD_COMPILE_OPTIONS( -Wno-cast-function-type ) + ENDIF() + CHECK_CXX_COMPILER_FLAG(-Wno-string-plus-int HAVE_NO_STRING_PLUS_INT) + IF (HAVE_NO_STRING_PLUS_INT) + ADD_COMPILE_OPTIONS( -Wno-string-plus-int ) + ENDIF() IF( ENABLE_COVERAGE OR "$ENV{CXXFLAGS}" MATCHES --coverage ) ADD_COMPILE_OPTIONS( --coverage ) SET(ENABLE_COVERAGE ON) @@ -245,7 +260,7 @@ IF( INSTALL_CMAKE_MODULES ) INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-config.cmake DESTINATION share/${name} ) # Install the pdb file. - IF( ENABLE_DEBUG ) + IF( ENABLE_DEBUG AND WIN32 ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/${name}.pdb DESTINATION ${BIN_DIR} ) ENDIF() ELSE() diff --git a/dali/devel-api/threading/mutex.cpp b/dali/devel-api/threading/mutex.cpp index 31c29b3..f8580de 100644 --- a/dali/devel-api/threading/mutex.cpp +++ b/dali/devel-api/threading/mutex.cpp @@ -46,6 +46,24 @@ Mutex::~Mutex() delete mImpl; } +Mutex::Mutex(Mutex&& rhs) noexcept + : mImpl(rhs.mImpl) +{ + rhs.mImpl = nullptr; +} + +Mutex &Mutex::operator=(Mutex&& rhs) noexcept +{ + if (mImpl != rhs.mImpl) + { + delete mImpl; + mImpl = rhs.mImpl; + rhs.mImpl = nullptr; + } + + return *this; +} + bool Mutex::IsLocked() { return mImpl->locked; diff --git a/dali/devel-api/threading/mutex.h b/dali/devel-api/threading/mutex.h index b829b8b..925f363 100644 --- a/dali/devel-api/threading/mutex.h +++ b/dali/devel-api/threading/mutex.h @@ -43,6 +43,16 @@ public: ~Mutex(); /** + * @brief Move constructor + */ + Mutex(Mutex&& rhs) noexcept; + + /** + * @brief Move assignment + */ + Mutex &operator=(Mutex&& rhs) noexcept; + + /** * @brief Check if the mutex is locked * @return true if the mutex is locked */ diff --git a/dali/internal/event/common/property-input-impl.h b/dali/internal/event/common/property-input-impl.h index bd8d4ec..e1e307d 100644 --- a/dali/internal/event/common/property-input-impl.h +++ b/dali/internal/event/common/property-input-impl.h @@ -31,7 +31,7 @@ #include #include -#if defined (ANDROID) || defined(WIN32) +#if defined (ANDROID) || defined(WIN32) || defined(__APPLE__) namespace std { diff --git a/dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h b/dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h index a818fc2..db979c4 100644 --- a/dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h +++ b/dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h @@ -28,7 +28,7 @@ namespace Dali { -struct TouchEvent; +class TouchEvent; struct Radian; namespace Internal diff --git a/dali/internal/event/events/pan-gesture/pan-gesture-recognizer.cpp b/dali/internal/event/events/pan-gesture/pan-gesture-recognizer.cpp index be9b307..5b61546 100644 --- a/dali/internal/event/events/pan-gesture/pan-gesture-recognizer.cpp +++ b/dali/internal/event/events/pan-gesture/pan-gesture-recognizer.cpp @@ -40,7 +40,6 @@ namespace const float MINIMUM_MOTION_DISTANCE_BEFORE_PAN( 15.0f ); const float MINIMUM_MOTION_DISTANCE_BEFORE_PAN_SQUARED( MINIMUM_MOTION_DISTANCE_BEFORE_PAN * MINIMUM_MOTION_DISTANCE_BEFORE_PAN ); const float MINIMUM_MOTION_DISTANCE_TO_THRESHOLD_ADJUSTMENTS_RATIO( 2.0f / 3.0f ); -const unsigned long MAXIMUM_TIME_DIFF_ALLOWED( 500 ); const unsigned long MINIMUM_TIME_BEFORE_THRESHOLD_ADJUSTMENTS( 100 ); const unsigned int MINIMUM_MOTION_EVENTS_BEFORE_PAN(2); } // unnamed namespace diff --git a/dali/internal/event/events/ray-test.h b/dali/internal/event/events/ray-test.h index 660d4e0..7190989 100644 --- a/dali/internal/event/events/ray-test.h +++ b/dali/internal/event/events/ray-test.h @@ -24,8 +24,8 @@ namespace Dali { -class Vector2; -class Vector4; +struct Vector2; +struct Vector4; namespace Internal { diff --git a/dali/internal/event/rendering/vertex-buffer-impl.cpp b/dali/internal/event/rendering/vertex-buffer-impl.cpp index 84f7f18..9d131c7 100644 --- a/dali/internal/event/rendering/vertex-buffer-impl.cpp +++ b/dali/internal/event/rendering/vertex-buffer-impl.cpp @@ -22,7 +22,7 @@ #include #include -#if defined (ANDROID) || defined(WIN32) +#if defined (ANDROID) || defined(WIN32) || defined(__APPLE__) namespace std { uint64_t _Hash_bytes(const void* bytes, uint64_t size, uint64_t seed) diff --git a/dali/internal/update/manager/frame-callback-processor.h b/dali/internal/update/manager/frame-callback-processor.h index 09f4acd..2c27d8b 100644 --- a/dali/internal/update/manager/frame-callback-processor.h +++ b/dali/internal/update/manager/frame-callback-processor.h @@ -67,7 +67,7 @@ public: FrameCallbackProcessor( const FrameCallbackProcessor& ) = delete; ///< Deleted copy constructor. FrameCallbackProcessor( FrameCallbackProcessor&& ) = default; ///< Default move constructor. FrameCallbackProcessor& operator=( const FrameCallbackProcessor& ) = delete; ///< Deleted copy assignment operator. - FrameCallbackProcessor& operator=( FrameCallbackProcessor&& ) = default; ///< Default move assignment operator. + FrameCallbackProcessor& operator=( FrameCallbackProcessor&& ) = delete; ///< Deleted move assignment operator. /** * Adds an implementation of the FrameCallbackInterface. diff --git a/dali/internal/update/manager/update-proxy-impl.h b/dali/internal/update/manager/update-proxy-impl.h index 88fefbb..ac9c4a9 100644 --- a/dali/internal/update/manager/update-proxy-impl.h +++ b/dali/internal/update/manager/update-proxy-impl.h @@ -70,7 +70,7 @@ public: UpdateProxy( const UpdateProxy& ) = delete; ///< Deleted copy constructor. UpdateProxy( UpdateProxy&& ) = default; ///< Default move constructor. UpdateProxy& operator=( const UpdateProxy& ) = delete; ///< Deleted copy assignment operator. - UpdateProxy& operator=( UpdateProxy&& ) = default; ///< Default move assignment operator. + UpdateProxy& operator=( UpdateProxy&& ) = delete; ///< Deleted move assignment operator. /** * @copydoc Dali::UpdateProxy::GetPosition() -- 2.7.4