Skip to content

Commit ed74c05

Browse files
authored
Merge pull request #36 from jeremydumais/FixStaticBuild
Fix static build - Version 1.1.9
2 parents 5b6e063 + c159674 commit ed74c05

28 files changed

+184
-40
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file
44

5+
## [1.1.9]
6+
7+
## Enhancement / Bug fixes
8+
- Rework the build system to support static build and to generate correct
9+
release version.
10+
- The build configuration now works with multi-config generators like Visual
11+
Studio
12+
- The default build configurations in Visual Studio has been changed to :
13+
- x64-Debug
14+
- x64-Debug-Static
15+
- x64-Debug-WithUnitTests
16+
- x64-Release
17+
- x64-Release-Static
18+
- x64-Release-WithUnitTests
19+
520
## [1.1.8]
621

722
## Enhancement / Bug fixes

CMakeLists.txt

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
4-
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
5-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
6-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
7-
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
3+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4+
5+
# For multi-config generators like Visual Studio, set per-config output dir
6+
foreach(OUTPUTCONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
7+
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
8+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG})
9+
endforeach()
810
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
911

1012
project(SMTPClient C CXX)
1113

14+
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
15+
16+
1217
# Set project name
1318
set(PROJECT_NAME "smtpclient")
1419
set(PROJECT_UNITTEST_NAME "smtpclient_unittests")
@@ -119,7 +124,7 @@ if (WIN32)
119124
ICON "${PATH_TO_APPLICATION_ICON}"
120125
VERSION_MAJOR 1
121126
VERSION_MINOR 1
122-
VERSION_PATCH 7
127+
VERSION_PATCH 9
123128
VERSION_REVISION ${BUILD_REVISION}
124129
)
125130
endif()
@@ -146,15 +151,23 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
146151
message(STATUS "Will use OpenSSL lib directory ${OPENSSL_LIBRARY_DIRECTORY}")
147152
link_directories(${OPENSSL_LIBRARY_DIRECTORY})
148153
message(STATUS "Will use OpenSSL libraries files ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY}")
149-
add_library(${PROJECT_NAME} SHARED
154+
add_library(${PROJECT_NAME}
150155
${PROJECT_SOURCE_FILES} ${VersionFilesOutputVariable})
156+
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
151157
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
152158
add_compile_options(/EHsc)
153159
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /WX)
154-
target_compile_definitions(${PROJECT_NAME}
155-
PRIVATE SMTPCLIENT_EXPORTS
156-
INTERFACE NOMINMAX # avoid Win macro definition of min/max, use std one
157-
INTERFACE _SCL_SECURE_NO_WARNINGS) # disable security-paranoia warning
160+
if(${BUILD_SHARED_LIBS})
161+
target_compile_definitions(${PROJECT_NAME}
162+
PRIVATE SMTPCLIENT_EXPORTS
163+
INTERFACE NOMINMAX # avoid Win macro definition of min/max, use std one
164+
INTERFACE _SCL_SECURE_NO_WARNINGS) # disable security-paranoia warning
165+
else()
166+
target_compile_definitions(${PROJECT_NAME}
167+
PRIVATE SMTPCLIENT_STATIC
168+
INTERFACE NOMINMAX # avoid Win macro definition of min/max, use std one
169+
INTERFACE _SCL_SECURE_NO_WARNINGS) # disable security-paranoia warning
170+
endif()
158171
target_link_libraries(${PROJECT_NAME} Ws2_32 ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} crypt32 cryptui)
159172
else()
160173
#For other compiler create the library as a static library
@@ -254,7 +267,9 @@ if (BUILD_TESTING)
254267
${TEST_SRC_PATH}/smtpclient_unittest.cpp
255268
${TEST_SRC_PATH}/serveroptionsanalyzer_unittest.cpp
256269
${TEST_SRC_PATH}/errorresolver_unittest.cpp)
257-
270+
if(DEFINED BUILD_SHARED_LIBS AND NOT BUILD_SHARED_LIBS)
271+
target_compile_definitions(${PROJECT_UNITTEST_NAME} PRIVATE SMTPCLIENT_STATIC)
272+
endif()
258273
target_link_libraries(${PROJECT_UNITTEST_NAME} ${PROJECT_NAME} gtest gtest_main ${PTHREAD})
259274
gtest_discover_tests(${PROJECT_UNITTEST_NAME})
260275
endif()
@@ -272,6 +287,7 @@ ADD_CUSTOM_TARGET(uninstall
272287
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/CMakeUninstall.cmake")
273288

274289
if(EXISTS ${PROJECT_PATH}/simpleclient AND IS_DIRECTORY ${PROJECT_PATH}/simpleclient)
290+
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
275291
add_subdirectory(${PROJECT_PATH}/simpleclient)
276292
endif()
277293

CMakeSettings.json

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
// See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
32
"configurations": [
43
{
54
"name": "x64-Debug",
@@ -11,6 +10,62 @@
1110
"cmakeCommandArgs": "",
1211
"buildCommandArgs": "-v",
1312
"ctestCommandArgs": ""
13+
},
14+
{
15+
"name": "x64-Release",
16+
"generator": "Ninja",
17+
"configurationType": "Release",
18+
"buildRoot": "${projectDir}\\out\\build\\${name}",
19+
"installRoot": "${projectDir}\\out\\install\\${name}",
20+
"cmakeCommandArgs": "",
21+
"buildCommandArgs": "-v",
22+
"ctestCommandArgs": "",
23+
"inheritEnvironments": [ "msvc_x64_x64" ]
24+
},
25+
{
26+
"name": "x64-Debug-WithUnitTests",
27+
"generator": "Ninja",
28+
"configurationType": "Debug",
29+
"buildRoot": "${projectDir}\\out\\build\\${name}",
30+
"installRoot": "${projectDir}\\out\\install\\${name}",
31+
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
32+
"buildCommandArgs": "-v",
33+
"ctestCommandArgs": "",
34+
"inheritEnvironments": [ "msvc_x64_x64" ]
35+
},
36+
{
37+
"name": "x64-Release-WithUnitTests",
38+
"generator": "Ninja",
39+
"configurationType": "Release",
40+
"buildRoot": "${projectDir}\\out\\build\\${name}",
41+
"installRoot": "${projectDir}\\out\\install\\${name}",
42+
"cmakeCommandArgs": "-DBUILD_TESTING=ON",
43+
"buildCommandArgs": "-v",
44+
"ctestCommandArgs": "",
45+
"inheritEnvironments": [ "msvc_x64_x64" ]
46+
},
47+
{
48+
"name": "x64-Debug-Static",
49+
"generator": "Ninja",
50+
"configurationType": "Debug",
51+
"buildRoot": "${projectDir}\\out\\build\\${name}",
52+
"installRoot": "${projectDir}\\out\\install\\${name}",
53+
"cmakeCommandArgs": "-DBUILD_SHARED_LIBS=OFF",
54+
"buildCommandArgs": "-v",
55+
"ctestCommandArgs": "",
56+
"inheritEnvironments": [ "msvc_x64_x64" ]
57+
},
58+
{
59+
"name": "x64-Release-Static",
60+
"generator": "Ninja",
61+
"configurationType": "Release",
62+
"buildRoot": "${projectDir}\\out\\build\\${name}",
63+
"installRoot": "${projectDir}\\out\\install\\${name}",
64+
"cmakeCommandArgs": "-DBUILD_SHARED_LIBS=OFF",
65+
"buildCommandArgs": "-v",
66+
"ctestCommandArgs": "",
67+
"inheritEnvironments": [ "msvc_x64_x64" ],
68+
"variables": []
1469
}
1570
]
1671
}

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Jed# C++ SMTP Client Library
22

33
[![Build status](https://github.com/jeremydumais/CPP-SMTPClient-library/actions/workflows/cmake.yml/badge.svg)](https://github.com/jeremydumais/CPP-SMTPClient-library/actions/workflows/cmake.yml)
4-
![Latest version](https://img.shields.io/badge/latest_version-1.1.8-brightgreen)
4+
![Latest version](https://img.shields.io/badge/latest_version-1.1.9-brightgreen)
55
![Dependencies](https://img.shields.io/badge/dependencies-openssl-brightgreen)
66

77
## A simple SMTP client library built in C++ that support authentication and secure connections (Opportunistic SSL/TLS and Forced SSL encryption).
@@ -109,6 +109,19 @@ for previous versions.
109109

110110
## 📰 What's new
111111

112+
113+
- Version 1.1.9:
114+
- Rework the build system to support static build and to generate correct
115+
release version.
116+
- The build configuration now works with multi-config generators like Visual
117+
Studio
118+
- The default build configurations in Visual Studio has been changed to :
119+
- x64-Debug
120+
- x64-Debug-Static
121+
- x64-Debug-WithUnitTests
122+
- x64-Release
123+
- x64-Release-Static
124+
- x64-Release-WithUnitTests
112125
- Version 1.1.8:
113126
- Some SMTP server send their list of supported extensions in multiple
114127
buffers like Zoho Mail. The EHLO command when in uncrypted mode, now supports

src/attachment.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include "base64.h"
77

88
#ifdef _WIN32
9-
#ifdef SMTPCLIENT_EXPORTS
9+
#ifdef SMTPCLIENT_STATIC
10+
#define ATTACHMENT_API
11+
#elif defined(SMTPCLIENT_EXPORTS)
1012
#define ATTACHMENT_API __declspec(dllexport)
1113
#else
1214
#define ATTACHMENT_API __declspec(dllimport)

src/cpp/attachment.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "../base64.h"
88

99
#ifdef _WIN32
10-
#ifdef SMTPCLIENT_EXPORTS
10+
#ifdef SMTPCLIENT_STATIC
11+
#define CPP_ATTACHMENT_API
12+
#elif defined(SMTPCLIENT_EXPORTS)
1113
#define CPP_ATTACHMENT_API __declspec(dllexport)
1214
#else
1315
#define CPP_ATTACHMENT_API __declspec(dllimport)

src/cpp/credential.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define CPPCREDENTIAL_H
33

44
#ifdef _WIN32
5-
#ifdef SMTPCLIENT_EXPORTS
5+
#ifdef SMTPCLIENT_STATIC
6+
#define CPP_CREDENTIAL_API
7+
#elif defined(SMTPCLIENT_EXPORTS)
68
#define CPP_CREDENTIAL_API __declspec(dllexport)
79
#else
810
#define CPP_CREDENTIAL_API __declspec(dllimport)

src/cpp/forcedsecuresmtpclient.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include "../forcedsecuresmtpclient.h"
66

77
#ifdef _WIN32
8-
#ifdef SMTPCLIENT_EXPORTS
8+
#ifdef SMTPCLIENT_STATIC
9+
#define CPP_FORCEDSECURESMTPCLIENT_API
10+
#elif defined(SMTPCLIENT_EXPORTS)
911
#define CPP_FORCEDSECURESMTPCLIENT_API __declspec(dllexport)
1012
#else
1113
#define CPP_FORCEDSECURESMTPCLIENT_API __declspec(dllimport)

src/cpp/htmlmessage.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include "messageaddress.hpp"
1010

1111
#ifdef _WIN32
12-
#ifdef SMTPCLIENT_EXPORTS
12+
#ifdef SMTPCLIENT_STATIC
13+
#define CPP_HTMLMESSAGE_API
14+
#elif defined(SMTPCLIENT_EXPORTS)
1315
#define CPP_HTMLMESSAGE_API __declspec(dllexport)
1416
#else
1517
#define CPP_HTMLMESSAGE_API __declspec(dllimport)

src/cpp/message.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#ifdef _WIN32
1111
#pragma warning(disable: 4251)
12-
#ifdef SMTPCLIENT_EXPORTS
12+
#ifdef SMTPCLIENT_STATIC
13+
#define CPP_MESSAGE_API
14+
#elif defined(SMTPCLIENT_EXPORTS)
1315
#define CPP_MESSAGE_API __declspec(dllexport)
1416
#else
1517
#define CPP_MESSAGE_API __declspec(dllimport)

0 commit comments

Comments
 (0)