janbar / openssl-cmake

Build OpenSSL with CMake on MacOS, Win32, Win64 and cross compile for Android, IOS
Other
267 stars 138 forks source link

Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) #26

Open brandonros opened 2 years ago

brandonros commented 2 years ago
cmake_minimum_required(VERSION 3.5.1)
project(j2534-rpc)
set(CMAKE_CXX_STANDARD 11)
# architecture
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  set(ARCHITECTURE_SLUG "x64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  set(ARCHITECTURE_SLUG "ia32")
endif()
# variables
set(MSGPACK_USE_BOOST OFF CACHE BOOL "")
# dependencies
add_subdirectory("deps/msgpack-c")
add_subdirectory("deps/openssl-cmake")
add_subdirectory("deps/curl")
# diag test
add_executable(j2534-rpc-diag-test-${ARCHITECTURE_SLUG} SHARED j2534-rpc-diag-test.cpp)
target_link_libraries(j2534-rpc-diag-test-${ARCHITECTURE_SLUG} curl msgpack)
Brandons-MacBook-Air:j2534-rpc-js brandonros 2022-02-19 19:11:44 $ rm -rf output && cmake -S . -B "output"
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Doxygen: /opt/homebrew/bin/doxygen (found version "1.9.3") found components: doxygen missing components: dot
-- OpenSSL version 1.1.1m
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of long
-- Check size of long - done
-- Check size of long long
-- Check size of long long - done
-- Check size of int
-- Check size of int - done
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- curl version=[7.82.0-DEV]
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_ADDR
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_ADDR - Success
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID - Success
-- Found Perl: /usr/bin/perl (found version "5.30.3") 
-- Looking for dlopen in ;-framework SystemConfiguration
-- Looking for dlopen in ;-framework SystemConfiguration - found
-- Looking for connect in socket;-framework SystemConfiguration
-- Looking for connect in socket;-framework SystemConfiguration - not found
-- Looking for gethostbyname in c
-- Looking for gethostbyname in c - found
-- Looking for gethostname
-- Looking for gethostname - found
CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
  OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/FindOpenSSL.cmake:574 (find_package_handle_standard_args)
  deps/curl/CMakeLists.txt:436 (find_package)

-- Configuring incomplete, errors occurred!
See also "/Users/brandonros/Desktop/j2534-rpc-js/output/CMakeFiles/CMakeOutput.log".
See also "/Users/brandonros/Desktop/j2534-rpc-js/output/CMakeFiles/CMakeError.log".
Brandons-MacBook-Air:j2534-rpc-js brandonros 2022-02-19 19:12:02 $ 
janbar commented 2 years ago

Because your sub project(s) check it with "find_package(OpenSSL)". So you need to setup it:

...
add_subdirectory("deps/openssl-cmake")
set(OPENSSL_SSL_LIBRARY ssl)
set(OPENSSL_CRYPTO_LIBRARY crypto)
set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
set(OPENSSL_FOUND ON)
message(STATUS "Build OpenSSL: ${openssl_BINARY_DIR}")
...
brandonros commented 2 years ago
-- Looking for ldap_init in ldap;-framework SystemConfiguration;-framework CoreFoundation;OpenSSL::SSL;OpenSSL::Crypto
CMake Error at /Users/brandonros/Desktop/j2534-rpc-js/output/CMakeFiles/CMakeTmp/CMakeLists.txt:15 (add_executable):
  Target "cmTC_30b46" links to target "OpenSSL::SSL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /Users/brandonros/Desktop/j2534-rpc-js/output/CMakeFiles/CMakeTmp/CMakeLists.txt:15 (add_executable):
  Target "cmTC_30b46" links to target "OpenSSL::Crypto" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/CheckLibraryExists.cmake:72 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  deps/curl/CMake/Macros.cmake:30 (check_library_exists)
  deps/curl/CMakeLists.txt:586 (check_library_exists_concat)

-- Configuring incomplete, errors occurred!
brandonros commented 2 years ago
cmake_minimum_required(VERSION 3.5.1)
project(j2534-rpc)
set(CMAKE_CXX_STANDARD 11)
# architecture
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  set(ARCHITECTURE_SLUG "x64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  set(ARCHITECTURE_SLUG "ia32")
endif()
# variables
set(MSGPACK_USE_BOOST OFF CACHE BOOL "")
# msgpack
add_subdirectory("deps/msgpack-c")
# openssl
add_subdirectory("deps/openssl-cmake")
set(OPENSSL_SSL_LIBRARY ssl)
set(OPENSSL_CRYPTO_LIBRARY crypto)
set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
set(OPENSSL_FOUND ON)
message(STATUS "Build OpenSSL: ${openssl_BINARY_DIR}")
# curl
add_subdirectory("deps/curl")
# diag test
add_executable(j2534-rpc-diag-test-${ARCHITECTURE_SLUG} j2534-rpc-diag-test.cpp)
target_link_libraries(j2534-rpc-diag-test-${ARCHITECTURE_SLUG} curl msgpack)
brandonros commented 2 years ago
Brandons-MacBook-Air:j2534-rpc-js brandonros 2022-02-20 13:20:44 $ uname -a
Darwin Brandons-MacBook-Air.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101 arm64
brandonros commented 2 years ago

It's the add_subdirectory("deps/curl") line causing it.

janbar commented 2 years ago

Try adding the following , before add of deps/curl:

add_library(OpenSSL::Crypto ALIAS crypto) add_library(OpenSSL::SSL ALIAS ssl)

Also see: https://cmake.org/cmake/help/v3.6/module/FindOpenSSL.html Probably we will have to add these lines in the project "openssl" itself ... if that works for you

edit: Yep looking in this issue: https://github.com/janbar/openssl-cmake/issues/23#issuecomment-924661972 , that should resolve your issue

brandonros commented 2 years ago

Nope, no luck. I think it's something to do with Mac/Darwin. It isn't happening to me on Windows. Maybe colliding with some local installation of libcurl-dev I have somewhere with Mac OS X by default or brew or something? Really no clue.

cmake_minimum_required(VERSION 3.5.1)
project(j2534-http)
set(CMAKE_CXX_STANDARD 11)
# architecture
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  set(ARCHITECTURE_SLUG "x64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  set(ARCHITECTURE_SLUG "ia32")
endif()
# msgpack
set(MSGPACK_USE_BOOST OFF CACHE BOOL "")
add_definitions(-DMSGPACK_NO_BOOST)
add_subdirectory("deps/msgpack-c")
include_directories("deps/msgpack-c/include")
# openssl
add_subdirectory("deps/openssl-cmake")
set(OPENSSL_SSL_LIBRARY ssl)
set(OPENSSL_CRYPTO_LIBRARY crypto)
set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
set(OPENSSL_FOUND ON)
message(STATUS "Build OpenSSL: ${openssl_BINARY_DIR}")
# curl
add_library(OpenSSL::Crypto ALIAS crypto)
add_library(OpenSSL::SSL ALIAS ssl)
add_subdirectory("deps/curl")
include_directories("deps/curl/include")
# libconfig
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
set(BUILD_TESTS OFF CACHE BOOL "")
set(BUILD_EXAMPLES OFF CACHE BOOL "")
add_subdirectory("deps/libconfig")
include_directories("deps/libconfig/lib")
# diag test
add_executable(j2534-http-diag-test-${ARCHITECTURE_SLUG} diag/log.cpp diag/api.cpp diag/j2534-http-diag-test.cpp)
target_link_libraries(j2534-http-diag-test-${ARCHITECTURE_SLUG} libcurl msgpackc-cxx)
# diag
add_library(j2534-http-diag-${ARCHITECTURE_SLUG} SHARED diag/log.cpp diag/api.cpp diag/structs.cpp diag/j2534-http-diag.cpp)
target_link_libraries(j2534-http-diag-${ARCHITECTURE_SLUG} libcurl msgpackc-cxx libconfig)
Brandons-MacBook-Air:j2534-http brandonros 2022-02-20 22:37:59 $ cmake -S . -B "output" && cmake --build output --config Debug
-- OpenSSL version 1.1.1m
-- Build OpenSSL: /Users/brandonros/Desktop/j2534-http/output/deps/openssl-cmake
-- curl version=[7.82.0-DEV]
-- Looking for ber_init in lber;-framework SystemConfiguration;-framework CoreFoundation;OpenSSL::SSL;OpenSSL::Crypto
CMake Error at /Users/brandonros/Desktop/j2534-http/output/CMakeFiles/CMakeTmp/CMakeLists.txt:15 (add_executable):
  Target "cmTC_fab92" links to target "OpenSSL::SSL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /Users/brandonros/Desktop/j2534-http/output/CMakeFiles/CMakeTmp/CMakeLists.txt:15 (add_executable):
  Target "cmTC_fab92" links to target "OpenSSL::Crypto" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/CheckLibraryExists.cmake:72 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  deps/curl/CMake/Macros.cmake:30 (check_library_exists)
  deps/curl/CMakeLists.txt:587 (check_library_exists_concat)

-- Configuring incomplete, errors occurred!
See also "/Users/brandonros/Desktop/j2534-http/output/CMakeFiles/CMakeOutput.log".
See also "/Users/brandonros/Desktop/j2534-http/output/CMakeFiles/CMakeError.log".
Brandons-MacBook-Air:j2534-http brandonros 2022-02-20 22:38:43 $ 
xzores commented 7 months ago

Hey still a problem for me

MhouneyLH commented 7 months ago

I still have the same problem on windows with the version 3.27.0-rc2. Is there any other solution?

HUNT3Rdotme commented 7 months ago

Same issue with Ubuntu 22.04.3 via WSL trying to build the toolchain for SerenityOS.

Cross-posting to the Serenity repo.