Skip to content

Commit

Permalink
refactore cmake files, adding optional demos and tests to the build
Browse files Browse the repository at this point in the history
  • Loading branch information
Plaristote authored and attila-tokes committed Dec 4, 2024
1 parent a942060 commit 3268ae3
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 27 deletions.
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.16)

project(SmtpMime
VERSION 2.0
LANGUAGES C CXX)

option(BUILD_TESTS "builds tests" ON)
option(BUILD_DEMOS "builds demos" ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC OFF)

find_package(QT NAMES Qt6 COMPONENTS Core Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network REQUIRED)

set(LIBRARY_TARGET_NAME ${PROJECT_NAME})

message(USING Qt${QT_VERSION_MAJOR})

add_subdirectory(src)

if (BUILD_TESTS)
add_subdirectory(test)
endif()
if (BUILD_DEMOS)
add_subdirectory(demos)
endif()
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,30 @@ For more examples see the [Wiki/Examples](https://github.com/bluetiger9/SmtpClie
## Building
### Building CMake
### Building with CMake
To build the project with CMake run the following comamnds:
To build the project with CMake run the following commands:
```sh
$ cmake . -DQt6_DIR="/qt/install/loccation/6.x.x/6.x.x/gcc_64/lib/cmake/Qt6" -DCMAKE_INSTALL_PREFIX="../release"
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_PREFIX_PATH=/qt/install/location/6.x.x/6.x.x/gcc_64/lib/cmake/Qt6 -DCMAKE_INSTALL_PREFIX="../release"
$ cmake --build ./
$ cmake --install ./
```

Or if you want to build without the demos and tests:
```sh
$ mkdir build
$ cd build
$ cmake .. -DBUILD_TESTS=OFF -DBUILD_DEMOS=OFF -DCMAKE_PREFIX_PATH=/qt/install/location/6.x.x/6.x.x/gcc_64/lib/cmake/Qt6 -DCMAKE_INSTALL_PREFIX="../release"
$ cmake --build ./
```

### Building with QMake

To build the project with QMake run the following comamnds:
To build the project with QMake run the following commands:
```sh
$ /qt/install/loccation/6.x.x/6.x.x/gcc_64/bin/qmake .
$ /qt/install/location/6.x.x/6.x.x/gcc_64/bin/qmake .
$ make
```

Expand Down
8 changes: 8 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Widgets REQUIRED)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

add_subdirectory(demo1)
add_subdirectory(demo2)
add_subdirectory(demo3)
add_subdirectory(demo4)
5 changes: 5 additions & 0 deletions demos/demo1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(demo1 demo1.cpp)

target_link_libraries(demo1 PRIVATE
Qt${QT_VERSION_MAJOR}::Core
${LIBRARY_TARGET_NAME})
10 changes: 10 additions & 0 deletions demos/demo2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(demo2
demo2.cpp
sendemail.cpp
sendemail.ui)

target_link_libraries(demo2 PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
${LIBRARY_TARGET_NAME})
5 changes: 5 additions & 0 deletions demos/demo3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(demo3 demo3.cpp)

target_link_libraries(demo3 PRIVATE
Qt${QT_VERSION_MAJOR}::Core
${LIBRARY_TARGET_NAME})
5 changes: 5 additions & 0 deletions demos/demo4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(demo4 demo4.cpp)

target_link_libraries(demo4 PRIVATE
Qt${QT_VERSION_MAJOR}::Core
${LIBRARY_TARGET_NAME})
30 changes: 8 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
cmake_minimum_required(VERSION 3.16)

project(SmtpMime VERSION 2.0 LANGUAGES C CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network REQUIRED)

add_compile_options(-DSMTP_MIME_LIBRARY)

message(USING Qt${QT_VERSION_MAJOR})

qt_add_library(${PROJECT_NAME} SHARED
qt_add_library(${LIBRARY_TARGET_NAME} SHARED
emailaddress.cpp
mimeattachment.cpp
mimebytearrayattachment.cpp
Expand Down Expand Up @@ -56,14 +40,16 @@ qt_add_library(${PROJECT_NAME} SHARED
mimebase64formatter.h
mimecontentformatter.h
)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Network)

target_link_libraries(${LIBRARY_TARGET_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network)

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH${ORIGIN}”)

target_include_directories(${PROJECT_NAME}
target_include_directories(${LIBRARY_TARGET_NAME}
PRIVATE
# where the library itself will look for its internal headers
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -98,14 +84,14 @@ set(public_headers
mimebytearrayattachment.h
)
# note that ${public_headers} has to be in quotes
set_target_properties(${PROJECT_NAME} PROPERTIES
set_target_properties(${LIBRARY_TARGET_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${public_headers}"
)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
install(TARGETS ${LIBRARY_TARGET_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/smtpmime
)
10 changes: 10 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED)

add_executable(test
main.cpp
connectiontest.cpp)

target_link_libraries(test PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Test
${LIBRARY_TARGET_NAME})

0 comments on commit 3268ae3

Please sign in to comment.