Issue
I'd like to preface this that I am relatively new to CMake but even more of a newcomer when it comes down to cross-compiling. I am able to do simple programs, with my own libraries with no problem. However I run into issues trying to include external libraries.
I am currently operating a machine that is running x86-64 w/ Debian (ergo Linux). Prior to this I would originally operate through visual studio to compile my programs but I have moved on from Windows entirely after my discovery of cross compilation. If possible, I would like to avoid VMs all together for development and would rather have it reserved as a way to only debug. This is why I would rather go through learning CMake and not compile natively, even if it is more difficult.
I have successfully compiled a windows program with #include <windows.h> using x86_64-w64-mingw32-g++ successfully. However, my problem involves when it comes to external headers.
I have gone through the steps of creating my own relevant triplet file. To begin, I would like to create static libraries just to simplify things. This has worked for simple things that require no external libraries, creating .exe executable (however I have no tried running them to see if they actually work because I am lazy but they probably do since they compiled w/ no errors).
"custom.cmake" - My triplet file
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Windows)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /home/undulating/Programming/C++/CrossCompile/cross.cmake)
#This does not alleviate the issue of installing custom:curl via vcpkg, logs still say it cannot find openssl.
set(OPENSSL_ROOT_DIR ~/Manual_Programs/vcpkg/installed/custom/include/openssl)
It should also be noted that I have installed openssl with both
sudo apt install libssl-dev
Not sure if this will work since I am targeting windows, not linux; but I wanted to shoot my shot anyway.
vcpkg install openssl:custom
vcpkg integrate
It should also be noted that vcpkg had successfully installed openssl with no errors.
However to my issue, I have a windows program that requires libcurl (#include curl/curl.h>).
So I tried to install curl via
vcpkg install curl:custom
Then we come to the initial error from vcpkg:
error: building curl:custom failed with: BUILD_FAILED
vcpkg stdout
Building curl[core,non-http,openssl,ssl]:custom...
-- Using cached curl-curl-curl-7_84_0.tar.gz.
-- Cleaning sources at /home/undulating/Manual_Programs/vcpkg/buildtrees/curl/src/url-7_84_0-fad13a6c94.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source /home/undulating/Manual_Programs/vcpkg/downloads/curl-curl-curl-7_84_0.tar.gz
.
.
.
-- Configuring custom
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:96 (message):
Command failed: /home/undulating/Manual_Programs/vcpkg/downloads/tools/ninja/1.10.2-linux/ninja -v
Working Directory: /home/undulating/Manual_Programs/vcpkg/buildtrees/curl/custom-rel/vcpkg-parallel-configure
Error code: 1
See logs for more information:
/home/undulating/Manual_Programs/vcpkg/buildtrees/curl/config-custom-CMakeCache.txt.log
/home/undulating/Manual_Programs/vcpkg/buildtrees/curl/config-custom-CMakeCache.txt.log
/home/undulating/Manual_Programs/vcpkg/buildtrees/curl/config-custom-out.log
Call Stack (most recent call first):
installed/x64-linux/share/vcpkg-cmake/vcpkg_cmake_configure.cmake:246 (vcpkg_execute_required_process)
ports/curl/portfile.cmake:80 (vcpkg_cmake_configure)
scripts/ports.cmake:147 (include)
Then we read config-custom-out.log...
CMake Error at /home/undulating/Manual_Programs/vcpkg/downloads/tools/cmake-3.24.0-linux/cmake-3.24.0-linux-x86_64/share/cmake-3.24/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):
/home/undulating/Manual_Programs/vcpkg/downloads/tools/cmake-3.24.0-linux/cmake-3.24.0-linux-x86_64/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/home/undulating/Manual_Programs/vcpkg/downloads/tools/cmake-3.24.0-linux/cmake-3.24.0-linux-x86_64/share/cmake-3.24/Modules/FindOpenSSL.cmake:599 (find_package_handle_standard_args)
/home/undulating/Manual_Programs/vcpkg/installed/custom/share/openssl/vcpkg-cmake-wrapper.cmake:37 (_find_package)
/home/undulating/Manual_Programs/vcpkg/scripts/buildsystems/vcpkg.cmake:788 (include)
CMakeLists.txt:438 (find_package)
After seeing such a thing, I decided it was best to do what it said and find out how I can incorporate the toolchain to mention openssl or something. Which I had done as you can see in my custom.cmake.
set(OPENSSL_ROOT_DIR ~/Manual_Programs/vcpkg/installed/custom/include/openssl)
This is the toolchain file: cross.cmake
"set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
#include openssl?
#set(OPENSSL_ROOT_DIR ~/Manual_Programs/vcpkg/installed/custom/include/openssl)
#end openssl
# where is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/bin/x86_64-w64-mingw32-g++
/home/undulating/Programming/C++/CrossCompile/cross.cmake)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-- Configuring incomplete, errors occurred!
.
.
.
"/home/undulating/Manual_Programs/vcpkg/downloads/tools/cmake-3.24.0-linux/cmake-3.24.0-linux-x86_64/bin/cmake" -E chdir "../../custom-dbg" "/home/undulating/Manual_Programs/vcpkg/downloads/tools/cmake-3.24.0-
linux/cmake-3.24.0-linux-x86_64/bin/cmake" "/home/undulating/Manual_Programs/vcpkg/buildtrees/curl/s rc/url-7_84_0-fad13a6c94.clean" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_INSTALL_PREFIX=/home/undulating/Manual_Programs/vcpkg/packages/curl_custom/debug" "-DCMAKE_PROJECT_INCLUDE=/home/undulating/Manual_Programs/vcpkg/ports/curl/cmake-project-include.cmake" "-DUSE_NGHTTP2=OFF" "-DCURL_USE_WOLFSSL=OFF" "-D
CURL_USE_OPENSSL=ON" "-DCURL_USE_MBEDTLS=OFF" "-DCURL_USE_LIBSSH2=OFF" "-DBUILD_CURL_EXE=OFF" "-DENABLE_ARES=OFF" "-DCURL_WINDOWS_SSPI=OFF" "-DCURL_BROTLI=OFF" "-DCURL_USE_SCHANNEL=OFF" "-DCURL_USE_SECTRANSP=OFF" "-DUSE_LIBIDN2=OFF" "-DUSE_WIN32_IDN=OFF"
"-DUSE_WIN32_LDAP=OFF" "-DHTTP_ONLY=OFF" "-DCURL_DISABLE_LDA P=ON" "-DBUILD_TESTING=OFF" "-DENABLE_MANUAL=OFF" "-DCURL_CA_FALLBACK=ON" "-DCURL_USE_LIBPSL=OFF" "-DCMAKE_MAKE_PROGRAM=/home/undulating/Manual_Programs/vcpkg/downloads/tools/ninja/1.10.2-linux/ninja"
"-DCMAKE_SYSTEM_NAME=Windows" "-DBUILD_SHARED_LIBS=OFF" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/undulating/Program ming/C++/CrossCompile/cross.cmake" "-DVCPKG_TARGET_TRIPLET=custom" "-DVCPKG_SET_CHARSET_FLAG=ON" "-DVCPKG_PLATFORM_TOOLSET=external"
"-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=T RUE"
"-DCMAKE_VERBOSE_MAKEFILE=ON" "-DVCPKG_APPLOCAL_DEPS=OFF" "-DCMAKE_TOOLCHAIN_FILE=/home/undulating/Manual_Programs/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" "-DVCPKG_CXX_FLAGS="
"-DVCPKG_CXX_FLAGS_RELEASE=" "-DVCPKG_CXX_FLAGS_DEBUG=" "-DVCPKG_C_FLAGS=" "-DVCPKG _C_FLAGS_RELEASE=" "-DVCPKG_C_FLAGS_DEBUG=" "-DVCPKG_CRT_LINKAGE=static"
"-DVCPKG_LINKER_FLAGS=" "-DVCPKG_LINKER_FLAGS_RELEASE=" "-DVCPKG_LINKER_FLAGS_DEBUG=" "-DVCPKG_TARGET_ARCHITECTURE=x64" "-DCMAKE_INSTALL_LIBDIR:STRING=lib" "-DCMAKE_INSTALL_BINDIR:STRING=bin" "-D_VCPKG_ROOT_DIR=/home/undulating/Manual_Program s/vcpkg"
"-D_VCPKG_INSTALLED_DIR=/home/undulating/Manual_Programs/vcpkg/installed" "-DVCPKG_MANIFEST_INSTALL=OFF" "-DENABLE_DEBUG=ON"
FAILED: ../../custom-dbg/CMakeCache.txt
...
There is a little bit more technical detail of course, but I cannot post them due to it being seen as spam by stackoverflow.
As you can see, it calls for other options in the toolchain (root locations, architecture, name of triplet), but no mention of including openssl at all.
This seems to have done nothing (not make things better or worse), the logs have no mention of OPENSSL in the logs. Replicated the same exact error as well. So cmake did recognize it as a legitamate option because otherwise it would throw an error not recognizing it, right? This is the most confusing part for me.
So I then decided that perhaps this required it to be in the toolchain rather than the triplet (keep in mind I kept it in the triplet because it didn't seem like it would matter anyway).
and it proceeded to do the same exact thing once again.
I am not sure what to do, my goals are to cross compile with cmake and use installed packages for the target environment with a triplet that targets a toolchain for that architecture. Other tutorials mention setting the variable in the cmake file but this involves vcpkg that has quadrillions of *.cmake files so I have no idea where to put it.
Thanks again. I know this is a bit much but I hope I could clarify my point from the get-go.
Solution
I ended up discarding creating my own triplet and used the community 84 bit triplet for MinGW. While this also hasn't been trouble-free either, I did get a lot further than trying to make my own triplet and toolchain.
Answered By - Undulating Aether Answer Checked By - Marie Seifert (WPSolving Admin)