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/.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 new file mode 100644 index 0000000..2b2c270 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,50 @@ +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) + +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() + +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}) +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/googletest b/googletest deleted file mode 160000 index ecd5308..0000000 --- a/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ecd530865cefdfa7dea58e84f6aa1b548950363d 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/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}) 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}) 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