Skip to content

[docs] Add a CMake support page - #28431

Open
juj wants to merge 2 commits into
emscripten-core:mainfrom
juj:docs_cmake_support
Open

juj wants to merge 2 commits into
emscripten-core:mainfrom
juj:docs_cmake_support

Conversation

@juj

@juj juj commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Add a "CMake support" page to the Porting section of the documentation, covering emcmake, using the toolchain file directly, the toolchain options, writing CMakeLists.txt files that build both natively and with Emscripten, choosing the output file type, compiler and linker flags, the em_link_js_library()/em_link_pre_js()/em_link_post_js() functions, build types, ports, and running tests with the cross-compiling emulator.

Replace the CMake section in Building-Projects with a link to the new page.

Fixes #2655.

juj added a commit to juj/emscripten that referenced this pull request Nov 29, 2026
juj added a commit to juj/emscripten that referenced this pull request Nov 30, 2026
Comment thread site/source/docs/porting/cmake.rst Outdated
support shared libraries with Emscripten (see
`CMake issue 27240 <https://gitlab.kitware.com/cmake/cmake/-/work_items/27240>`_).
- **C++ modules**: ``import std`` is supported with CMake 3.30 and newer when
``CMAKE_CXX_MODULE_STD`` is enabled.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not leave this page under "compiling" where it is today?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread site/source/docs/porting/cmake.rst Outdated

- **Whole archive linking**: With CMake 3.24 and newer,
``target_link_libraries(app $<LINK_LIBRARY:WHOLE_ARCHIVE,mylib>)`` links all
object files from a static library.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any benefit to document generic cmake feature like this? (i.e. this doesn't seem emscripten specific at all).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these are features that CMake doesn't provide out of the box for cross-platform targets. Emscripten's toolchain file adds support for those (cmake/Modules/Platform/Emscripten.cmake:292-294), so that is why the bot picked up on documenting these.

For a CMake veteran, it does then seem like there could be value to know "hey, this wouldn't exist in general, but our toolchain file does provide it."

----------------

Configure-time checks like ``check_include_file()``, ``check_function_exists()``
and ``check_type_size()`` work, and are performed with *emcc*. Some values that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should emcc be in double backticks here rather than asterisks?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juj and others added 2 commits November 30, 2026 19:26
Add a "CMake support" page to the Porting section of the documentation,
covering emcmake, using the toolchain file directly, the toolchain options,
writing CMakeLists.txt files that build both natively and with Emscripten,
choosing the output file type, compiler and linker flags, the
em_link_js_library()/em_link_pre_js()/em_link_post_js() functions, build
types, ports, and running tests with the cross-compiling emulator.

Replace the CMake section in Building-Projects with a link to the new page.

Fixes emscripten-core#2655.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eatures

- Move porting/cmake.rst to compiling/CMake.rst, next to Building-Projects,
  and list it in compiling/index.rst instead of porting/index.rst.
- Reword the "Other features and limitations" section to make clear that
  these are features the Emscripten toolchain file enables (or disables)
  for CMake, rather than generic CMake features.
- Fix the shared library warning in Emscripten.cmake, which said
  "cmake > 4.3.3" although 4.3.3 and 4.2.6+ work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juj
juj force-pushed the docs_cmake_support branch from be00837 to fd00bf9 Compare November 30, 2026 17:26
.. note::

*emcmake* automatically passes the Emscripten CMake toolchain file (``-DCMAKE_TOOLCHAIN_FILE=.../Emscripten.cmake``) to CMake.
For using CMake to build projects with Emscripten, see the section :ref:`CMake-support`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little odd to have a whole subsection there that just links to another section.. maybe I don't have a better suggestion off hand

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah.. there was enough material that having that embedded in this section didn't feel good either. With a link from this page though should be discoverable at least.

@juj
juj enabled auto-merge (squash) November 30, 2026 18:12

This branch has not been deployed

No deployments
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.

Write up a documentation page on how to set up build systems with cmake.

2 participants