Skip to content

Commit 72cf2e6

Browse files
authored
Changes to allow building as a static library and to set RPATH (#182)
* Changes to allow building as a static library and to set RPATH * Avoid redefinition warning on MacOS
1 parent 014970d commit 72cf2e6

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
Makefile
55
moc_*.cpp
66
*.pro.user*
7+
# CMake build directory
8+
build/

CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.16)
1+
cmake_minimum_required(VERSION 3.21)
22

33
project(SmtpMime
44
VERSION 2.0
@@ -13,22 +13,36 @@ set(CMAKE_AUTOUIC OFF)
1313
set(CMAKE_AUTOMOC ON)
1414
set(CMAKE_AUTORCC OFF)
1515

16-
find_package(QT NAMES Qt6 COMPONENTS Core Network REQUIRED)
17-
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network REQUIRED)
16+
find_package(QT NAMES Qt6 COMPONENTS Core Network Test REQUIRED)
17+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Test REQUIRED)
1818

1919
set(LIBRARY_TARGET_NAME ${PROJECT_NAME})
2020

21-
message(USING Qt${QT_VERSION_MAJOR})
21+
message("Using Qt" ${QT_VERSION_MAJOR})
22+
23+
#
24+
# Allow -DBUILD_SHARED_LIBS to control the library type built by qt_add_library
25+
#
26+
qt_policy(SET QTP0003 NEW)
27+
28+
#
29+
# Set the default for BUILD_SHARED_LIBS to ON, but allow command line
30+
# to override using -DBUILD_SHARED_LIBS=OFF
31+
#
32+
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
2233

23-
set(CMAKE_SKIP_BUILD_RPATH FALSE)
24-
#set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) # note: this breaks the demos
2534
set(CMAKE_INSTALL_RPATH $ORIGIN)
2635

36+
if(BUILD_SHARED_LIBS)
37+
add_compile_options(-DBUILD_SHARED_LIBS)
38+
endif()
39+
2740
add_subdirectory(src)
2841

2942
if (BUILD_TESTS)
3043
add_subdirectory(test)
3144
endif()
45+
3246
if (BUILD_DEMOS)
3347
add_subdirectory(demos)
3448
endif()

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
add_compile_options(-DSMTP_MIME_LIBRARY)
22

3-
qt_add_library(${LIBRARY_TARGET_NAME} SHARED
3+
qt_add_library(${LIBRARY_TARGET_NAME}
44
emailaddress.cpp
55
mimeattachment.cpp
66
mimebytearrayattachment.cpp
@@ -91,3 +91,4 @@ install(TARGETS ${LIBRARY_TARGET_NAME}
9191
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
9292
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/smtpmime
9393
)
94+

src/smtpmime_global.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#ifndef SMTPMIME_GLOBAL_H
22
#define SMTPMIME_GLOBAL_H
33

4-
#ifdef SMTP_MIME_LIBRARY
5-
#define SMTP_MIME_EXPORT Q_DECL_EXPORT
4+
#if defined(BUILD_SHARED_LIBS)
5+
# ifdef SMTP_MIME_LIBRARY
6+
# define SMTP_MIME_EXPORT Q_DECL_EXPORT
7+
# else
8+
# define SMTP_MIME_EXPORT Q_DECL_IMPORT
9+
# endif
610
#else
7-
#define SMTP_MIME_EXPORT Q_DECL_IMPORT
11+
# define SMTP_MIME_EXPORT
812
#endif
913

1014
#endif // SMTPMIME_GLOBAL_H

0 commit comments

Comments
 (0)