premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

Cannot set default project scheme in Xcode #1237

Closed macsforme closed 5 years ago

macsforme commented 5 years ago

It is desirable to be able to determine which project scheme is selected by default when generating Xcode project files. I don't believe that the startproject option ever worked for Xcode, but I was able to do it with a workaround by reordering my project definitions so that the project I wanted to be the default was declared first in the premake scripts. This snippet of code shows how it was set up so that the main executable would come up as the start project in Xcode

  -- set up the build (build order/dependencies are honored notwithstanding the
  -- listed order here; this order is how we want the projects to show up in
  -- the IDEs since the startproject option isn't fully supported)
  if not _OPTIONS["disable-client"] then include "src/bzflag" end
  if not _OPTIONS["disable-server"] then include "src/bzfs" end
  if not _OPTIONS["disable-bzadmin"] then include "src/bzadmin" end
  if not _OPTIONS["disable-client"] then include "src/3D" end
  include "src/common"
  include "src/date"
  include "src/game"
  if not _OPTIONS["disable-client"] then include "src/geometry" end
  if not _OPTIONS["disable-client"] then include "src/mediafile" end
  include "src/net"
  include "src/obstacle"
  if not _OPTIONS["disable-client"] then include "src/ogl" end
  if not _OPTIONS["disable-client"] then include "src/platform" end
  if not _OPTIONS["disable-client"] then include "src/scene" end
  if not _OPTIONS["disable-plugins"] and not _OPTIONS["disable-server"] then include "plugins" end
  if _TARGET_OS == "windows" and
     not _OPTIONS["disable-client"] and
     not _OPTIONS["disable-server"] and
     not _OPTIONS["disable-bzadmin"] and
     not _OPTIONS["disable-plugins"] and
     not _OPTIONS["disable-installer"] then
    include "package/win32/nsis" -- for man2html, makehtml, and installer
  end

This used to create a workspace laid out like this:

screen shot 2019-02-04 at 1 57 05 am 2

As of c92c7a595ee7e8a19f30bc1cb37451a9208538e3 by @tvandijck, the first project specified in the premake scripts no longer appears at the top and is no longer selected by default. Now, we have this:

screen shot 2019-02-04 at 1 58 32 am 2

So as you can see, the list of schemes in the drop-down menu doesn't mirror the list of projects in the sidebar (not before, and not now). I'm not sure what causes the schemes to generate in the order that they do (maybe something to do with dependencies between them). Digging into the BZFlag.xcworkspace/contents.xcworkspacedata file for both versions, it looks like prior to the above commit, projects were listed in the workspace file in the order that they were specified in the premake scripts, and subsequent to the above commit, projects seem to be listed in the workspace file in alphabetical order. The other consistent element seems to be that the very first project listed in the workspace file is the one that is selected by default when you first open the workspace.

It would be a big help to be able to set the start project in Xcode to save a step (and possible confusion) after generating the project files. Looking at the Visual Studio solution code here, it looks like startproject is implemented simply by reordering of certain elements. Is it possible to do this in Xcode using similar means, since we apparently just need to have the start project appear first in the workspace file?

I can try my hand at doing the implementation, if I can just get a bit of guidance.

samsinsane commented 5 years ago

I think you would just need to add a similar reorderProjects function into this list call array before m.workspaceFileRefs: https://github.com/premake/premake-core/blob/339a5f6f83ea8457804f945caec7f0987a20e405/modules/xcode/xcode4_workspace.lua#L18-L25

I can't imagine the function needing to be overly different, give the sln2005 one a whirl?