Skip to content

Add more arch tags#57

Merged
pdimov merged 3 commits intoboostorg:developfrom
Neumann-A:arch-tags
Apr 20, 2024
Merged

Add more arch tags#57
pdimov merged 3 commits intoboostorg:developfrom
Neumann-A:arch-tags

Conversation

@Neumann-A
Copy link
Copy Markdown
Contributor

@Neumann-A Neumann-A commented Apr 19, 2024

closes #53

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

CMAKE_CXX_COMPILER_ARCHITECTURE_ID is documented as "an internal variable subject to change" and there are StackOverflow reports that it's not always set (e.g. on MinGW-w64), so this has the potential to be a regression.

E.g. https://gitlab.kitware.com/cmake/cmake/-/issues/17702

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

@Neumann-A
Copy link
Copy Markdown
Contributor Author

I could also copy over what boost-context does
https://github.com/boostorg/context/blob/f5d062c9399b6410cf1f90070bf6716f2ee0ced3/CMakeLists.txt#L32-L75
and switch on CMAKE_SYSTEM_PROCESSOR.
Alternatively guarding this code with if(MSVC) would also be possible.
And of course provide an escape hatch and make BOOST_ARCHITECTURE_TAG a CACHE variable.

@pdimov: Any preferences?

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

The current state of CMake is that CMAKE_CXX_COMPILER_ARCHITECTURE_ID only works under MSVC, and CMAKE_SYSTEM_PROCESSOR only works when not MSVC. So if we want a solution that actually works, we need to use both.

@Neumann-A
Copy link
Copy Markdown
Contributor Author

CMAKE_SYSTEM_PROCESSOR only works when not MSVC

CMAKE_SYSTEM_PROCESSOR always works. The issue you linked (https://gitlab.kitware.com/cmake/cmake/-/issues/15170) is a user error. If you do a cross build like x64 to x86 or arm you have to manually set CMAKE_SYSTEM_PROCESSOR because otherwise it will be set to CMAKE_HOST_SYSTEM_PROCESSOR as documented in the CMake docs. A lot of users are just unaware of this little fact.

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

No, that's not true. Read the comments on the issue again.

@Neumann-A
Copy link
Copy Markdown
Contributor Author

No, that's not true. Read the comments on the issue again.

I did and as a conclusion the docs for CMAKE_SYSTEM_PROCESSOR were updated. vcpkg even has this whole setup https://github.com/microsoft/vcpkg/blob/b346ee32f13f3bf2ef19ac02f982f6938f7a84ea/scripts/toolchains/windows.cmake#L8-L36 to setup cross builds on windows correctly from a CMake perspective. The problem is that people expect CMAKE_SYSTEM_PROCESSOR to be set correctly by CMake even though it as little to no info to do so.

But ultimately I don't mind I can just add if(MSVC) do as FindBoost does and use the boost context logic otherwise.

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

Please make the following changes:

  • Remove BOOST_ARCHITECTURE_TAG
  • Use arch as the variable name instead of __boost_default_arch_tag
  • Remove the x86 cases and the warnings and always use "x" as a fallback
  • Fix the string(APPEND errors because the default value is "x"
  • Remove the IA64 case because I don't think anyone uses MSVC for IA64 anymore

In principle we support more architectures (e.g. s390x, PowerPC) but I don't know what the CMAKE_SYSTEM_PROCESSOR correct values for them are.

On second thought, I'm not sure MSVC supports MIPS anymore either. We can probably drop that case too.

@Neumann-A
Copy link
Copy Markdown
Contributor Author

strongly simplified as requested

@Neumann-A
Copy link
Copy Markdown
Contributor Author

In principle we support more architectures (e.g. s390x, PowerPC) but I don't know what the CMAKE_SYSTEM_PROCESSOR correct values for them are.

Where is the b2 logic for the selection for that? CMake is just using uname -m for the host I would assume b2 does something similar?

@Neumann-A Neumann-A changed the title Add more arch tags following FindBoost.cmake Add more arch tags Apr 20, 2024
@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

b2 uses configure checks and looks at predefined compiler macros: https://github.com/boostorg/config/tree/develop/checks/architecture

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

@Neumann-A
Copy link
Copy Markdown
Contributor Author

@pdimov: I also found those but the question is rather where the b2 build hides the mapping from architecture to character literal.

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

Character literal?

@Neumann-A
Copy link
Copy Markdown
Contributor Author

Character literal?

The mapping from "x64" to "x" or "aarch" to "a"

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

That's done by just taking the first letter of the architecture.

@pdimov pdimov merged commit d62cda1 into boostorg:develop Apr 20, 2024
@Neumann-A Neumann-A deleted the arch-tags branch April 20, 2024 15:42
@Neumann-A
Copy link
Copy Markdown
Contributor Author

If I would have known that I probably would have used

      if(CMAKE_SYSTEM_PROCESSOR MATCHES "i(3|6)86")
        set(arch "x")
      else()
        string(SUBSTRING "${CMAKE_SYSTEM_PROCESSOR}" 0 1 arch)
        string(TOLOWER "${arch}" arch)
      endif()

for the !MSVC part

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

I suppose that would work too; I can't offhand think of an architecture where it would give the wrong result.

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 20, 2024

amd64, maybe; Wikipedia lists this for OpenBSD 5.4.

@pdimov
Copy link
Copy Markdown
Member

pdimov commented Apr 28, 2024

Feel free to submit another PR for the above change to avoid the need to patch in vcpkg if you like - but please check for amd64 in the x86 branch and maybe use i[3-6]86 if someone still uses i486.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Boost Install only knows x64

2 participants