easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

Provide a CMake config file rather than a find module

Open codecircuit opened this issue 5 years ago • 4 comments

According to modern CMake you should rather provide a easyloggingppConfig.cmake than a FindEASYLOGGINGPP.cmake, which should be installed when make install is executed. This would enhance the useability of this project, as other CMake projects want to include Easylogging by:

find_package(easyloggingpp REQUIRED)
add_executable(foo ...)
target_link_libraries(foo easyloggingpp::easyloggingpp ...)

This requires the installation of ${CMAKE_INSTALL_PREFIX}/share/cmake/easyloggingppConfig.cmake similar to easyloggingpp.pc, and the implementation of #621.

See also: https://www.youtube.com/watch?v=bsXLMQ6WgIk summarised in: https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/

This would also simplify the installation of Easylogging with package manager spack

codecircuit avatar Sep 14 '18 13:09 codecircuit

This would be amazing! Easylogging is the only external package that I use that does not conform to modern cmake.

ruifm avatar Feb 27 '19 11:02 ruifm

I've done a temporary solution.

https://gist.github.com/ccvca/d7c3b90122ac96dc9485afaa0d10b3f5

Using this FindEasyloggingpp.cmake file will provide you find_package support with the current version of the library.

Usage:

  1. Install the static library
  2. Add FindEasyloggingpp.cmake to your project (e.g. in the directory cmake)
  3. Use the follwing cmake-snipped to include it into your project
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # adapt your folder name for CMAKE-files here
find_package(easyloggingpp REQUIRED)

add_library(Util ConfigureLogger.cpp)
target_link_libraries(Util easyloggingpp::easyloggingpp) #Include by linking easyloggingpp::easyloggingpp

ccvca avatar Apr 05 '19 15:04 ccvca

What speaks against simply including Easylogging with your sources? With "modern CMake", you could do

FetchContent_Declare(
		easyloggingpp
		GIT_REPOSITORY https://github.com/amrayn/easyloggingpp.git
		GIT_TAG        v9.97.0
)
FetchContent_GetProperties(easyloggingpp)
if(NOT easyloggingpp_POPULATED)
	FetchContent_Populate(easyloggingpp)
endif()

and in your application/library target, you attach the sources as you normally would do:

add_executable(blub
		source.cpp
		${easyloggingpp_SOURCE_DIR}/src/easylogging++.cc
		)
target_include_directories(blub
		PRIVATE
		${easyloggingpp_SOURCE_DIR}/src/
		)

I'm by far not a CMake expert, but that seems to work.

halirutan avatar Apr 18 '21 07:04 halirutan

On Ubuntu where I can install libeasyloggingpp-dev it comes with a pkgconfig .pc file.

In CMake, you can create a find module:

find_package(PkgConfig REQUIRED)
pkg_search_module(
    Easylogging
    REQUIRED
    IMPORTED_TARGET
    easyloggingpp)
    
if(Easylogging_FOUND)
  add_library(Easylogging::Easylogging ALIAS PkgConfig::Easylogging)
endif()

Then you can consume with

find_package(Easylogging REQUIRED)
target_link_libraries(foo PRIVATE Easylogging::Easylogging)

This has the advantage of working with the version installed in current Ubuntu distros, without having to bring in Easylogging and compile locally in your library.

Sadly, I can't get it to work. According to the CMake's docs, the target PkgConfig::<prefix> should be created, but it isn't.

0.949   add_library cannot create ALIAS target "Easylogging::Easylogging" because
0.949   target "PkgConfig::Easylogging" does not already exist.
0.949 Call Stack (most recent call first):
0.949   CMakeLists.txt:264 (find_package)

Any help is appreciated.

Ryanf55 avatar Aug 08 '23 19:08 Ryanf55