Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake Integration #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.idea/
CMakeLists.txt
cmake-build-debug/
make-all.sh
build/

._*
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GeneratedCode.cc is not a file that exists in the repo - it has to be generated by the preprocessor script. I don't think this command succeed on a standard check out. @syang0 do you have CI checks enabled on pull requests? I see no checks ran on this PR and I suspect they should be failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, CI checks are only enabled on the main branch. They wouldn't have run anyway for this PR since it substantially changed the build structure and where the executables exist.

add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})

target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/runtime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be marked as PUBLIC not PRIVATE to ensure that non standalone builds get the correct include directories.


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)

14 changes: 14 additions & 0 deletions NanoLog.pc.in
Original file line number Diff line number Diff line change
@@ -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@
21 changes: 21 additions & 0 deletions cmake/modules/FindRT.cmake
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions decompressor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
File renamed without changes.
1 change: 0 additions & 1 deletion googletest
Submodule googletest deleted from ecd530
9 changes: 9 additions & 0 deletions perf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions sample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.