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 #2207

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ Makefile.in
/resources/js/d3.v3.min.js.tmp
/resources/js/hogan.min.js.tmp
/resources/tpls.html.tmp

# CMake and IDE
.idea
*build*
*_export.h
92 changes: 92 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.19)
project(goaccess VERSION 0.0.1 LANGUAGES C)

set(CMAKE_C_STANDARD 90)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
if (BUILD_SHARED_LIBS)
set(LIBRARY_TYPE_FLAG "SHARED")
else ()
set(LIBRARY_TYPE_FLAG "STATIC")
endif ()

# control where the static and shared libraries are built so that on windows
# we don't need to tinker with the path to run the executable
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

add_library("${PROJECT_NAME}_compiler_flags" INTERFACE)
target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_90")

set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
# -g -fsanitize=address -fno-omit-frame-pointer
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused;-pedantic->>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
if (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
endif()

# configure a header file to pass the version number only
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_NAME}Config.h"
)

add_subdirectory("src")

install(
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h"
DESTINATION "include"
)

include(InstallRequiredSystemLibraries)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "Gerardo O.")
set(CPACK_PACKAGE_DESCRIPTION "GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GoAccess is an open source real-time web log analyzer and interactive viewer")
if (APPLE)
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CustomVolumeIcon.icns")
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Welcome.txt")
set(CPACK_PACKAGE_CONTACT "hhttps://github.com/allinurl/${PROJECT_NAME}")

include(CPack)
include(CMakePackageConfigHelpers)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if (BUILD_SHARED_LIBS)
set(LIBRARY_TYPE_FLAG "SHARED")
else ()
set(LIBRARY_TYPE_FLAG "STATIC")
endif ()

# generate the config file that is includes the exports
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "lib/cmake/example"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
Binary file added cmake/BundleIcon.icns
Binary file not shown.
7 changes: 7 additions & 0 deletions cmake/CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CTEST_PROJECT_NAME "goaccess")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")

set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=goaccess")
set(CTEST_DROP_SITE_CDASH TRUE)
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/libgoaccessTargets.cmake" )
Binary file added cmake/CustomVolumeIcon.icns
Binary file not shown.
42 changes: 42 additions & 0 deletions cmake/FindGeoIP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# - Find GeoIP
# Find the GeoIP libraries
#
# This module defines the following variables:
# GeoIP_FOUND - True if GeoIP_INCLUDE_DIR & GeoIP_LIBRARY are found
# GeoIP_LIBRARIES - Set when GeoIP_LIBRARY is found
# GeoIP_INCLUDE_DIRS - Set when GeoIP_INCLUDE_DIR is found
#
# GeoIP_INCLUDE_DIR - where to find GeoIP.h and GeoIPCity.h.
# GeoIP_LIBRARY - the GeoIP library
#

#=============================================================================
# Copyright 2012 piernov <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

find_path(GeoIP_INCLUDE_DIR NAMES GeoIP.h GeoIPCity.h)

find_library(GeoIP_LIBRARY NAMES GeoIP)

# handle the QUIETLY and REQUIRED arguments and set GeoIP_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GeoIP DEFAULT_MSG GeoIP_LIBRARY GeoIP_INCLUDE_DIR)

set(GeoIP_FOUND ${GEOIP_FOUND})

if(GeoIP_FOUND)
set(GeoIP_LIBRARIES ${GeoIP_LIBRARY})
set(GeoIP_INCLUDE_DIRS ${GeoIP_INCLUDE_DIR})
endif()

mark_as_advanced(GeoIP_INCLUDE_DIR GeoIP_LIBRARY)
57 changes: 57 additions & 0 deletions cmake/FindMaxMindDB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# - Try to find MaxMindDB headers and libraries
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# LIBMAXMINDDB_ROOT_DIR Set this variable to the root installation of
# libmaxminddb if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# LIBMAXMINDDB_FOUND System has GeoIP libraries and headers
# LIBMAXMINDDB_LIBRARY The GeoIP library
# LIBMAXMINDDB_INCLUDE_DIR The location of GeoIP headers

set(brew_search "/usr/local/Cellar/libmaxminddb")
if (APPLE AND (NOT DEFINED LIBMAXMINDDB_ROOT_DIR) AND (IS_DIRECTORY "${brew_search}"))
file(GLOB children RELATIVE ${brew_search} ${brew_search}/*)
set(dirlist "")
foreach (child ${children})
if (IS_DIRECTORY ${brew_search}/${child})
LIST(APPEND include_search_list "${child}/include")
LIST(APPEND lib_search_list "${child}/lib")
endif ()
endforeach ()
set(brew_search "/usr/local/Cellar/libmaxminddb")
endif ()

find_path(LIBMAXMINDDB_INCLUDE_DIR
NAMES maxminddb.h
HINTS ${LIBMAXMINDDB_ROOT_DIR}/include ${include_search_list}
)

# We are just going to prefer static linking for this plugin.
set(libmaxminddb_names maxminddb libmaxminddb.a)

find_library(LIBMAXMINDDB_LIBRARY
NAMES ${libmaxminddb_names}
HINTS ${LIBMAXMINDDB_ROOT_DIR}/lib ${lib_search_list}
)

if (DEFINED LIBMAXMINDDB_INCLUDE_DIR AND DEFINED LIBMAXMINDDB_LIBRARY)
set(LIBMAXMINDDB_FOUND 1)
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MaxMindDB DEFAULT_MSG
LIBMAXMINDDB_LIBRARY
LIBMAXMINDDB_INCLUDE_DIR
)

mark_as_advanced(
LibMaxMindDB_ROOT_DIR
LIBMAXMINDDB_LIBRARY
LIBMAXMINDDB_INCLUDE_DIR
)

14 changes: 14 additions & 0 deletions cmake/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>BundleGeneratorTest</string>
<key>CFBundleIconFile</key>
<string>BundleGeneratorTest.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
6 changes: 6 additions & 0 deletions cmake/MultiCPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include("release/CPackConfig.cmake")

set(CPACK_INSTALL_CMAKE_PROJECTS
"debug;goaccess;ALL;/"
"release;goaccess;ALL;/"
)
1 change: 1 addition & 0 deletions cmake/Welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal on *nix systems or through your browser.
9 changes: 9 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef GOACCESS_CONFIG_H
#define GOACCESS_CONFIG_H

#define GOACCESS_VERSION_MAJOR @GOACCESS_VERSION_MAJOR@
#define GOACCESS_VERSION_MINOR @GOACCESS_VERSION_MINOR@
#define GOACCESS_VERSION_PATCH @GOACCESS_VERSION_PATCH@
#define GOACCESS_VERSION "@GOACCESS_VERSION@"

#endif /* GOACCESS_CONFIG_H */
Loading