I am trying to clone and build 3rd party libraries from git using Cmake's ExternalProject_Add
.
Could someone please explain to me how to use ExternalProject_Add
correctly?
Currently I have this in my CmakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(openGLtest)
include(ExternalProject)
set(CMAKE_CXX_STANDARD 17)
set(OUTPUT_DIR ${PROJECT_SOURCE_DIR}/glfw)
set(CMAKE_CXX_FLAGS "-framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo")
ExternalProject_Add(glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR})
include_directories(glad/include)
include_directories(${OUTPUT_DIR}/include)
link_directories(${OUTPUT_DIR}/lib)
add_executable(openGLtest glad/src/glad.c main.cpp)
add_dependencies(openGLtest glfw)
target_link_libraries(openGLtest glfw3.a)
I'm using GLFW
, and GLAD
. The issue is that GLFW
's dependencies are not being linked when it get's compiled, that's why I added the set CMAKE_CXX_FLAGS
line. Everything compiles now, but I am pretty sure that shoehorning in system specific compiler flags is not the right solution.
-EDIT-
My problem is not with this library specifically, it's about the finding the correct way of setting up my Cmake to get the libraries that my project needs from the internet when I build the project. I'm sure Cmake is capable of pulling, or downloading the necessary libraries when it builds my project. It also seems to me that using ExternalProject_Add
is the right way to do that. I just don't know how to use ExternalProject_Add
to get the libraries, without there being weird compile errors.
Any help would be greatly appreciated, I've been stuck with this problem for almost a week at this point.