-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: Toolchain fixes #631
base: master
Are you sure you want to change the base?
Conversation
# If author request generate iso file, then prepare the command here. | ||
if(GEN_XISO) | ||
set(XISO_OUTPUT "${NXDK_DIR}/tools/extract-xiso/build/extract-xiso" -c "$<TARGET_FILE_DIR:${ARGV0}>/bin" "$<TARGET_FILE_DIR:${ARGV0}>/${GEN_XISO}") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to leave XISO out of this. It also doesn't feel CMake-ish.
It also doesn't handle a common use-case where a user will want to selectively add more files to the XISO; so this will need a better design.
Also, if we support GEN_XISO
now, then we can't remove it without breaking projects.
As nxdk matures, we should avoid breakage like that.
In my own CMake work I just created another CMake function but I believe I still did XISO creation manually in a shell script for flexibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the concept of making it as CMake function which I now notice from your link. Initially I'm following how makefile handling things which currently use GEN_XISO
. If preferred the change to CMake function, I'll be happily change it. Yet may need to preserve backward compatibility for the change from make to CMake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet may need to preserve backward compatibility for the change from make to CMake?
I don't think so.
Users who move from the makefile to CMake will have to change their code anyway, so they can add the function call themselves.
I believe the original nxdk makefile (for use outside of nxdk internally) will also be retired eventually, and users who still want to use a makefile can use their own OR find some build-system they like (which doesn't have to be CMake).
Also see my work on autoconf etc. - while CMake support is part of nxdk, it's trivial to use other build-systems after the existing refactors to the build-system (which only added CMake, for better or worse)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there opened ticket discussed about it and/or have list of tasks for moving away from original nxdk makefile to have it done through toolchain script? I am currently unable to find the information in the repository. If there is or isn't, it will be helpful to follow through guideline to make a working toolchain as possible and have tasks done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xiso creation is one of those - it gives very little control over the end result (on-disc layout, non-1:1 directory mapping etc.), and technically isn't required to get something running on the Xbox, so imho we can leave that out the CMake toolchain file. It's still frequently used for quick emulator testing, so my suggestion would be to have a wiki entry "Creating an xiso from CMake" or something that supplies code that can just be dropped in.
In summary, it's better off to perform xiso creation from application preferred target's POST_BUILD process with CMake's add_custom_command function; via nxdk wiki CMake's getting started/howto.
@@ -19,7 +26,7 @@ set(WIN32 1) | |||
set(NXDK 1) | |||
|
|||
set(CMAKE_C_COMPILER "${NXDK_DIR}/bin/${TOOLCHAIN_PREFIX}-cc") | |||
set(CMAKE_C_STANDARD_LIBRARIES "${NXDK_DIR}/lib/libwinapi.lib ${NXDK_DIR}/lib/xboxkrnl/libxboxkrnl.lib ${NXDK_DIR}/lib/libxboxrt.lib ${NXDK_DIR}/lib/libpdclib.lib ${NXDK_DIR}/lib/libnxdk_hal.lib ${NXDK_DIR}/lib/libnxdk.lib ${NXDK_DIR}/lib/nxdk_usb.lib") #"${CMAKE_CXX_STANDARD_LIBRARIES_INIT}" | |||
set(CMAKE_C_STANDARD_LIBRARIES "${NXDK_DIR}/lib/libwinapi.lib ${NXDK_DIR}/lib/xboxkrnl/libxboxkrnl.lib ${NXDK_DIR}/lib/libxboxrt.lib ${NXDK_DIR}/lib/libpdclib.lib ${NXDK_DIR}/lib/libnxdk_hal.lib ${NXDK_DIR}/lib/libnxdk.lib ${NXDK_DIR}/lib/nxdk_usb.lib ${NXDK_DIR}/lib/libnxdk_net.lib") #"${CMAKE_CXX_STANDARD_LIBRARIES_INIT}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why networking would be part of the C standard.
Applications which want to use this, should add it explicitly.
Also see https://github.com/JayFoxRox/nxdk/pull/84/files#r611210118
Once nxdk has winsock, that could also take care of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NXDK_NET option is dropped, so it is always included. See #575 pull request changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a good reason why it should always be linked (for CMake and the legacy nxdk "build-application"-makefile alike). But good reasons to always build it (as part of the nxdk "build-toolchain"-makefile).
I can only speculate, but I assume the intention in #575 was to always build the lib, so the nxdk makefile is used for actually building nxdk (= libraries usable by pkg-config / CMake / ..), instead of building a single application (= decision which libraries to include); the PR description says:
To make building the libraries easier, the network code is now always built.
Maybe @thrimbor can clarify?
I believe, in your case, the CMake user should now choose which libraries to include (but CMake will take care of the standard library, hence you need to specify those and dependencies for the C/C++ standard).
The fewer symbols our CMake brings, the better (smaller binaries, faster linking, less symbol name collisions, easier to customize your drivers/backends).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small thing I would like to add into JayFoxRox's comment. If download source code repo without build nxdk via make. Then use CMake, the toolchain, to build user's application will not setup the necessary build files due to nxdk did not get built. I took a punch in my own eye not realizing this and didn't think about build nxdk via make. Mainly because I thought it was already handled through nxdk's makefile from the toolchain script. I was completely wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in #575 regarding building were mostly to simplify building nxdk itself - adjusting compiler flags and include directories based on make vars is a hot mess when building the libraries.
Regarding the change above, I think I'm ok with it for now. Ultimately I'd like to see a winsock library (next lwIP release should hopefully bring us closer to being able to implement this), and then we can have a ws2_32.lib
that I'd expect the user to have to explicitly specify, which can then pull in the other networking libraries via #pragma comment(lib,"libnxdk_net.lib")
(this is done a lot on Windows). Atm our messy buildsystem relies on dependencies being explicit, so we can't really utilize this as long as we have a makefile that's expected to handle both building nxdk itself and applications.
In the long term I'd like to see the low-level networking and USB libs removed from the standard libs and have them explicitly linked against if the app touches low-level stuff directly, or automatically pulled in by higher level libraries that are explicitly specified by the user such as SDL or winsock. But as long as we can't have that, imho linking them in might be the lesser of two evils.
endif() | ||
|
||
# If custom title is not given, use given executable name. | ||
if(NOT XBE_TITLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this variable name needs a prefix to not clash with user variables in CMake?
There's probably some convention for this in CMake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only triggered when user call add_executable function. Though, I will check with forked NevolutionX repo with fixed CMake support to be sure it doesn't return back to user's CMakeList. It may also apply to GEN_XISO
variable too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm XBE_TITLE is stored back into user's CMakeList, will need to make a fix for this.
concept fix:
if(NOT XBE_TITLE)
set(<prefix>_XBE_TITLE ${ARGV0})
else()
set(<prefix>_XBE_TITLE ${XBE_TITLE})
endif()
As for prefix, not sure if we should use NXDK or CMAKE prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for _NXDK_XBE_TITLE
, the leading underscore seems to be convention in CMake for variables that are considered internal to a module.
Could we also do an unset
when we're done with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also do an
unset
when we're done with it?
That's the plan. I must had forgot to mentioned that in my previous comment.
set_target_properties(SDL2::SDL2 PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" | ||
INTERFACE_LINK_LIBRARIES "${SDL2_LINK_LIBRARIES}" | ||
# NOTE: pkg_check_modules' Cflags definition for "XBOX" did not get included and was passed to CFLAGS_OTHER for some reason... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Most comments in this PR have typos (pkg_check_modules'
) or poor wording. Someone should spell check these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a typo, you can find it at https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#command:pkg_check_modules . Since the function's name is already plural, then there shouldn't be an s after apostrophe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it's actually fine, but other comments have spelling/grammar issues.
@thrimbor, can we get a public guideline what toolchain should do? There's no information about it. Such as |
The closest thing to a guideline I have is "don't rely on anything the makefile does for you". It didn't really start out as the base for a toolchain, the goal probably was to have something that makes it as simple as possible to build the example it came with. As such it brings a few convenience functions, but with limitations and and reliance on specifics of flawed tools. Xiso creation is one of those - it gives very little control over the end result (on-disc layout, non-1:1 directory mapping etc.), and technically isn't required to get something running on the Xbox, so imho we can leave that out the CMake toolchain file. It's still frequently used for quick emulator testing, so my suggestion would be to have a wiki entry "Creating an xiso from CMake" or something that supplies code that can just be dropped in. Feature parity between our current makefile and CMake to ease the switch is not a big concern to me - getting rid of the way we currently build things will break applications relying on it and require major adjustments anyway. |
I'm not close to having reviewed the whole PR yet (my free time is rather fragmented), but regarding 702b32e: Is that change required by CMake? As it is now that commit breaks direct usage of |
When I was debugging the issues for CMake problems from codespace I'll quote what I had found from OP post:
|
Like that guide says it's for Unix-like systems.
What will not work? What was the issue and how can I reproduce it? /edit: |
You can use https://github.com/RadWolfie/NevolutionX/tree/dev-container branch, select green code button dropdown menu > three dots (...) > + New with options... > it will open a page with options. The only thing need to change is Dev container configuration to "Xbox Development". Once done, you can press "Create codespace". From there, you can test compile build out of the box which is currently using my own nxdk package. The modified I made to CMakeLists.txt file to show the output are:
which output:
To reproduce the issue from upstream. You will need go into
As for cannot have -L / -l is a bit confusing... I ran a CI test for pkg-config command on all three available platforms from GitHub action: https://github.com/RadWolfie/cross-platform-pkg-config-test/actions/runs/5634597949
🤔 on side note: I didn't know it is possible to compile nxdk with msvc? |
I see. Annoying that CMake seems to mess with these files directly, but I guess we'll need to keep CMake happy.
That's expected, pkg-config defaults to assuming a Unix-like environment (mysys/Cygwin on Windows).
That's annoying - there are three different implementations of pkg-config:
For some reason you seem to get If you want to experiment you could try calling
It's not, but the tools we use ( |
From codespace using the docker image, it is using pkgconf (version 1.9.4) when I call pkg-config -h and pkg-config --version. To be sure it's not a fluke, I can confirm it is the same via call pkgconf. I can also confirm I tried downgrade pkgconf to 1.8.1 yet still it gives me blank library inputs.
The output will be:
If I change SDL2_image.pc to include `-l` before library file. Then it outputs:
With the correction from PR outputs:
TLDR version: Alpine docker's pkgconf didn't output the libraries with |
There seems to be a misunderstanding here, let me clarify what I meant. The way we currently have things set up makes pkg-config emit link.exe-style parameters which is fine for using them directly or with meson, but doesn't work with CMake because it expects to see ld-style parameters. The only requirement is that we have a compatible implementation of pkg-config. On our docker image that's not a problem because we control what software it contains, and I don't worry about Linux distros either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone through the code, and as far as I can see apart from the bits I'm mentioning here all issues have already been raised by jfr.
-I${NXDK_DIR}/lib/net/lwip/src/include \ | ||
-I${NXDK_DIR}/lib/net/nforceif/include \ | ||
-I${NXDK_DIR}/lib/net/nvnetdrv \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need all of these? I don't expect regular application code to have to deal with nvnetdrv for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the option of NXDK_NET was dropped in main makefile, These includes came from these lines.
Lines 22 to 27 in da6a0bd
NXDK_CFLAGS += -I$(LWIPDIR)/include | |
NXDK_CFLAGS += -I$(NXDK_DIR)/lib/net/nforceif/include | |
NXDK_CFLAGS += -I$(NXDK_DIR)/lib/net/nvnetdrv | |
NXDK_CXXFLAGS += -I$(LWIPDIR)/include | |
NXDK_CXXFLAGS += -I$(NXDK_DIR)/lib/net/nforceif/include | |
NXDK_CXXFLAGS += -I$(NXDK_DIR)/lib/net/nvnetdrv |
Do I know which includes folder actually used for application? No, I didn't have time to check all other applications using nxdk. Since I was too busy figuring out what are the major problems using CMake in codespace environment. I can recheck it later for what's really unnecessary for user-level application development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to check all applications. You seem to be testing with NevolutionX, which includes network support, so you can check whether it builds without the nvnetdrv
and nforceif
directories, and if it does, you can remove them. I assume only the lwip directory is necessary because that supplies the actual socket layer for the application, the other two should only be necessary for building nxdk itself.
set_target_properties(SDL2::SDL2 PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" | ||
INTERFACE_LINK_LIBRARIES "${SDL2_LINK_LIBRARIES}" | ||
# NOTE: pkg_check_modules' Cflags definition for "XBOX" did not get included and was passed to CFLAGS_OTHER for some reason... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it's actually fine, but other comments have spelling/grammar issues.
endif() | ||
|
||
# If custom title is not given, use given executable name. | ||
if(NOT XBE_TITLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for _NXDK_XBE_TITLE
, the leading underscore seems to be convention in CMake for variables that are considered internal to a module.
Could we also do an unset
when we're done with it?
After some troubleshooting process to figure out what went wrong with docker image for cmake usage. I found out there are several both manually incorrect coded and missing some support.
Libs:
variable. I had confirmed the correction now appear in<PREFIX>_LIBRARIES
and<PREFIX>_LINK_LIBRARIES
from output message test in cmake.CMAKE_SYSTEM_NAME
variable is set to Generic instead of Windows which fall back to unix-like's search method.<PREFIX>_CFLAGS_OTHER
. Although, it does show up in<PREFIX>_CFLAGS
except got exclude at compile/link time for unknown reason.CMAKE_MODULE_PATH
.NOTE:
CMAKE_MODULE_PATH
is document intended for project level than toolchain.The changes made were tested with experimental package published on GitHub to test with NevolutionX application using cmake. It is able to compile with nxdk and with linux libraries (require install sdl2 packages).