Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include OpenSSL in a CMakeList.txt file

I have a question for people who work with CMakeList.txt in C++. I want to use Podofo project (a project to parse & create pdf).

So my main function is simple as:

#include <iostream>
#include <podofo/podofo.h>

int main() {
  PoDoFo::PdfMemDocument pdf;
  pdf.Load("/Users/user/path/to.pdf");

  int nbOfPage = pdf.GetPageCount();

  std::cout << "Our pdf have " << nbOfPage << " pages." << std::endl;
  return 0;
}

My CMakeList.txt is:

cmake_minimum_required(VERSION 3.7)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES main.cpp)

add_executable(untitled ${SOURCE_FILES})

But I am stuck with this error:

/usr/local/include/podofo/base/PdfEncrypt.h:44:10: fatal error: 'openssl/opensslconf.h' file not found
#include <openssl/opensslconf.h

I tried to include with find_package, find_library .. setting some variables but I do not find the way.

My env is:

  • macOS
  • Clion
  • Podofo installed via home-brew in /usr/local/podofo
  • OpenSSL installed via home-brew in /usr/local/opt/openssl

Thanks by advance community !!

like image 321
nodeover Avatar asked Aug 07 '17 13:08

nodeover


People also ask

What is Cmakelist txt file?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.

Where is CMakeLists TXT located?

CMakeLists. txt is placed at the root of the source tree of any application, library it will work for. If there are multiple modules, and each module can be compiled and built separately, CMakeLists. txt can be inserted into the sub folder.


1 Answers

find_package is the correct approach; you find details about it here.

In your case, you should add these lines:

find_package(OpenSSL REQUIRED)
target_link_libraries(untitled OpenSSL::SSL)

If CMake doesn't find OpenSSL directly, you should set the CMake variable OPENSSL_ROOT_DIR.

like image 118
oLen Avatar answered Oct 09 '22 23:10

oLen