0

I am quite new to cmake and have a question what is the best way to achieve this:

I need to link my code against three libraries from cpp-netlib:

cppnetlib-uri
cppnetlib-server-parsers
cppnetlib-client-connections

This is how my CMakeLists.txt currently looks like:

cmake_minimum_required(VERSION 2.6)
project(Songkick_API_call)

set(SOURCE_DIR src)
add_subdirectory(${SOURCE_DIR})

find_library(CPPNETLIB_URI cppnetlib-uri)
find_library(CPPNETLIB_SERVER cppnetlib-server-parsers)
find_library(CPPNETLIB_CON cppnetlib-client-connections)

add_executable(Songkick_API_call ${SOURCE_DIR}/test.cpp)
target_link_libraries(Songkick_API_call ${CPPNETLIB_URI} 
${CPPNETLIB_SERVER} ${CPPNETLIB_CON} pthread)

It is working, but calling find_library three times looks wrong. How should this be done?

Natjo
  • 2,005
  • 29
  • 75
  • 1
    You may try to use `find_package(cppnetlib)`, like in [that question](https://stackoverflow.com/questions/34447568/cmake-cant-find-cpp-netlib-libraries). If this doesn't work (there is no CMake file which describes such package), `find_library` approach is good. You may wrap single call to `find_library` into a macro, but generally that doesn't change anything. – Tsyvarev Aug 08 '17 at 21:56
  • `find_package(cppnetlib)` works! After some research I also found an example cmake file on their website explaining what you recommended. Is there any way I could have known from linked libraries I used that there exists a preconfigured package? – Natjo Aug 09 '17 at 11:08
  • 1
    Except from "Find" modules shipped with CMake itself, there is no single list of available modules (at least, I don't know about such list). If CMake package file exists for a library ``, then simple google request "CMake find " is usually sufficient. – Tsyvarev Aug 09 '17 at 17:29

0 Answers0