I recently started learning CMake and have decided to use it with an old project I was working on. The project has cpp-netlib, boost and Openssl as dependencies. Here is the working CMakeLists.txt file I came up with.
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
PROJECT(MangaMe)
INCLUDE_DIRECTORIES(includes)
ADD_EXECUTABLE(mangaMe src/mangaMe.cpp)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.59.0 REQUIRED COMPONENTS system thread filesystem)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMe ${Boost_LIBRARIES})
SET(OPENSSL_LIB_DIR /usr/local/Cellar/openssl/1.0.2e/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/openssl/1.0.2e/include)
TARGET_LINK_LIBRARIES(mangaMe ${OPENSSL_LIB_DIR}/libcrypto.dylib ${OPENSSL_LIB_DIR}/libssl.dylib)
#WHY DOESNT THIS WORK!?!??!!?
#FIND_PACKAGE(cppnetlib 0.11 REQUIRED COMPONENTS client-connections server-parsers uri)
#INCLUDE_DIRECTORIES(${cppnetlib_INCLUDE_DIRS})
#TARGET_LINK_LIBRARIES(mangaMe ${cppnetlib_LIBRARIES})
SET(CPPNETLIB_LIB_DIR /usr/local/Cellar/cpp-netlib/0.11.2/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/cpp-netlib/0.11.2/include)
TARGET_LINK_LIBRARIES(mangaMe ${CPPNETLIB_LIB_DIR}/libcppnetlib-client-connections.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-server-parsers.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-uri.a)
I was wondering if anyone has any idea why the commented out section using FIND_PACKAGE to find cppnetlib doesn't work? I used homebrew to install cpp-netlib and when I run an if(cppnetlib_FOUND) I know that it finds the package but it seems to not find the libraries so when I try to make my project it errors saying its missing the libraries from cpp-netlib. I also noticed that when I set the version to 0.11.2 (the currently installed version) in the FIND_PACKAGE I get a message saying
-- Boost version: 1.59.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
CMake Error at CMakeLists.txt:16 (FIND_PACKAGE):
Could not find a configuration file for package "cppnetlib" that is
compatible with requested version "0.11.2".
The following configuration files were considered but not accepted:
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
-- Configuring incomplete, errors occurred!
See also "/Users/LittleNewt/gitness/mangaMe/build/CMakeFiles/CMakeOutput.log".
Not a huge deal since it works when I explicitly specify the directories but would still like to know why I can't just use FIND_PACKAGE.
Try changing cppnetlib_INCLUDE_DIRS
to CPPNETLIB_INCLUDE_DIRS
and cppnetlib_LIBRARIES
to CPPNETLIB_LIBRARIES
.
The prefix doesn't go by the package name, but rather by what is exported in the package's CMake file. Here's the source that uses uppercase: https://github.com/cpp-netlib/cpp-netlib/blob/master/cppnetlibConfig.cmake.in