Skip to content

Commit

Permalink
Enhance build system and testing
Browse files Browse the repository at this point in the history
* Added a new STATIC library target to enhance testing
* Added an OBJECT precompile phase to ease linking

Signed-off-by: Vinícius Ferrão <[email protected]>
  • Loading branch information
viniciusferrao committed Jul 15, 2023
1 parent 173f5f0 commit e023f7a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
47 changes: 38 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Add source files and set linking
file(GLOB SOURCE_FILES
*.cpp
mailsystem/*.cpp
presenter/*.cpp
queuesystem/*.cpp
services/*.cpp
view/*.cpp)
# Add all source files except main.cpp
file(GLOB_RECURSE SOURCE_FILES *.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

message(STATUS "Source files found are: ${SOURCE_FILES}")

add_executable(main ${SOURCE_FILES})
# Build a library and a main binary that links to the library
add_library(cloysterhpc_object OBJECT ${SOURCE_FILES})
add_library(cloysterhpc_static STATIC $<TARGET_OBJECTS:cloysterhpc_object>)
add_executable(main main.cpp)

target_link_libraries(
main
PRIVATE
cloysterhpc_static
cloysterhpc::cloysterhpc_options
cloysterhpc::cloysterhpc_warnings)

Expand All @@ -33,6 +33,35 @@ target_link_system_libraries(
${STDC++FS}
doctest::doctest)

target_link_libraries(
cloysterhpc_object
PRIVATE
cloysterhpc::cloysterhpc_options
cloysterhpc::cloysterhpc_warnings)

target_link_system_libraries(
cloysterhpc_object
PRIVATE
${NEWT_LIBRARY}
fmt::fmt
CLI11::CLI11
Boost::headers
Boost::system
Boost::thread
spdlog::spdlog
gsl::gsl-lite
magic_enum::magic_enum
SimpleIni::SimpleIni
resolv
${STDC++FS}
doctest::doctest)

target_include_directories(cloysterhpc_static PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")
target_include_directories(cloysterhpc_static ${WARNING_GUARD} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)

target_include_directories(cloysterhpc_object PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")
target_include_directories(cloysterhpc_object ${WARNING_GUARD} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)

target_include_directories(main PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")
target_include_directories(main ${WARNING_GUARD} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)

Expand Down
2 changes: 1 addition & 1 deletion src/inifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "cloysterhpc/inifile.h"
#include <cloysterhpc/inifile.h>

// TODO: Template<T> the next three functions
void inifile::loadFile(const std::string& filepath)
Expand Down
35 changes: 23 additions & 12 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,34 @@ add_test(NAME cli.has_help COMMAND main --help)
add_test(NAME cli.version_matches COMMAND main --version)
set_tests_properties(cli.version_matches PROPERTIES PASS_REGULAR_EXPRESSION "${PROJECT_VERSION}")

file(GLOB TEST_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
message(STATUS "Test files found are: ${TEST_SOURCES}")

add_executable(${PROJECT_NAME} ${TEST_SOURCES})

target_link_libraries(
${PROJECT_NAME}
PRIVATE cloysterhpc::cloysterhpc_warnings
cloysterhpc::cloysterhpc_options
doctest::doctest
fmt::fmt
spdlog::spdlog
magic_enum::magic_enum
SimpleIni::SimpleIni
gsl::gsl-lite
Boost::headers
Boost::system
Boost::thread)
PRIVATE
cloysterhpc_static
cloysterhpc::cloysterhpc_warnings
cloysterhpc::cloysterhpc_options)

target_link_system_libraries(
${PROJECT_NAME}
PRIVATE
${NEWT_LIBRARY}
fmt::fmt
CLI11::CLI11
Boost::headers
Boost::system
Boost::thread
spdlog::spdlog
gsl::gsl-lite
magic_enum::magic_enum
SimpleIni::SimpleIni
resolv
${STDC++FS}
doctest::doctest)

target_include_directories(${PROJECT_NAME} ${WARNING_GUARD} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/../include>
Expand Down
4 changes: 2 additions & 2 deletions test/inifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <cloysterhpc/inifile.h>
#include "../src/inifile.cpp"
#include <doctest/doctest.h>

#include <cloysterhpc/inifile.h>
#include <filesystem>
#include <iostream>

Expand Down
7 changes: 2 additions & 5 deletions test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <doctest/doctest.h>

#include <cloysterhpc/network.h>
#include <cloysterhpc/connection.h>
#include "../src/network.cpp" // This is lame
#include "../src/connection.cpp" // This is also lame
#include <boost/asio.hpp>

#include <doctest/doctest.h>

TEST_SUITE("Network setters and getters")
{

Expand Down

0 comments on commit e023f7a

Please sign in to comment.