Skip to content

Commit 027eaf8

Browse files
committed
Exporting Functions for Windows Library
We did not export any of your functions. This is important on Windows, otherwise no *.lib gets build and you can't use the library. This was fixed by using GenerateExportHeader module from cmake. CMake defines a macro that you can use to export functions. Signed-off-by: Christian Rapp <0x2a@posteo.org>
1 parent c7203db commit 027eaf8

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

include/qAccordion/clickableframe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QGraphicsView>
2626

2727
#include "config.h"
28+
#include "qaccordion_export.h"
2829

2930
// TODO: No need to use a namespace for our constants as we are using them only
3031
// in this class
@@ -40,7 +41,7 @@ const char *const CARRET_ICON_OPENED = ":/qAccordionIcons/caret-bottom.png"; /**
4041
* This class represents a clickable QFrame. It is used by a ContentPane. The class
4142
* is used internally.
4243
*/
43-
class ClickableFrame : public QFrame
44+
class QACCORDION_EXPORT ClickableFrame : public QFrame
4445
{
4546

4647
Q_OBJECT

include/qAccordion/contentpane.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
#include <memory>
3030

3131
#include "config.h"
32+
#include "qaccordion_export.h"
3233
#include "clickableframe.h"
3334
#include "qaccordion.h"
3435

36+
// TODO: Do i really need to export the ClickableFrame class?
3537
/**
3638
* @brief Content Pane class
3739
*
@@ -61,7 +63,7 @@
6163
* @details
6264
* The animation speed is influenceable setAnimationDuration().
6365
*/
64-
class ContentPane : public QWidget
66+
class QACCORDION_EXPORT ContentPane : public QWidget
6567
{
6668
Q_OBJECT
6769
public:

include/qAccordion/qaccordion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <iterator>
3434

3535
#include "config.h"
36+
#include "qaccordion_export.h"
3637
#include "contentpane.h"
3738

3839
class ContentPane;
@@ -64,7 +65,7 @@ class ContentPane;
6465
* Currently Headers have to be unique
6566
*
6667
*/
67-
class QAccordion : public QWidget
68+
class QACCORDION_EXPORT QAccordion : public QWidget
6869
{
6970
Q_OBJECT
7071
public:

src/CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
1010
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
1111

1212
# Compiler-specific C++11 activation.
13-
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
13+
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
1414
execute_process(
1515
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
1616
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
1717
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
1818
endif ()
19-
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
19+
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
2020
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2121
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
2222
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
2323
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
2424
endif()
2525
elseif(WIN32)
2626
# So far only msvc is supported on Windows.
27-
if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
27+
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
2828
message(
2929
ERROR
3030
"qAccordion does not support compiling on Windows with "
3131
"${CMAKE_CXX_COMPILER_ID}. Please use MSVC.")
32-
endif (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
32+
endif (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
3333

3434
# MSVC 1800 supports C++11; earlier versions don't. So, warn if you try to
3535
# use anything else.
@@ -47,6 +47,9 @@ else ()
4747
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
4848
endif ()
4949

50+
# include GenerateExportHeader module
51+
include(GenerateExportHeader)
52+
5053
# Find includes in corresponding build directories
5154
set(CMAKE_INCLUDE_CURRENT_DIR ON)
5255
# Instruct CMake to run moc automatically when needed.
@@ -62,12 +65,8 @@ else ()
6265
set(base_path ${CMAKE_SOURCE_DIR})
6366
endif()
6467

65-
message(STATUS "base path: ${base_path}")
66-
67-
68-
# include this directories so all moc headers and wrapped ui files are found
6968
include_directories(
70-
${PROJECT_BINARY_DIR}
69+
${PROJECT_BINARY_DIR} # include this directory so all moc headers and wrapped ui files are found
7170
${base_path}/include
7271
)
7372

@@ -88,9 +87,13 @@ set(QACCORDION_ICON_RESOURCE "${base_path}/icons/qaccordionicons.qrc")
8887
# add resource files so they can be compiled into the binary
8988
qt5_add_resources(ICON_RESOURCE_ADDED ${QACCORDION_ICON_RESOURCE})
9089

90+
# we are building a shared library
9191
add_library (qAccordion SHARED ${QACCORDION_HEADER} ${QACCORDION_SOURCE} ${ICON_RESOURCE_ADDED})
9292
target_link_libraries(qAccordion Qt5::Widgets)
9393

94+
# generate the export header. this will be used to define a macro that exports functions on windows.
95+
generate_export_header(qAccordion)
96+
9497
if (QACCORDION_BUILD_TESTER)
9598
# generate ui_*.h files
9699
qt5_wrap_ui(accordion_tester_FORMS ${TEST_UI})
@@ -104,3 +107,4 @@ install(FILES ${base_path}/include/qAccordion/clickableframe.h DESTINATION inclu
104107
install(FILES ${base_path}/include/qAccordion/contentpane.h DESTINATION include/qAccordion)
105108
install(FILES ${base_path}/include/qAccordion/qaccordion.h DESTINATION include/qAccordion)
106109
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/qAccordion)
110+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qaccordion_export.h DESTINATION include/qAccordion)

0 commit comments

Comments
 (0)