Hi,
I want to use the .h
and .c.
files created by the webservice in my project but I do not want to store each ~10k line file in my repo.
Is there a way to include this and "build" it via CMAKE and have the needed files generated (similar to GLFW)?
Thanks for your project
Yes it's possible. Make a subdirectory in your project and add a CMakeLists.txt
in it together with the files:
cmake_minimum_required(VERSION 3.0)
project(Glad)
add_library(glad include/glad/glad.h src/glad.c)
target_include_directories(glad PUBLIC include/)
Then in your main CMakeLists.txt
file put:
add_subdirectory(glad/)
target_link_libraries(<your target> PRIVATE glad)
Or something like that. There are a bunch of ways of achieving this.
@Shimmen thanks for the explanation!
You can also look through the issue https://github.com/Dav1dde/glad/issues/174 where a few awesome people added more ways to do that.
Personally I'd include the generated files though, the symbols should be sorted so if you upgrade the generated files at one point you'll get minimal diffs, also it means you don't have a dependency on external resources and Python.
I just realized I didn't at all supply an answer to the original question! Personally I like to keep the glad stuff out of my source directory and out of the build step of my main executable, so that's what my example does.
I'll assume this is answered, if not please feel free to re-open.
I understand it's typical to put the generated files into your include directory, but IS there a way to have this generate when building CMake?
I don't think requiring Python is that big of a deal, it's very common place. Having the option is at least nice.
@DerekCresswell yes you can run the generator on a build, there is a CMakeLists.txt
in the root of this repository that should allow you to do that (iirc through add_subdirectory
).
I've also been working on glad2 which has a new CMakeLists.txt
with an example here.
Most helpful comment
Yes it's possible. Make a subdirectory in your project and add a
CMakeLists.txt
in it together with the files:Then in your main
CMakeLists.txt
file put:Or something like that. There are a bunch of ways of achieving this.