Skip to content

Commit c7203db

Browse files
committed
Fix support for MSVC
This commit brings MSVC support. CMake now checks for this compiler. You need MSVC Version 12.0 (VS2013) or later. I have also added the Macro ATTR_UNUSED. Clang does work with __attribute__ ((unused)) but MSVC doesn't. The macro ensures we use this feature only with gcc. Fixes #1 Signed-off-by: Christian Rapp <0x2a@posteo.org>
1 parent 3174d63 commit c7203db

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

include/qAccordion/clickableframe.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <QLabel>
2525
#include <QGraphicsView>
2626

27+
#include "config.h"
28+
2729
// TODO: No need to use a namespace for our constants as we are using them only
2830
// in this class
2931
namespace ClickableFrame_constants

include/qAccordion/config.h.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#define VERSION_MINOR "@qAccordion_VERSION_MINOR@"
2222
#define VERSION_PATCH "@qAccordion_VERSION_PATCH@"
2323

24-
//#cmakedefine
24+
#ifdef __GNUC__
25+
#define ATTR_UNUSED __attribute__((unused))
26+
#else
27+
#define ATTR_UNUSED
28+
#endif
2529

2630
#endif // CONFIG_H_IN

include/qAccordion/contentpane.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <memory>
3030

31+
#include "config.h"
3132
#include "clickableframe.h"
3233
#include "qaccordion.h"
3334

@@ -301,7 +302,7 @@ private slots:
301302
* @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets
302303
* @param event
303304
*/
304-
void paintEvent(__attribute__((unused)) QPaintEvent *event);
305+
void paintEvent(ATTR_UNUSED QPaintEvent *event);
305306
};
306307

307308
#endif // CONTENTPANE_H

include/qAccordion/qaccordion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private slots:
377377
* @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets
378378
* @param event
379379
*/
380-
void paintEvent(__attribute__((unused)) QPaintEvent *event);
380+
void paintEvent(ATTR_UNUSED QPaintEvent *event);
381381
};
382382

383383
#endif // QACCORDION_H

src/CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Initialize CXXFLAGS.
22
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")
3-
set(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0 -g -Wno-reorder") # No reorder warnings since this pop up frequently if you are using the Q_OBJECT macro
3+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") # No reorder warnings since this pop up frequently if you are using the Q_OBJECT macro
4+
if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
5+
# these flags really hurt msvc so we add them here
6+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra -Wno-reorder")
7+
endif(NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
48
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
59
set(CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
610
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
@@ -18,6 +22,27 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
1822
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
1923
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
2024
endif()
25+
elseif(WIN32)
26+
# So far only msvc is supported on Windows.
27+
if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
28+
message(
29+
ERROR
30+
"qAccordion does not support compiling on Windows with "
31+
"${CMAKE_CXX_COMPILER_ID}. Please use MSVC.")
32+
endif (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
33+
34+
# MSVC 1800 supports C++11; earlier versions don't. So, warn if you try to
35+
# use anything else.
36+
if (${MSVC_VERSION} LESS 1800)
37+
message(
38+
ERROR
39+
"qAccordion does not support compiling on MSVC versions earlier than 1800. "
40+
"Please use MSVC 1800 (included with Visual Studio 2013 or later).")
41+
endif (${MSVC_VERSION} LESS 1800)
42+
43+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
44+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
45+
2146
else ()
2247
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
2348
endif ()

src/clickableframe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ void ClickableFrame::mousePressEvent(QMouseEvent *event)
9999
}
100100
}
101101

102-
void ClickableFrame::enterEvent(__attribute__ ((unused)) QEvent *event)
102+
void ClickableFrame::enterEvent(ATTR_UNUSED QEvent *event)
103103
{
104104
if (this->clickable) {
105105
this->setStyleSheet(this->hoverStylesheet);
106106
}
107107
}
108108

109-
void ClickableFrame::leaveEvent(__attribute__ ((unused)) QEvent *event)
109+
void ClickableFrame::leaveEvent(ATTR_UNUSED QEvent *event)
110110
{
111111
if (this->clickable) {
112112
this->setStyleSheet(this->normalStylesheet);

src/contentpane.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ void ContentPane::initAnimations()
204204
QEasingCurve(QEasingCurve::Type::Linear));
205205
}
206206

207-
void ContentPane::headerClicked(__attribute__((unused)) QPoint pos) {
207+
void ContentPane::headerClicked(ATTR_UNUSED QPoint pos) {
208208
emit this->clicked();
209209
}
210210

211-
void ContentPane::paintEvent(__attribute__((unused)) QPaintEvent *event)
211+
void ContentPane::paintEvent(ATTR_UNUSED QPaintEvent *event)
212212
{
213213
QStyleOption o;
214214
o.initFrom(this);

src/qaccordion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void QAccordion::numberOfPanesChanged(int number)
410410
}
411411
}
412412

413-
void QAccordion::paintEvent(__attribute__((unused)) QPaintEvent *event)
413+
void QAccordion::paintEvent(ATTR_UNUSED QPaintEvent *event)
414414
{
415415
QStyleOption o;
416416
o.initFrom(this);

0 commit comments

Comments
 (0)