简体   繁体   中英

Setting Ninja values through CMake (cross compilation)

I am currently trying to cross compile a program I wrote on macOS to Linux, and I have had to make some changes to the build.ninja file to make that possible (specifically the linker commands/other places where libraries are linked). However, this gets wiped when I reconfigure CMake. Is there a way that I could use CMake to set the values in my Ninja file instead of wherever they are being set from? I am also using vcpkg for this project with GCC 10.2.0 for x86_64 Linux. The ninja files had to be trimmed to fit under the character limit, I can find a different way to put up the complete ones if needed. Here are my current CMakeLists, the first being my top level one and the second being the one that links everything:

Removed to make room for edits, working file can be found in edit 2
# CMakeList.txt : CMake project for ImpromptuServer, include source and define
# project specific logic here.
#
cmake_minimum_required(VERSION 3.8)

add_subdirectory("database")
add_subdirectory("web")
add_subdirectory("api")
add_subdirectory("utils")

# Add source to this project's executable.
file(GLOB_RECURSE web ./web/*.cpp ./web/*.hpp)
file(GLOB_RECURSE database ./database/*.cpp ./datbase/*.hpp)
file(GLOB_RECURSE api ./api/*.cpp ./api/*.hpp)

add_library(libweb ${web})
add_library(libdata ${database})
add_library(libapi ${api})

add_executable(ImpromptuServer "ImpromptuServer.cpp" ${web} ${database} ${api})

set(ALL_LIBS Wt::Wt Wt::Dbo Wt::HTTP Wt::DboSqlite3 cryptopp-static json11 OpenSSL::SSL OpenSSL::Crypto cpr)

# TODO: Add tests and install targets if needed.
target_link_libraries(ImpromptuServer PRIVATE ${ALL_LIBS})
target_link_libraries(libweb PRIVATE Wt::Wt Wt::Dbo Wt::HTTP Wt::DboSqlite3)
target_link_libraries(libdata PRIVATE Wt::Wt Wt::Dbo Wt::HTTP Wt::DboSqlite3)
target_link_libraries(libapi PRIVATE ${ALL_LIBS})

I know GLOB_RECURSE is not best practice, but I don't want to change it unless it will fix my problem. Here is my original build.ninja file:

REMOVED due to irrelevancy to question.

Here is the one that I modified to get working:

REMOVED due to irrelevancy to question.

However, even when I compile successfully with the modified ninja file, I get this output message and the code fails to run on a Linux machine:

/Volumes/CaseSensitive/cross/lib/gcc/x86_64-linux/10.2.0/../../../../x86_64-linux/bin/ld: warning: cannot find entry symbol arch_paths_first; defaulting to 0000000000414000

The code runs fine when compiling for macOS and using the original build.ninja file.

Edit 1

After a lot of work, I have gotten CMake to use the toolchain file, but I still have a lingering problem where CMake can't find Threads::Threads . Here is my current CMakeLists.txt :

Working file can be found in edit 2

Here is the output message that I get:

[main] Configuring folder: ImpromptuServer 
[cmake] -- Found OpenSSL: /usr/lib/libcrypto.dylib   
[cmake] -- Found ZLIB: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libz.tbd (found version "1.2.11") 
[cmake] -- Found CURL: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libcurl.tbd (found version "7.64.1")  
[cmake] -- Configuring done
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] -- Generating done
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.
[main] Configuring folder: ImpromptuServer 
[proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=/Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake -DCMAKE_CROSSCOMPILING=True -Wno-dev -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/Volumes/CaseSensitive/cross/bin/x86_64-linux-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/Volumes/CaseSensitive/cross/bin/x86_64-linux-g++ -H/Users/jackhogan/Desktop/Code/C++/ImpromptuServer -B/Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] INFO Using Linux protocols
[cmake] -- Configuring done
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:331 (_add_executable):
[cmake]   Target "ImpromptuServer" links to target "Threads::Threads" but the target
[cmake]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[cmake]   target, or an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:20 (add_executable)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libapi" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:18 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libdata" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:17 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] CMake Error at /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake:360 (_add_library):
[cmake]   Target "libweb" links to target "Threads::Threads" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake]   ImpromptuServer/CMakeLists.txt:16 (add_library)
[cmake] 
[cmake] 
[cmake] -- Generating done
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.

Edit 2

Everything now configures correctly with this CMake file:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required(VERSION 3.8)
project (ImpromptuServer C CXX)

if(${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
    #set(CMAKE_TOOLCHAIN_FILE /Users/jackhogan/Desktop/Code/Utilities/vcpkg/scripts/buildsystems/vcpkg.cmake)
    set(LIB_DIR /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib)
    add_compile_options(-std=c++17)
    find_package(threads REQUIRED)
else()
    message(INFO " Using Linux protocols")
    if(NOT ${CMAKE_TOOLCHAIN_FILE} STREQUAL /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake)
        message(FATAL_ERROR " Incorrect toolchain file")
    endif()

    add_compile_options(-std=gnu++17)

    #set(CMAKE_TOOLCHAIN_FILE /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake)
    set(CMAKE_CROSSCOMPILING true)
    set(CMAKE_SYSTEM_NAME Linux)
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
    set(LIB_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/debug/lib)
    set(CMAKE_FIND_ROOT_PATH /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/debug/lib)
    set(CMAKE_SYSROOT /Volumes/CaseSensitive/cross/x86_64-linux/)

    # Find libraries, may be changed later
    set(wt_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/wt/)
    set(OPENSSL_INCLUDE_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/openssl)
    set(OPENSSL_ROOT_DIR /Volumes/CaseSensitive/cross/x86_64-linux/lib/)
    set(cryptopp_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/cryptopp/)
    set(cpr_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/cpr/)

    # Find pthread
    set(CMAKE_THREAD_LIBS_INIT /Volumes/CaseSensitive/cross/x86_64-linux/lib/libpthread.a)

    include_directories(/Volumes/CaseSensitive/cross/x86_64-linux/lib/)
    include_directories(/Volumes/CaseSensitive/cross/x86_64-linux/lib64/)
    include_directories(/Volumes/CaseSensitive/cross/x86_64-linux/include/)
    include_directories(/Volumes/CaseSensitive/cross/x86_64-linux/include/linux/)
    include_directories(/Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/)
    #include_directories(/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include)

    #set(Boost_NO_SYSTEM_PATHS true)
    #set(BOOST_INCLUDEDIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/boost/)
    #set(BOOST_LIBRARYDIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/debug/lib/)
    #add_link_options(-g -isysroot /Volumes/CaseSensitive/cross/x86_64-linux)
    find_package(boost REQUIRED)
    find_package(Threads REQUIRED)
endif()

# Install packages
find_package(wt REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(cryptopp CONFIG REQUIRED)
find_package(cpr CONFIG REQUIRED)

add_library(json11 STATIC IMPORTED)
set_target_properties(json11 PROPERTIES IMPORTED_LOCATION ${LIB_DIR}/libjson11.a)

# Include sub-projects.
add_subdirectory ("ImpromptuServer")

But I get a ton of errors like this:

[main] Building folder: ImpromptuServer 
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build --config Debug --target all -- -j 22
[build] [22/29   3% :: 0.087] Building CXX object ImpromptuServer/CMakeFiles/libapi.dir/api/internal/ios/AppStore.cpp.o
[build] [23/29   6% :: 0.091] Building CXX object ImpromptuServer/CMakeFiles/ImpromptuServer.dir/api/internal/ios/AppStore.cpp.o
[build] [24/29  10% :: 1.946] Building CXX object ImpromptuServer/CMakeFiles/ImpromptuServer.dir/web/pages/About.cpp.o
[build] FAILED: ImpromptuServer/CMakeFiles/ImpromptuServer.dir/web/pages/About.cpp.o 
[build] /Volumes/CaseSensitive/cross/bin/x86_64-linux-g++ --sysroot=/Volumes/CaseSensitive/cross/x86_64-linux/ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -I/Volumes/CaseSensitive/cross/x86_64-linux/lib -I/Volumes/CaseSensitive/cross/x86_64-linux/lib64 -isystem /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include -isystem /usr/local/include -isystem /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/openssl -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -std=gnu++17 -MD -MT ImpromptuServer/CMakeFiles/ImpromptuServer.dir/web/pages/About.cpp.o -MF ImpromptuServer/CMakeFiles/ImpromptuServer.dir/web/pages/About.cpp.o.d -o ImpromptuServer/CMakeFiles/ImpromptuServer.dir/web/pages/About.cpp.o -c ../ImpromptuServer/web/pages/About.cpp
[build] In file included from /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/bits/localefwd.h:40,
[build]                  from /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/string:43,
[build]                  from /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/bitset:47,
[build]                  from /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/Wt/WWebWidget.h:11,
[build]                  from /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/Wt/WInteractWidget.h:10,
[build]                  from /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/Wt/WContainerWidget.h:10,
[build]                  from ../ImpromptuServer/web/pages/About.hpp:3,
[build]                  from ../ImpromptuServer/web/pages/About.cpp:1:
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:52:23: error: 'uselocale' was not declared in this scope; did you mean 'setlocale'?
[build]    52 |   extern "C" __typeof(uselocale) __uselocale;
[build]       |                       ^~~~~~~~~
[build]       |                       setlocale
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:62:11: error: '__locale_t' does not name a type
[build]    62 |   typedef __locale_t  __c_locale;
[build]       |           ^~~~~~~~~~
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:69:26: error: '__c_locale' does not name a type
[build]    69 |   __convert_from_v(const __c_locale& __cloc __attribute__ ((__unused__)),
[build]       |                          ^~~~~~~~~~
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h: In function 'int std::__convert_from_v(const int&, char*, int, const char*, ...)':
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:75:5: error: '__c_locale' was not declared in this scope; did you mean '__cloc'?
[build]    75 |     __c_locale __old = __gnu_cxx::__uselocale(__cloc);
[build]       |     ^~~~~~~~~~
[build]       |     __cloc
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:100:28: error: '__old' was not declared in this scope
[build]   100 |     __gnu_cxx::__uselocale(__old);
[build]       |                            ^~~~~
[build] /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/x86_64-linux/bits/c++locale.h:100:33: error: '__gnu_cxx::__uselocale' cannot be used as a function
[build]   100 |     __gnu_cxx::__uselocale(__old);
[build]       |                                 ^

Edit 3

Here is my CMake output:

[main] Configuring folder: ImpromptuServer 
[driver] Removing /Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build/CMakeCache.txt
[driver] Removing /Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build/CMakeFiles
[proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=/Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake -DCMAKE_CROSSCOMPILING=True -Wno-dev -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/Volumes/CaseSensitive/cross/bin/x86_64-linux-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/Volumes/CaseSensitive/cross/bin/x86_64-linux-g++ -H/Users/jackhogan/Desktop/Code/C++/ImpromptuServer -B/Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 10.2.0
[cmake] -- The CXX compiler identification is GNU 10.2.0
[cmake] -- Checking whether C compiler has -isysroot
[cmake] -- Checking whether C compiler has -isysroot - yes
[cmake] -- Checking whether C compiler supports OSX deployment target flag
[cmake] -- Checking whether C compiler supports OSX deployment target flag - no
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: /Volumes/CaseSensitive/cross/bin/x86_64-linux-gcc - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Checking whether CXX compiler has -isysroot
[cmake] -- Checking whether CXX compiler has -isysroot - yes
[cmake] -- Checking whether CXX compiler supports OSX deployment target flag
[cmake] -- Checking whether CXX compiler supports OSX deployment target flag - no
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: /Volumes/CaseSensitive/cross/bin/x86_64-linux-g++ - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] INFO Using Linux protocols
[cmake] -- Found Boost: /usr/local/lib/cmake/Boost-1.72.0/BoostConfig.cmake (found version "1.72.0")  
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - not found
[cmake] -- Found Threads: TRUE  
[cmake] -- Found OpenSSL: /usr/lib/libcrypto.dylib   
[cmake] -- Found ZLIB: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libz.tbd (found version "1.2.11") 
[cmake] -- Found CURL: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libcurl.tbd (found version "7.64.1")  
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /Users/jackhogan/Desktop/Code/C++/ImpromptuServer/build
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.

After a week of trying to get this to work, I finally have a solution. The solution came from this answer. Here is my final working CMake file that can compile for both MacOS and Linux:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required(VERSION 3.8)
# Target-specific stuff to be done before creating the project
if(${USE_LINUX})
    # Prevents linker from not finding program entry point
    set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
endif()
project (ImpromptuServer CXX)

if(NOT ${USE_LINUX})
    message(INFO " Using MacOS protocols")
    if(NOT ${CMAKE_TOOLCHAIN_FILE} STREQUAL /Users/jackhogan/Desktop/Code/Utilities/vcpkg/scripts/buildsystems/vcpkg.cmake)
        message(FATAL_ERROR " Incorrect toolchain file")
    endif()
    set(LIB_DIR /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib)
    add_compile_options(-std=c++17)
    find_package(Threads REQUIRED)

else()
    message(INFO " Using Linux protocols")
    if(NOT ${CMAKE_TOOLCHAIN_FILE} STREQUAL /Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake)
        message(FATAL_ERROR " Incorrect toolchain file")
    endif()

    set(CMAKE_C_LINK_FLAGS "")
    set(CMAKE_CXX_LINK_FLAGS "")
    add_compile_options(-std=gnu++17)
    add_link_options(-Wl,--copy-dt-needed-entries)

    set(CMAKE_CROSSCOMPILING true)
    # Get rid of OSX SDK to prevent incorrect linking
    set(CMAKE_OSX_SYSROOT "/Volumes/CaseSensitive/cross/x86_64-linux/include/")

    set(LIB_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/debug/lib)
    set(CMAKE_FIND_ROOT_PATH /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/debug/lib)
    set(CMAKE_SYSROOT /)

    # Find libraries, may be changed later
    set(wt_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/wt/)
    set(cryptopp_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/cryptopp/)
    set(cpr_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/share/cpr/)

    set(OPENSSL_INCLUDE_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/openssl)
    set(OPENSSL_ROOT_DIR /Volumes/CaseSensitive/cross/x86_64-linux/lib/)
    # Cheat a little bit by linking a dynamic library
    set(OPENSSL_CRYPTO_LIBRARY /Volumes/CaseSensitive/cross/x86_64-linux/lib/libcrypto.a)
    set(OPENSSL_USE_STATIC_LIBS true)

    # Special system library include directories
    set(ZLIB_INCLUDE_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/)
    set(ZLIB_ROOT /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/lib/)
    set(CURL_INCLUDE_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/curl/)

    # Find pthread and link to non-apple
    set(CMAKE_THREAD_LIBS_INIT /Volumes/CaseSensitive/cross/x86_64-linux/lib/libpthread.a)

    # GCC includes
    include_directories(SYSTEM /Volumes/CaseSensitive/cross/lib/gcc/x86_64-linux/10.2.0/include/)
    # System includes
    include_directories(SYSTEM /Volumes/CaseSensitive/cross/x86_64-linux/include/c++/10.2.0/)

    #set(BOOST_INCLUDE_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/include/boost/)
    set(Boost_NO_BOOST_CMAKE on)
    set(Boost_USE_STATIC_LIBS true)
    set(Boost_LIBRARY_DIR /Volumes/CaseSensitive/vcpkgLinux/installed/x64-linux/lib/)
    find_package(Boost COMPONENTS program_options filesystem thread chrono date_time REQUIRED)
    find_package(Threads REQUIRED)
endif()

# Install packages
find_package(wt REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(cryptopp CONFIG REQUIRED)
find_package(cpr CONFIG REQUIRED)

add_library(json11 STATIC IMPORTED)
set_target_properties(json11 PROPERTIES IMPORTED_LOCATION ${LIB_DIR}/libjson11.a)

# Include sub-projects.
add_subdirectory ("ImpromptuServer")

While all of the paths are system-specific, this could be improved later with some more advanced scripting. Here are the arguments I pass in on MacOS and Linux respectively:

-DCMAKE_TOOLCHAIN_FILE=/Users/jackhogan/Desktop/Code/Utilities/vcpkg/scripts/buildsystems/vcpkg.cmake -DUSE_LINUX=false
-DCMAKE_TOOLCHAIN_FILE=/Volumes/CaseSensitive/vcpkgLinux/scripts/buildsystems/vcpkg.cmake -DUSE_LINUX=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM