1

I installed the latest version of OpenSSL (1.0.2q) via macports and I'm trying to build a project on my mac that depends on OpenSSL and found that CMake seems to be returning the wrong library path or the wrong include path:

message("@@@")
message(${OPENSSL_INCLUDE_DIR})
message(${OPENSSL_SSL_LIBRARY})
message("/@@@")

prints:

@@@
/opt/local/include
/usr/lib/libssl.dylib
/@@@

So it gives me headers for OpenSSL from macports and the library from system.

I found this because building an external library fails with linking errors:

Undefined symbols for architecture x86_64:
  "_X509_check_host", referenced from:
      _ma_tls_verify_server_cert in libmariadbclient.a(openssl.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I make CMake find and use macports libraries only?

ruipacheco
  • 15,025
  • 19
  • 82
  • 138
  • As in a [general case](https://stackoverflow.com/questions/16248775/cmake-not-able-to-find-openssl-library), you may try to set **environment** variable `OPENSSL_ROOT_DIR` to `/opt/local`. Note, that it could be quite tricky to "hide" the library under system directory `/usr/lib` from the linker and from the runtime loader. Normally, CMake warns about such situations. – Tsyvarev Dec 27 '18 at 19:32
  • Didn't work: -- SSL support: OPENSSL Libs: /usr/lib/libssl.dylib;/usr/lib/libcrypto.dylib – ruipacheco Dec 27 '18 at 19:45
  • 1
    Have you cleared the cache before new attempt? – Tsyvarev Dec 27 '18 at 19:46
  • 1
    No, and now it works. Turn this into an answer so I can accept it. – ruipacheco Dec 27 '18 at 19:58

1 Answers1

2

You may hint CMake about OpenSSL location with OPENSSL_ROOT_DIR environment variable (not CMake variable!) by setting it to /opt/local. Other ways of hints, described in CMake not able to find OpenSSL library could also work.


Note, that it could be quite tricky to "hide" the library under system directory /usr/lib from the linker and from the runtime loader. This is because other libraries, used by a project, can be located in that directory, and which may prevent CMake to build correct directories list for pass to the linker or for assign to RPATH. Normally, CMake warns about such situations.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153