Skip to content

Commit

Permalink
Merge pull request rougier#262 from joshuafc/patch-2
Browse files Browse the repository at this point in the history
generate config.h while compile by cmake variable status, so user can get the macro which exists when build freetype-gl .
  • Loading branch information
rougier authored Dec 15, 2021
2 parents 80f5877 + 5f1a596 commit 41193bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,20 @@ endif()
find_package(Freetype REQUIRED)

if(freetype-gl_WITH_GLEW)
add_definitions(-DWITH_GLEW=1)
set(FREETYPE_GL_USE_GLEW 1)
find_package(GLEW REQUIRED)
endif()

if(freetype-gl_WITH_GLAD)
add_definitions(-DGL_WITH_GLAD)
set(GL_WITH_GLAD 1)
endif()

include_directories(
${OPENGL_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${GLEW_INCLUDE_PATH}
${PROJECT_BINARY_DIR}
)

if(MSVC)
Expand All @@ -127,9 +128,14 @@ if(MSVC)
endif(MSVC)

if(freetype-gl_USE_VAO)
add_definitions(-DFREETYPE_GL_USE_VAO)
set(FREETYPE_GL_USE_VAO 1)
endif(freetype-gl_USE_VAO)

configure_file (
"${PROJECT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)

set(FREETYPE_GL_HDR
distance-field.h
edtaa3func.h
Expand All @@ -148,6 +154,7 @@ set(FREETYPE_GL_HDR
vertex-attribute.h
vertex-buffer.h
freetype-gl-errdef.h
${PROJECT_BINARY_DIR}/config.h
)

set(FREETYPE_GL_SRC
Expand Down
5 changes: 5 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// config.h is generated by cmake while build freetype-gl from template config.h.in by cmake variable status

#cmakedefine FREETYPE_GL_USE_GLEW @FREETYPE_GL_USE_GLEW@
#cmakedefine FREETYPE_GL_USE_VAO @FREETYPE_GL_USE_VAO@
#cmakedefine GL_WITH_GLAD @GL_WITH_GLAD@
3 changes: 2 additions & 1 deletion opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#ifndef __OPEN_GL_H__
#define __OPEN_GL_H__
#include "config.h"

#if defined(GL_WITH_GLAD)
# include <glad/glad.h>
Expand All @@ -30,7 +31,7 @@
# include <GLES2/gl2.h>
# endif
#else
#if defined(WITH_GLEW)
#if defined(FREETYPE_GL_USE_GLEW)
# include <GL/glew.h>
#endif
# include <GL/gl.h>
Expand Down

0 comments on commit 41193bc

Please sign in to comment.