Skip to content

Conversation

cajomar
Copy link
Contributor

@cajomar cajomar commented Feb 19, 2025

This allows projects to include OpenGL like so

find_package(OpenGL REQUIRED)
target_link_libraries(myproject OpenGL::GL)

Link to CMake's documentation: https://cmake.org/cmake/help/latest/module/FindOpenGL.html#imported-targets

CMake's FindOpenGL.cmake also produces GLES-related imported targets. While I think they would be nice to add, I've omitted them as I don't know if it would be as simple as duplicating the OpenGL::GL target or more needs to be to communicate that choice of flavor to emscripten.

Added OpenGL::GL and OpenGL::GLU to FindOpenGL.cmake following CMake's
own FindOpenGL.cmake
@sbc100
Copy link
Collaborator

sbc100 commented Feb 19, 2025

Can we test this? Perhaps by adding to the existing test/cmake/find_modules/ test?

@cajomar
Copy link
Contributor Author

cajomar commented Feb 22, 2025

@sbc100 I added a few lines to validate the IMPORTED_LIBNAME property of OpenGL::GL. Please let me know if you had something else in mind.

include_directories(${OPENAL_INCLUDE_DIR})
target_link_libraries(test_prog ${OPENAL_LIBRARY})
message(" test: OPENGL_LIBRARIES: ${OPENAL_LIBRARIES}")
message(" test: OPENAL_LIBRARIES: ${OPENAL_LIBRARIES}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use STATUS here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add STATUS to pre-existing messages because I thought perhaps the outputting to stderr was intentional (adding STATUS directs it to stdout), but I can certainly do that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should be consistent within this file. i don't think anything else is reading the stdout or std of the cmake process.

message(" test: SDL2_LIBRARIES: ${SDL2_LIBRARIES}")
message(" test: SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")

get_target_property(lib OpenGL::GL IMPORTED_LIBNAME)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this creating a new lib variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, although an admittedly lazy naming choice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Should we check INTERFACE_LINK_LIBRARIES too?

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm % comments

@sbc100 sbc100 enabled auto-merge (squash) February 25, 2025 01:15
@sbc100 sbc100 merged commit 2ee1188 into emscripten-core:main Feb 27, 2025
28 of 29 checks passed
@dschuff
Copy link
Member

dschuff commented Feb 28, 2025

This doesn't seem to work on Windows:
https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8721741671459149313/+/u/Emscripten_testsuite__other_/stdout

Oddy I tried it locally I got a different error:

test_cmake_find_modules (test_other.other.test_cmake_find_modules) ... configure: cmake C:\src\emr\install\emscripten\test\cmake\find_modules -DCMAKE_TOOLCHAIN_FILE=C:\src\emr\install\emscripten\cmake\Modules\Platform\Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=C:/src/emr/emscripten-releases/node-v20.14.0-win-x64/node.exe -G Ninja
-- The C compiler identification is Clang 21.0.0
-- The CXX compiler identification is Clang 21.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/src/emr/install/emscripten/emcc.bat - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/src/emr/install/emscripten/em++.bat - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
 test: OPENGL_LIBRARIES: GL;GLU
 test: OPENGL_LIBRARIES:
 test: SDL2_LIBRARIES: -sUSE_SDL=2
 test: SDL2_INCLUDE_DIRS: C:/src/emr/install/emscripten/cache/sysroot/include/SDL2
-- Configuring done
CMake Error in CMakeLists.txt:
  Imported target "SDL2::SDL2" includes non-existent path

    "C:/src/emr/install/emscripten/cache/sysroot/include/SDL2"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Any ideas from either of those?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 28, 2025

I think you need to make sure sdl2 is built before you can run that test. We should probably add an embuilder command in there to fix that.

sbc100 added a commit to sbc100/emscripten that referenced this pull request Apr 2, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Apr 2, 2025
sbc100 added a commit that referenced this pull request Apr 2, 2025
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.

4 participants