2

I'm trying to include FreeType with cmake but am having issues with ft2build.h not being found. Here are my cmake files

main cmakelist:

cmake_minimum_required(VERSION 2.8)

project(game)

add_subdirectory(Managers)
add_subdirectory(Core)
add_subdirectory(Rendering)
add_subdirectory(Input)

add_executable(game main.cpp)

target_link_libraries(game initglew initglut camera modelmanager scenemanager shadermanager renderinglib)

find_library(GLUT glut)
find_library(OPENGL GL)
find_library(GLEW GLEW)
find_library(MATH m)

find_package(Freetype REQUIRED)

target_link_libraries(game ${GLUT} ${OPENGL} ${GLEW} ${MATH} ${FREETYPE_LIBRARIES})
include_directories(${FREETYPE_INCLUDE_DIRS})

SET(GCC_FLAGS "-Wall -Wextra -pedantic -std=c++17 -Wno-unused-parameter -g")
add_definitions(${GCC_FLAGS})

install(TARGETS game DESTINATION bin)

Rendering cmakelist:

cmake_minimum_required(VERSION 2.8)

project(rendering)
file(GLOB_RECURSE renderingcpps CONFIGURE_DEPENDS "*.cpp")
file(GLOB_RECURSE renderinghpps CONFIGURE_DEPENDS "*.hpp")

add_library(renderinglib STATIC ${renderingcpps})

install(TARGETS renderinglib DESTINATION lib)

install(FILES ${renderinghpps} DESTINATION include)

I'm including FreeType in the highest level cmakelist but a file inside a subfolder of rendering cant find ft2build.h. I tried following this link Linking freetype with cmake which got me where I am now but ft2build.h still cant be found. I was originally compiling with "-lfreetype -I/usr/include/freetype2" before trying to switch to cmake

I logged some output and FREETYPE_INCLUDE_DIRS is being populated with /usr/include/freetype2 but its two subcomponets are empty, not sure if thats related

Jordan
  • 21
  • 5
  • I guess order matters here. Your `include_directories` command is located after the call to `add_library` therefore it is not seen from the library. Restructure your CMakeLists.txt to find freetype before the `add_library` command and do your `include_directories` also before it. – vre Dec 30 '20 at 21:38
  • `include_directories(` -> `target_include_directories(the_target PUBLIC ...)` – KamilCuk Dec 30 '20 at 23:29
  • I originally used target include directories but switched it since include_directories seems more general? and it looked like target might only include them for the specific target, also changing the order doesnt seem to work :(. AHA actually it does work i had to move it before the add_subdirectory?????? guess i really need a better understanding of how cmake really works – Jordan Dec 31 '20 at 02:15

0 Answers0