Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using CMake on Windows #174

Closed
tysonbrochu opened this issue Sep 21, 2018 · 7 comments
Closed

Problems using CMake on Windows #174

tysonbrochu opened this issue Sep 21, 2018 · 7 comments

Comments

@tysonbrochu
Copy link

Hello,

I'm having trouble getting glad working with CMake on Windows. I would like to have glad run as part of our CMake build process, and use the generated glad.h/lib files in our project.

For testing, my folder structure looks like:
C:\Users\me\projects\glad (cloned from GitHub)
C:\Users\me\projects\glad-driver (new directory with nothing except a CMakeLists.txt)

I made empty build\ directories off of each of these as well.

The contents of glad-driver\CMakeLists.txt are:

cmake_minimum_required(VERSION 3.0)
set(glad_DIR "..\\glad\\build")
find_package(glad REQUIRED)

Here are the commands I use to try to build glad-driver. First run CMake on glad:

> cd glad\build
> cmake -DGLAD_INSTALL=ON ..

Result:

-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.15.26729.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: C:/Users/me/AppData/Local/Programs/Python/Python36/python.exe (found version "3.6.5")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/me/projects/glad/build

Next, compile the generated Visual Studio projects:

> msbuild /p:Configuration=Release ALL_BUILD.vcxproj

Result:
(Lots of stuff then):

Done Building Project "C:\Users\me\projects\glad\build\ALL_BUILD.vcxproj" (default targets).

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:02.08

Last step, try finding glad with CMake’s find_package command:

> cd ....\glad-driver\build
> cmake ..

Result:

-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.15.26729.0
-- The CXX compiler identification is MSVC 19.15.26729.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual >Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at C:/Users/me/projects/glad/build/gladConfig.cmake:27 (include):
include could not find load file:

C:/Users/me/projects/glad/build/gladTargets.cmake

Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)

-- Configuring incomplete, errors occurred!
See also "C:/Users/me/projects/glad-driver/build/CMakeFiles/CMakeOutput.log".

Further investigation reveals that the gladTargets.cmake file (and a bunch couple of seemingly related files are actually located at):

C:\Users\me\projects\glad\build\CMakeFiles\Export\lib\cmake\glad\gladTargets.cmake

I don’t know why gladConfig.cmake ends up in build and gladTargets.cmake ends up in build\CmakeFiles\Export\lib\cmake\glad.

If I copy gladTargets.cmake into the glad\build directory and re-run CMake from glad-driver, then my glad-driver CMake project does succeed. However if I add the following lines to glad-driver\CMakeLists.txt:

add_executable (hello_glad "HelloGlad.cpp")
target_link_libraries(hello_glad glad::glad)

then I get the following error:

CMake Error in CMakeLists.txt:
Imported target "glad::glad" includes non-existent path

"C:/Users/me/include/glad"

in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:

  • The path was deleted, renamed, or moved to another location.

  • An install or uninstall procedure did not complete successfully.

  • The installation package was faulty and references files it does not
    provide.

Any help would be greatly appreciated!

@Dav1dde
Copy link
Owner

Dav1dde commented Sep 21, 2018

Thanks for the comprehensive description of your problem - I will have to look into this and try to reproduce this issue.

@sfuller maybe you can help me look into this?

@Dav1dde Dav1dde added the glad1 label Sep 21, 2018
@tysonbrochu
Copy link
Author

Thanks for the quick reply!

I think I might be closer to a solution now. I think that instead of running msbuild on the output of glad cmake, I should be running cmake --build . --install. That seems to try to install everything (gladConfig and gladTargets) into my CMake directory. I will continue to investigate, but I'd still be interested to hear if anyone has had any success with a similar setup.

@Dav1dde
Copy link
Owner

Dav1dde commented Sep 24, 2018

Did you figure this out? Sorry busy at the moment, I'll try to take a look at the weekend again.

@tysonbrochu
Copy link
Author

No problem. We did not track this all the way down to a workable solution, and we had to move on to other things. So for now we are just going to incorporate the pre-generated .h/.c files directly into our build, rather than go through glad's CMake mechanism. If we revisit in the future I will update this issue.

Thanks again for your help.

@manenko
Copy link

manenko commented Sep 29, 2018

Hello everyone.

@tysonbrochu , have you considered to try FetchContent module instead of cloning glad manually?

My suggestion is to give it a shot. It may solve the issue you have (you let CMake handle everything for you). Plus, you can manage other dependencies is the same unified way.

  1. Edit your root CMakeLists.txt and add the following line:
    add_subdirectory(extern)
  2. Create a directory extern in the root folder of the project.
  3. Create an extern/CMakeLists.txt file with the following content:
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
# Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on
# the official specs. http://glad.dav1d.de/
FetchContent_Declare(
  extern_glad

  GIT_REPOSITORY https://github.com/Dav1dde/glad.git
  GIT_TAG        v0.1.27)

FetchContent_GetProperties(extern_glad)
if(NOT extern_glad_POPULATED)
  FetchContent_Populate(extern_glad)

  set(GLAD_INSTALL ON)
  add_subdirectory(
    ${extern_glad_SOURCE_DIR}
    ${extern_glad_BINARY_DIR}
    EXCLUDE_FROM_ALL)
endif()
  1. Add glad as a dependency inside one of your CMakeLists.txts as usual:
target_link_libraries(the_target_you_want_to_link_agains_glad
  PUBLIC
  glad

  PRIVATE
  ${CMAKE_DL_LIBS})

Hope this helps.

@sfuller
Copy link

sfuller commented Sep 30, 2018

Hi, sorry I'm late to this conversation.
In your project, you are using find_package(glad REQUIRED).
I don't believe this will work unless you have a special module used for finding GLAD. To use the CMake config package mechanism that Glad is utilizing, instead try using find_package(glad REQUIRED CONFIG)

Note, that you will need to run cmake --build . --install on the glad build first. Also, if CMake is still unable to find the GLAD target, you might need to point CMake to the installed files using -DCMAKE_PREFIX_PATH. See the find_package documentation for more detailed information on that: https://cmake.org/cmake/help/v3.12/command/find_package.html

@Dav1dde
Copy link
Owner

Dav1dde commented Apr 30, 2019

I assume this is solved, if not feel free to re-open.

@Dav1dde Dav1dde closed this as completed Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants