Premake5-generated xcode project does not see vcpkg-installed dependency

123 views Asked by At

Problem

src/main.cpp with "file not found" issue:

#include "spdlog/spdlog.h" //File not found

int main(int, char**) {
    spdlog::info("Welcome to spdlog!");
    return 0;
}

Background

I’m using vcpkg to install, say spdlog. I've put vcpkg as a submodule into vendor/packages using git submodule add -f https://github.com/Microsoft/vcpkg.git ./vendor/packages. Next, I bootstrap vcpkg, ./vendor/packages/bootstrap-vcpkg.sh. Now I'm able to add spdlog as a dependency by editing vcpkg.json. I then install the dependencies ./vendor/packages/vcpkg install --x-install-root=vendor/vcpkg-installed.

Finally, I make an xcode project ./vendor/bin/premake/premake5 xcode4.
premake5 version is 5.0.0-dev

premake5.lua:

workspace "Vulkan2"
   configurations { "Debug", "Release" }
   architecture "ARM64"
   location "./"

outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"

project "Vulkan2"
   kind "ConsoleApp"
   language "C++"
   targetdir ("bin/" .. outputdir .. "/%{prj.name}/")
   objdir ("bin-int/" .. outputdir .. "/%{prj.name}/")
   staticruntime "On"
   cppdialect "C++17"

   files { "%{wks.location}/src/**.h", "%{wks.location}/src/**.cpp"}

   includedirs{
    "%{wks.location}/vendor/vcpkg-installed/" .. "arm64-osx" .. "/include/",
    "%{wks.location}/vendor/vcpkg-installed/arm64-osx/include/spdlog/" --this may be overkill
   }
   externalincludedirs{
    "%{wks.location}/vendor/vcpkg-installed/" .. "arm64-osx" .. "/include/",
    "%{wks.location}/vendor/vcpkg-installed/arm64-osx/include/spdlog/"
   } 

   xcodebuildsettings = { ["ALWAYS_SEARCH_USER_PATHS"] = "YES",
   ["HEADER_SEARCH_PATHS"] = { "%{wks.location}/vendor/vcpkg-installed/" .. "arm64-osx" .. "/include/" }
  }

   links {"spdlog"}

   filter "configurations:Debug"
      defines { "DEBUG" }
      symbols "On"
      libdirs {"%{wks.location}/vendor/vcpkg-installed/" .. "arm64-osx" .. "/debug/lib/"}

   filter "configurations:Release"
      defines { "NDEBUG" }
      optimize "On"
      libdirs {"%{wks.location}/vendor/vcpkg-installed/" .. "arm64-osx" .. "/lib/"}

Curiously, I was able to generate a xcode project (without issues) with cmake by making a CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(Vulkan2)
find_package(spdlog CONFIG REQUIRED)
add_executable(Vulkan2 src/main.cpp)
target_link_libraries(Vulkan2 PRIVATE spdlog::spdlog)

Then, after installing dependencies with vcpkg, doing ./vendor/packages/vcpkg integrate install and then cmake -G Xcode -S . -B build -DCMAKE_TOOLCHAIN_FILE=/Users/erik/Dev/Projects/Vulkan2/vendor/packages/scripts/buildsystems/vcpkg.cmake, as vcpkg recommended doing for cmake projects.

Conclusion

So I'm looking to use premake5 to get a similarly working project as I had with cmake. Can premake5 generate projects without CMakeLists.txt? It would be great if I only had to list the dependencies in links{} and in vcpkg.json.

Is there an issue with my premake5.lua? Note that I have libdirs first appearing at the various configurations. Is that a problem for the links{spdlog} step?

Is there an equivalent way of specifying toolchain file with premake5, or does toolchain file not apply at all with premake5?

Update

I noticed that the non-framework libraries in the links{} section do not appear in the project’s “Frameworks and Libraries”. Does it mean the links step failed? If I add the libraries (fmt, glfw3, spdlog and vulkan) manually to the xcode project‘s “Frameworks and Libraries”, I get this error:

Ld /Users/erik/Dev/Projects/Vulkan2/bin/Debug-macosx-ARM64/Vulkan2/Vulkan2 normal (in target 'Vulkan2' from project 'Vulkan2')
    cd /Users/erik/Dev/Projects/Vulkan2
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Xlinker -reproducible -target arm64-apple-macos14.2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -O0 -L/Users/erik/Library/Developer/Xcode/DerivedData/Vulkan2-bjvzuhuwjwufmfaommqrpgnkatkb/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -L/Users/erik/Dev/Projects/Vulkan2/bin/Debug-macosx-ARM64/Vulkan2 -Lvendor/vcpkg-installed/arm64-osx/lib -L/Users/erik/Dev/Projects/Vulkan2/vendor/vcpkg-installed/arm64-osx/lib -F/Users/erik/Library/Developer/Xcode/DerivedData/Vulkan2-bjvzuhuwjwufmfaommqrpgnkatkb/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -F/Users/erik/Dev/Projects/Vulkan2/bin/Debug-macosx-ARM64/Vulkan2 -filelist /Users/erik/Library/Developer/Xcode/DerivedData/Vulkan2-bjvzuhuwjwufmfaommqrpgnkatkb/Build/Intermediates.noindex/Vulkan2.build/Objects-normal/arm64/Vulkan2.LinkFileList -dead_strip -Xlinker -object_path_lto -Xlinker /Users/erik/Library/Developer/Xcode/DerivedData/Vulkan2-bjvzuhuwjwufmfaommqrpgnkatkb/Build/Intermediates.noindex/Vulkan2.build/Objects-normal/arm64/Vulkan2_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -lspdlog -lglwf3 -lvulkan -lfmt -lspdlog -lfmt -framework Cocoa -lvulkan -framework IOKit -lglfw3 -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/erik/Library/Developer/Xcode/DerivedData/Vulkan2-bjvzuhuwjwufmfaommqrpgnkatkb/Build/Intermediates.noindex/Vulkan2.build/Objects-normal/arm64/Vulkan2_dependency_info.dat -o /Users/erik/Dev/Projects/Vulkan2/bin/Debug-macosx-ARM64/Vulkan2/Vulkan2

ld: warning: ignoring duplicate libraries: '-lfmt', '-lspdlog', '-lvulkan'
ld: library 'glwf3' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
0

There are 0 answers