From 0aaf10a604cc99150409b4bc87edef1cc51e635a Mon Sep 17 00:00:00 2001 From: Waqqas Jabbar Date: Tue, 14 Jan 2020 17:25:22 +0500 Subject: [PATCH 1/3] Moved test coded in "tests". Moved decompressor code in "decompressor". Moved Perf in "perf" directory. Added CMakelist to generate library and decompressor. Added functionality to generate NanoLog.pc to easily integrate with other cmake projects using pkg-config --- .gitignore | 2 +- CMakeLists.txt | 32 ++++++++++++++++++++ NanoLog.pc.in | 14 +++++++++ cmake/modules/FindRT.cmake | 21 +++++++++++++ decompressor/CMakeLists.txt | 10 ++++++ {runtime => decompressor}/LogDecompressor.cc | 0 perf/CMakeLists.txt | 9 ++++++ {runtime => perf}/Perf.cc | 0 {runtime => perf}/PerfHelper.cc | 0 {runtime => perf}/PerfHelper.h | 0 {runtime => tests}/LogTest.cc | 0 {runtime => tests}/NanoLogCpp17Test.cc | 0 {runtime => tests}/NanoLogTest.cc | 0 {runtime => tests}/PackerTest.cc | 0 14 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 NanoLog.pc.in create mode 100644 cmake/modules/FindRT.cmake create mode 100644 decompressor/CMakeLists.txt rename {runtime => decompressor}/LogDecompressor.cc (100%) create mode 100644 perf/CMakeLists.txt rename {runtime => perf}/Perf.cc (100%) rename {runtime => perf}/PerfHelper.cc (100%) rename {runtime => perf}/PerfHelper.h (100%) rename {runtime => tests}/LogTest.cc (100%) rename {runtime => tests}/NanoLogCpp17Test.cc (100%) rename {runtime => tests}/NanoLogTest.cc (100%) rename {runtime => tests}/PackerTest.cc (100%) diff --git a/.gitignore b/.gitignore index e4a7470..31cac09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .idea/ -CMakeLists.txt cmake-build-debug/ make-all.sh +build/ ._* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9031f47 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.10) + +project(NanoLog VERSION 0.0.1 DESCRIPTION "Nanolog is an extremely performant nanosecond scale logging system for C++ that exposes a simple printf-like API.") + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") + +set(CMAKE_CXX_STANDARD 17) + +# pre-requisites +find_package(Threads REQUIRED) +find_package(RT REQUIRED) + +file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/runtime/*.h) +file(GLOB SOURCES ${PROJECT_SOURCE_DIR}/runtime/*.cc ${PROJECT_SOURCE_DIR}/runtime/testHelper/GeneratedCode.cc) +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/runtime) + +set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1) +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADERS}") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) + +add_subdirectory(decompressor) +add_subdirectory(perf) + +include(GNUInstallDirs) + +install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) + diff --git a/NanoLog.pc.in b/NanoLog.pc.in new file mode 100644 index 0000000..c6d9d68 --- /dev/null +++ b/NanoLog.pc.in @@ -0,0 +1,14 @@ +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix="@CMAKE_INSTALL_PREFIX@" +libdir="${exec_prefix}/@CMAKE_INSTALL_LIBDIR@" +includedir="${exec_prefix}/@CMAKE_INSTALL_INCLUDEDIR@" + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +URL: https://github.com/PlatformLab/NanoLog.git +Version: @PROJECT_VERSION@ +Requires: @PKGCONF_LIBS_PUB@ +Requires.private: @PKGCONF_REQ_PRIV@ +Cflags: -I"${includedir}" +Libs: -L"${libdir}" -l@PROJECT_NAME@ @CMAKE_THREAD_LIBS_INIT@ @RT_LIBRARIES@ @PKGCONF_LIBS_PUB@ +Libs.private: -L"${libdir}" -l@PROJECT_NAME@ @CMAKE_THREAD_LIBS_INIT@ @RT_LIBRARIES@ @PKGCONF_LIBS_PRIV@ \ No newline at end of file diff --git a/cmake/modules/FindRT.cmake b/cmake/modules/FindRT.cmake new file mode 100644 index 0000000..1c44b76 --- /dev/null +++ b/cmake/modules/FindRT.cmake @@ -0,0 +1,21 @@ +# Try to find real time libraries +# Once done, this will define +# +# RT_FOUND - system has rt library +# RT_LIBRARIES - rt libraries directory + +include(FindPackageHandleStandardArgs) + +if(RT_LIBRARIES) + set(RT_FIND_QUIETLY TRUE) +else() + find_library( + RT_LIBRARY + NAMES rt + HINTS ${RT_ROOT_DIR} + PATH_SUFFIXES ${LIBRARY_PATH_PREFIX}) + + set(RT_LIBRARIES ${RT_LIBRARY}) + find_package_handle_standard_args(rt DEFAULT_MSG RT_LIBRARY) + mark_as_advanced(RT_LIBRARY) +endif() diff --git a/decompressor/CMakeLists.txt b/decompressor/CMakeLists.txt new file mode 100644 index 0000000..28a8be6 --- /dev/null +++ b/decompressor/CMakeLists.txt @@ -0,0 +1,10 @@ +project(decompressor) + +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cc ${CMAKE_SOURCE_DIR}/runtime/testHelper/GeneratedCode.cc) +add_executable(${PROJECT_NAME} ${SOURCES}) + +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime) +target_link_libraries(${PROJECT_NAME} NanoLog) + +include(GNUInstallDirs) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/runtime/LogDecompressor.cc b/decompressor/LogDecompressor.cc similarity index 100% rename from runtime/LogDecompressor.cc rename to decompressor/LogDecompressor.cc diff --git a/perf/CMakeLists.txt b/perf/CMakeLists.txt new file mode 100644 index 0000000..4001f58 --- /dev/null +++ b/perf/CMakeLists.txt @@ -0,0 +1,9 @@ +project(Perf) + +find_package(Threads REQUIRED) + +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_SOURCE_DIR}/runtime/testHelper/GeneratedCode.cc) +add_executable(${PROJECT_NAME} ${SOURCES}) + +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime) +target_link_libraries(${PROJECT_NAME} NanoLog ${CMAKE_THREAD_LIBS_INIT}) diff --git a/runtime/Perf.cc b/perf/Perf.cc similarity index 100% rename from runtime/Perf.cc rename to perf/Perf.cc diff --git a/runtime/PerfHelper.cc b/perf/PerfHelper.cc similarity index 100% rename from runtime/PerfHelper.cc rename to perf/PerfHelper.cc diff --git a/runtime/PerfHelper.h b/perf/PerfHelper.h similarity index 100% rename from runtime/PerfHelper.h rename to perf/PerfHelper.h diff --git a/runtime/LogTest.cc b/tests/LogTest.cc similarity index 100% rename from runtime/LogTest.cc rename to tests/LogTest.cc diff --git a/runtime/NanoLogCpp17Test.cc b/tests/NanoLogCpp17Test.cc similarity index 100% rename from runtime/NanoLogCpp17Test.cc rename to tests/NanoLogCpp17Test.cc diff --git a/runtime/NanoLogTest.cc b/tests/NanoLogTest.cc similarity index 100% rename from runtime/NanoLogTest.cc rename to tests/NanoLogTest.cc diff --git a/runtime/PackerTest.cc b/tests/PackerTest.cc similarity index 100% rename from runtime/PackerTest.cc rename to tests/PackerTest.cc From bd1d6b0c63b263a494f36223f4449c966d825ebb Mon Sep 17 00:00:00 2001 From: Waqqas Jabbar Date: Tue, 14 Jan 2020 17:44:11 +0500 Subject: [PATCH 2/3] Added options to build sample, decompressor and perf. Building sample using cmake --- CMakeLists.txt | 16 ++++++++++++++-- sample/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 sample/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9031f47..f8975ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,20 @@ set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADERS}") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -add_subdirectory(decompressor) -add_subdirectory(perf) +option(BUILD_DECOPRESSOR "Build decompressor app" ON) +if(BUILD_DECOPRESSOR) + add_subdirectory(decompressor) +endif() + +option(BUILD_PERF "Build perf app" OFF) +if(BUILD_PERF) + add_subdirectory(perf) +endif() + +option(BUILD_SAMPLE "Build sample app" OFF) +if(BUILD_SAMPLE) + add_subdirectory(sample) +endif() include(GNUInstallDirs) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..503d5fb --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,12 @@ +project(sample) + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") + +find_package(Threads REQUIRED) +find_package(RT REQUIRED) + +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) +add_executable(${PROJECT_NAME} ${SOURCES}) + +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime) +target_link_libraries(${PROJECT_NAME} NanoLog ${CMAKE_THREAD_LIBS_INIT} ${RT_LIBRARIES}) From 8933b36096eab6bfae5fbeef0736d6392ea6d03d Mon Sep 17 00:00:00 2001 From: Waqqas Jabbar Date: Tue, 14 Jan 2020 19:17:07 +0500 Subject: [PATCH 3/3] Building unit-test through cmake. Removed googletest for git modules --- .gitmodules | 3 --- CMakeLists.txt | 6 ++++++ googletest | 1 - tests/CMakeLists.txt | 11 +++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) delete mode 100644 .gitmodules delete mode 160000 googletest create mode 100644 tests/CMakeLists.txt diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8cf8b5e..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "googletest"] - path = googletest - url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index f8975ce..2b2c270 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,12 @@ if(BUILD_SAMPLE) add_subdirectory(sample) endif() +option(BUILD_TEST "Build unit tests" ON) +if(BUILD_TEST) + enable_testing () + add_subdirectory(tests) +endif() + include(GNUInstallDirs) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/googletest b/googletest deleted file mode 160000 index ecd5308..0000000 --- a/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ecd530865cefdfa7dea58e84f6aa1b548950363d diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..6430e3c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +project(Tests) + +find_package(GTest REQUIRED) + +file(GLOB SOURCES *.cc) +add_executable(${PROJECT_NAME} ${SOURCES}) + +target_link_libraries(${PROJECT_NAME} GTest::GTest GTest::Main NanoLog ${CMAKE_THREAD_LIBS_INIT} ${RT_LIBRARIES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime) + +gtest_discover_tests(${PROJECT_NAME})