skaslev / gl3w

Simple OpenGL core profile loading
http://github.com/skaslev/gl3w
The Unlicense
705 stars 157 forks source link

Fixes #44, when project is added as a subdirectory to the root CMakeList #46

Closed podgorskiy closed 7 years ago

podgorskiy commented 7 years ago

In the commit da13943e39159a193c1192b2dedb6a41bba31d49, was created an interface, the motivation of which was to create a generator target, a command for generating sources and moving all generated sources to the binary folder.

However, those changes prevent using the project by including it as a subdirectory (Issue #44).

In this pull request, CMAKE_PROJECT_NAME replaced by PROJECT_NAME. PROJECT_NAME - the name of the project set by PROJECT() command, while CMAKE_PROJECT_NAME the name of the first project set by the PROJECT() command, i.e. the top level project. If gl3w was added to root project as a subdirectory, then CMAKE_PROJECT_NAME would have the name of the root project that caused CMake errors.

That is not the only issue. If the project is added as a subdirectory, then the generation of build files for root files fails, because the source gl3w.c is not generated yet. It is a chicken or the egg problem, I do not know how to solve it. As a temporary solution, I build gl3w and then run CMake for root project again.

I guess, it would be better, to have a switch, that would allow using the old logic.

64 commented 7 years ago

That is not the only issue. If the project is added as a subdirectory, then the generation of build files for root files fails, because the source gl3w.c is not generated yet. It is a chicken or the egg problem, I do not know how to solve it. As a temporary solution, I build gl3w and then run CMake for root project again.

Would using PROJECT_SOURCE_DIR instead of SOURCE_DIR when referencing gl3w.c work? It seemed to do so for me.

64 commented 7 years ago

Ah, I see the issue. With the new interface you are not supposed to call add_subdirectory, you need to run cmake . in the gl3w folder first, then from your main CMakeLists.txt you need to call find_package(gl3w REQUIRED) and target_link_libraries(YourProject gl3w).

disco-fella commented 5 years ago

Tip of the day for anybody exploring the ticket in the future: execute_process runs exactly prior to build system generation stage and can be used to cmake gl3w:

execute_process( COMMAND cmake . WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/gl3w )

execute_process( COMMAND cmake --build . WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/gl3w )

find_package(gl3w REQUIRED) target_link_libraries(${YOUR_PROJECT} gl3w)

skaslev commented 5 years ago

@krankenbyte Would you consider submitting a pull request?