Skip to content

Commit

Permalink
Merge pull request #38 from ess-dmsc/cmake_and_namespace_fixes
Browse files Browse the repository at this point in the history
CMake and namespace fixes
  • Loading branch information
SkyToGround authored May 12, 2020
2 parents 02351c2 + 0470345 commit daf1648
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 32 deletions.
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project("graylog-logger"
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)

# Conan - bring in dependencies with conan
set(CONAN_PROFILE "default" CACHE STRING "Name of conan profile to use, uses default by default")
Expand Down Expand Up @@ -40,14 +40,26 @@ else()
add_definitions(-D_WIN32_WINNT=0x0A00)
endif(NOT WIN32)

find_package(ASIO REQUIRED MODULE)
find_package(nlohmann_json REQUIRED)
find_package(asio REQUIRED)
find_package(nlohmann_json QUIET)
if (NOT nlohmann_json_FOUND)
message(STATUS "Unable to find system installed version of jsonformoderncpp. Attempting to find Conan provided version.")
find_package(jsonformoderncpp REQUIRED)
endif()

find_package(Threads REQUIRED)
find_package(ConcurrentQueue REQUIRED)
find_package(concurrentqueue REQUIRED)

find_package(GTest)
find_package(GMock)
find_package(fmt 6)
find_package(fmt CONFIG)
if (NOT fmt_FOUND)
message(STATUS "Unable to find fmt using config-module. Attempting again using built-in find-module.")
find_package(fmt MODULE)
if (NOT fmt_FOUND)
message(STATUS "Unable to find fmt using built-in find-module.")
endif()
endif()
find_package(GoogleBenchmark)

add_subdirectory(src)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ cmake ..
make install
```

#### Making a conan package
If you are creating a conan package of this library you should disable CMake from running Conan by providing the following argument to CMake: `-DCONAN=DISABLE`. Furthermore, you must also use the `cmake_find_package` generator for CMake to be able to find the dependencies.

#### System installed dependencies
If using conan is not an option, it is possible to build the library using system installed dependencies. This requires a bit more work though and might not be as reliable.

Expand Down
6 changes: 3 additions & 3 deletions cmake/FindASIO.cmake → cmake/Findasio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if(ASIO_FOUND)
set(ASIO_INCLUDE_DIRS ${ASIO_INCLUDE_DIR})
endif()

if(ASIO_FOUND AND NOT TARGET ASIO::ASIO)
add_library(ASIO::ASIO INTERFACE IMPORTED)
set_target_properties(ASIO::ASIO PROPERTIES
if(ASIO_FOUND AND NOT TARGET asio::asio)
add_library(asio::asio INTERFACE IMPORTED)
set_target_properties(asio::asio PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ASIO_INCLUDE_DIR}"
)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if(ConcurrentQueue_FOUND)
set(ConcurrentQueue_INCLUDE_DIRS ${ConcurrentQueue_INCLUDE_DIR})
endif()

if(ConcurrentQueue_FOUND AND NOT TARGET ConcurrentQueue::ConcurrentQueue)
add_library(ConcurrentQueue::ConcurrentQueue INTERFACE IMPORTED)
set_target_properties(ConcurrentQueue::ConcurrentQueue PROPERTIES
if(ConcurrentQueue_FOUND AND NOT TARGET concurrentqueue::concurrentqueue)
add_library(concurrentqueue::concurrentqueue INTERFACE IMPORTED)
set_target_properties(concurrentqueue::concurrentqueue PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ConcurrentQueue_INCLUDE_DIR}"
)
endif()
6 changes: 2 additions & 4 deletions cmake/GraylogLoggerConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ include(CMakeFindDependencyMacro)
list(APPEND CMAKE_MODULE_PATH ${GraylogLogger_CMAKE_DIR})

find_dependency(Threads REQUIRED)
find_dependency(ASIO REQUIRED MODULE)
find_dependency(nlohmann_json REQUIRED)
find_dependency(ConcurrentQueue REQUIRED)
find_dependency(concurrentqueue REQUIRED)

set(WITH_FMT @fmt_FOUND@)

if(WITH_FMT)
find_package(fmt 6 REQUIRED)
find_dependency(fmt REQUIRED)
endif()

if(NOT TARGET GraylogLogger::graylog_logger)
Expand Down
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ gtest:shared=False
[generators]
cmake
virtualrunenv
cmake_find_package
8 changes: 8 additions & 0 deletions documentation/changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changes

### Version 2.0.2
* Made important CMkae changes required for properly making Conan packages. (ed-alertedh)
* Made minor changes to the code to prevent issues when using a `using namespace std;` statement.
* Minor documentation changes.

### Version 2.0.1
* Fixed faulty CMake code that did not properly import dependencies.

### Version 2.0.0
* Added performance tests.
* Replaced the home-brewed concurrent queue with a *much* faster open source one.
Expand Down
3 changes: 2 additions & 1 deletion include/graylog_logger/MinimalApply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace detail {
template <class F, class Tuple, std::size_t... I>
constexpr decltype(auto) apply_impl(F &&f, Tuple &&t,
std::index_sequence<I...>) {
return invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...);
return minimal::invoke(std::forward<F>(f),
std::get<I>(std::forward<Tuple>(t))...);
}
} // namespace detail

Expand Down
32 changes: 20 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
set(common_libs PUBLIC
set(common_private_libs
Threads::Threads
ConcurrentQueue::ConcurrentQueue
ASIO::ASIO
nlohmann_json::nlohmann_json
)
asio::asio
)
if (nlohmann_json_FOUND)
list(APPEND common_private_libs nlohmann_json::nlohmann_json)
endif()

if (jsonformoderncpp_FOUND)
list(APPEND common_private_libs jsonformoderncpp::jsonformoderncpp)
endif()

set(common_public_libs
concurrentqueue::concurrentqueue
)

if(fmt_FOUND)
message(STATUS "Found fmtlib, adding support for threaded formatting.")
list(APPEND common_libs fmt::fmt)
list(APPEND common_public_libs fmt::fmt)
else()
message(STATUS "Unable to find fmtlib. There will be no support for threaded formatting.")
endif()
Expand Down Expand Up @@ -40,11 +49,10 @@ set(Graylog_INC
${CMAKE_BINARY_DIR}/include/graylog_logger/LibConfig.hpp
)

get_target_property(JSON_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)

add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC})
add_library(GraylogLogger::graylog_logger ALIAS graylog_logger)
target_link_libraries(graylog_logger ${common_libs})
target_link_libraries(graylog_logger PRIVATE ${common_private_libs})
target_link_libraries(graylog_logger PUBLIC ${common_public_libs})
target_include_directories(graylog_logger
PUBLIC
$<INSTALL_INTERFACE:include>
Expand All @@ -56,7 +64,8 @@ target_include_directories(graylog_logger

add_library(graylog_logger_static STATIC ${Graylog_SRC} ${Graylog_INC} ${Graylog_private_INC})
add_library(GraylogLogger::graylog_logger_static ALIAS graylog_logger_static)
target_link_libraries(graylog_logger_static ${common_libs})
target_link_libraries(graylog_logger_static PRIVATE ${common_private_libs})
target_link_libraries(graylog_logger_static PUBLIC ${common_public_libs})
target_include_directories(graylog_logger_static
PUBLIC
$<INSTALL_INTERFACE:include>
Expand Down Expand Up @@ -108,8 +117,7 @@ configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/GraylogLoggerConfig.cm
)

install(FILES
${CMAKE_CURRENT_LIST_DIR}/../cmake/FindASIO.cmake
${CMAKE_CURRENT_LIST_DIR}/../cmake/FindConcurrentQueue.cmake
${CMAKE_CURRENT_LIST_DIR}/../cmake/Findconcurrentqueue.cmake
${CMAKE_CURRENT_BINARY_DIR}/GraylogLoggerConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GraylogLoggerConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
Expand Down
18 changes: 14 additions & 4 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ set(UnitTest_INC
Semaphore.hpp)

add_executable(unit_tests EXCLUDE_FROM_ALL ${UnitTest_SRC} ${UnitTest_INC})

target_link_libraries(unit_tests
set(unit_test_libs PUBLIC
GraylogLogger::graylog_logger_static
nlohmann_json::nlohmann_json
GTest::GTest
${GMOCK_BOTH_LIBRARIES}
ASIO::ASIO
asio::asio
)

if (nlohmann_json_FOUND)
list(APPEND unit_test_libs nlohmann_json::nlohmann_json)
endif()

if (jsonformoderncpp_FOUND)
list(APPEND unit_test_libs jsonformoderncpp::jsonformoderncpp)
endif()

target_link_libraries(unit_tests
${unit_test_libs}
)

add_test(TestAll unit_tests)

0 comments on commit daf1648

Please sign in to comment.