gl3w
gl3w copied to clipboard
CMake doesn't work out of the box
Hello!
First of all, great library! I was planning on doing exactly this for my project and it's great to see that somebody already had this idea and nicely executed it.
I tried adding this as-is to my project using either CMake's FetchContent or a normal add_subdirectory call, but both lead to the same problem when making an linking gl3w after an add_library: it says it's missing the gl3w.c file.
I believe that's because the .c and .h files generated by the Python script is done so at the build time, and this checking is happening at configure time, so they are not there yet. If I run the script myself beforehand everything compiles fine.
I am not an expert at this, but is it possible to make the file generation happen just once at configure time? This would make embedding gl3w into newer projects more straight forward.
If it matters, I am on Windows, using CMake version 3.17.0-rc1 with MSVC 16.5.1. If any more information is needed I am happy to provide them.
Thanks!
Same issue here.
@salesvictor , @concatime , I execute gl3w_gen.py at the beginning of the CMakelist with a command like:
execute_process(COMMAND python gl3w_gen.py --root ${PROJECT_BINARY_DIR}/libs/gl3w WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/libs/gl3w)
Example: https://github.com/podgorskiy/bimpy/blob/master/CMakeLists.txt#L41
Doing this for many years now, never had problems with it.
I'm using gl3w with FetchContent. I was able to have it working out of the box by commenting one line out: https://github.com/bwrsandman/gl3w/commit/1494cee3776bfa5d16624cda159bd80fec1637dc
Try my branch: https://github.com/bwrsandman/gl3w/
Here's a CMake script I wrote using FetchContent
to include this in my project. It solves two issues I had with the one in this project: The install rules aren't optional, making it difficult, if not impossible, to exclude the sources in a CPack generated installer. I don't want to redistribute the gl3w sources with my app. And the sources are generated at build-time, when they really should be generated pre-build so an IDE can find them before it compiles the first time.
cmake_minimum_required(VERSION 3.24)
find_package(OpenGL REQUIRED)
find_package(PythonInterp REQUIRED)
include(FetchContent)
FetchContent_Declare(gl3w GIT_REPOSITORY "https://github.com/skaslev/gl3w.git" GIT_TAG "master")
message(CHECK_START "Fetching skaslev/gl3w from GitHub")
FetchContent_Populate(gl3w)
message(CHECK_PASS "Done")
message(CHECK_START "Generating gl3w sources")
execute_process(COMMAND ${PYTHON_EXECUTABLE} gl3w_gen.py WORKING_DIRECTORY ${gl3w_SOURCE_DIR} OUTPUT_QUIET)
message(CHECK_PASS "Done")
add_library(gl3w INTERFACE)
target_sources(gl3w INTERFACE
$<BUILD_INTERFACE:${gl3w_SOURCE_DIR}/src/gl3w.c>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_DATAROOTDIR}/gl3w/src/gl3w.c>)
target_sources(gl3w INTERFACE FILE_SET HEADERS
BASE_DIRS
${gl3w_source_dir}/include
FILES
${gl3w_headers})
target_include_directories(gl3w INTERFACE
$<BUILD_INTERFACE:${gl3w_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/gl3w>)
target_link_libraries(gl3w INTERFACE OpenGL::GL ${CMAKE_DL_LIBS})
Thanks for the script. It works but is not ideal.