Skip to content

Commit 6197911

Browse files
RookieCLYmergify[bot]
authored andcommitted
Support compiler MSYS2-MinGW (#5600)
* feature: support compiler MSYS2-MinGW #5575 Signed-off-by: RookieCLY <[email protected]> * feature: support compiler MSYS2-MinGW #5575 Signed-off-by: RookieCLY <[email protected]> * feature: support compiler MSYS2-MinGW and fix some format problem #5575 Signed-off-by: RookieCLY <[email protected]> --------- Signed-off-by: RookieCLY <[email protected]> (cherry picked from commit 28b11ca) # Conflicts: # include/fastdds/fastdds_dll.hpp # src/cpp/fastdds/xtypes/serializers/json/dynamic_data_json.cpp # src/cpp/utils/TimedConditionVariable.cpp
1 parent 657c521 commit 6197911

File tree

9 files changed

+1304
-4
lines changed

9 files changed

+1304
-4
lines changed

CMakeLists.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,26 @@ endif()
374374
###############################################################################
375375
# Tools default setup
376376
###############################################################################
377-
option(COMPILE_TOOLS "Build tools" ON)
377+
if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
378+
execute_process(
379+
COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
380+
OUTPUT_VARIABLE COMPILER_MACHINE
381+
OUTPUT_STRIP_TRAILING_WHITESPACE
382+
)
383+
if(COMPILER_MACHINE MATCHES "mingw")
384+
message(STATUS "Using MinGW compiler.")
385+
option(COMPILE_TOOLS "Build tools" OFF)
386+
add_definitions(-DMINGW_COMPILER=1)
387+
set(CMAKE_CXX_FLAGS
388+
"${CMAKE_CXX_FLAGS} -Wno-attributes -Wno-stringop-overread -Wno-builtin-macro-redefined -Wno-cast-function-type -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-missing-field-initializers")
389+
target_link_libraries(fastdds PUBLIC ws2_32 mswsock)
390+
else()
391+
message(STATUS "Using a GNU compiler on Windows but not MinGW.")
392+
endif()
393+
else()
394+
message(STATUS "Not using a GNU compiler on Windows.")
395+
option(COMPILE_TOOLS "Build tools" ON)
396+
endif()
378397

379398
if(EPROSIMA_BUILD)
380399
set(COMPILE_TOOLS ON)

include/fastdds/fastdds_dll.hpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file fastdds_dll.hpp
17+
*
18+
*/
19+
20+
#ifndef FASTDDS_FASTDDS_DLL_H
21+
#define FASTDDS_FASTDDS_DLL_H
22+
23+
#include <fastdds/config.hpp>
24+
25+
// normalize macros
26+
#if !defined(FASTDDS_DYN_LINK) && !defined(FASTDDS_STATIC_LINK) \
27+
&& !defined(EPROSIMA_ALL_DYN_LINK) && !defined(EPROSIMA_ALL_STATIC_LINK)
28+
#define FASTDDS_STATIC_LINK
29+
#endif // if !defined(FASTDDS_DYN_LINK) && !defined(FASTDDS_STATIC_LINK) && !defined(EPROSIMA_ALL_DYN_LINK) && !defined(EPROSIMA_ALL_STATIC_LINK)
30+
31+
#if defined(EPROSIMA_ALL_DYN_LINK) && !defined(FASTDDS_DYN_LINK)
32+
#define FASTDDS_DYN_LINK
33+
#endif // if defined(EPROSIMA_ALL_DYN_LINK) && !defined(FASTDDS_DYN_LINK)
34+
35+
#if defined(FASTDDS_DYN_LINK) && defined(FASTDDS_STATIC_LINK)
36+
#error Must not define both FASTDDS_DYN_LINK and FASTDDS_STATIC_LINK
37+
#endif // if defined(FASTDDS_DYN_LINK) && defined(FASTDDS_STATIC_LINK)
38+
39+
#if defined(EPROSIMA_ALL_NO_LIB) && !defined(FASTDDS_NO_LIB)
40+
#define FASTDDS_NO_LIB
41+
#endif // if defined(EPROSIMA_ALL_NO_LIB) && !defined(FASTDDS_NO_LIB)
42+
43+
// enable dynamic linking
44+
45+
#if defined(_WIN32)
46+
#if defined(EPROSIMA_ALL_DYN_LINK) || defined(FASTDDS_DYN_LINK)
47+
#if defined(MINGW_COMPILER)
48+
#if defined(fastdds_EXPORTS)
49+
#define FASTDDS_EXPORTED_API __declspec( dllexport )
50+
#else
51+
#define FASTDDS_EXPORTED_API __attribute__((visibility("default")))
52+
#endif // FASTDDS_SOURCE
53+
#else
54+
#if defined(fastdds_EXPORTS)
55+
#define FASTDDS_EXPORTED_API __declspec( dllexport )
56+
#else
57+
#define FASTDDS_EXPORTED_API __declspec( dllimport )
58+
#endif // FASTDDS_SOURCE
59+
#endif // if defined(MINGW_COMPILER)
60+
#else
61+
#define FASTDDS_EXPORTED_API
62+
#endif // if defined(EPROSIMA_ALL_DYN_LINK) || defined(FASTDDS_DYN_LINK)
63+
#else
64+
#define FASTDDS_EXPORTED_API
65+
#endif // _WIN32
66+
67+
// Auto linking.
68+
69+
#if !defined(FASTDDS_SOURCE) && !defined(EPROSIMA_ALL_NO_LIB) \
70+
&& !defined(FASTDDS_NO_LIB)
71+
72+
// Set properties.
73+
#define EPROSIMA_LIB_NAME fastdds
74+
75+
#if defined(EPROSIMA_ALL_DYN_LINK) || defined(FASTDDS_DYN_LINK)
76+
#define EPROSIMA_DYN_LINK
77+
#endif // if defined(EPROSIMA_ALL_DYN_LINK) || defined(FASTDDS_DYN_LINK)
78+
79+
#include <fastdds/fastdds_auto_link.hpp>
80+
#endif // auto-linking disabled
81+
82+
#endif // FASTDDS_FASTDDS_DLL_H

include/fastrtps/utils/TimedMutex.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528
2828
#include <mutex>
29+
#elif defined(MINGW_COMPILER)
30+
#include <mutex>
2931
#else
3032
#include <thread>
3133
extern int clock_gettime(
@@ -47,6 +49,9 @@ namespace fastrtps {
4749
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 193632528
4850
using TimedMutex = std::timed_mutex;
4951
using RecursiveTimedMutex = std::recursive_timed_mutex;
52+
#elif defined(MINGW_COMPILER)
53+
using TimedMutex = std::timed_mutex;
54+
using RecursiveTimedMutex = std::recursive_timed_mutex;
5055
#else
5156
class TimedMutex
5257
{

0 commit comments

Comments
 (0)