Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake set start path for FIND_PACKAGE?

Tags:

c++

cmake

I am using a newer verion of openssl that I installed through Homebrew on my Mac and was wondering if there was a way to set a start path for CMAKE's FIND_PACKAGE function? Right now when I attempt to using FIND_PACKAGE CMAKE finds and older version of openssl that is used by my OS. I am currently using this in my CMakeLists.txt

SET(OPENSSL_LIB_DIR /usr/local/Cellar/openssl/1.0.2f/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/openssl/1.0.2f/include)
TARGET_LINK_LIBRARIES(mangaMe ${OPENSSL_LIB_DIR}/libcrypto.dylib ${OPENSSL_LIB_DIR}/libssl.dylib)

The only issue I have with this is that if my openssl updates I have to manually update the version in the path. I have tried reading over the CMAKE FIND_PACKAGE documentation but am not sure which of the many PATH variables I would use to get the effect I am looking for.

like image 680
Jem4687 Avatar asked Feb 22 '16 05:02

Jem4687


2 Answers

You can either set OPENSSL_ROOT_DIR cmake variable or OPENSSL_ROOT_DIR env variable to the following path: /usr/local/Cellar/openssl/* and then use find_package. Example:

set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
like image 124
ixSci Avatar answered Nov 04 '22 17:11

ixSci


You can use OPENSSL_ROOT_DIR before calling FindOpenSSL:

set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/1.0.2f/)
include(FindOpenSSL)
like image 42
Guillaume Avatar answered Nov 04 '22 17:11

Guillaume