cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
539 stars 58 forks source link

question about glbindingConfig.cmake #399

Closed GooksanGom closed 5 years ago

GooksanGom commented 5 years ago

Hi, I'm trying to build globjects from sources using Visual Studio 2019. I downloaded the source code of glbinding and managed to succeed to generate VS2019 solution using CMake (GUI) and build it to binaries. CMake keeps showing me the following error message when I try to generate a solution for globjects:

CMake Error at source/globjects/CMakeLists.txt:7 (find_package):
  By not providing "Findglbinding.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "glbinding", but CMake did not find one.

  Could not find a package configuration file provided by "glbinding" with
  any of the following names:

    glbindingConfig.cmake
    glbinding-config.cmake

  Add the installation prefix of "glbinding" to CMAKE_PREFIX_PATH or set
  "glbinding_DIR" to a directory containing one of the above files.  If
  "glbinding" provides a separate development package or SDK, be sure it has
  been installed.

shame on me for not being familiar with CMake even though I am using it... (I am not even sure that I am using it right) and I don't have any idea of how to make cmake find glbinding. I don't see any files such as glbindingConfig.cmake or glbinding-config.cmake, and glmConfig.cmake was found, but not for glbinding.

I tried to set glbinding_DIR manually to build directory of glbinding or the source directory in CMake GUI window but it does not help.

Please help me to generate a VS2019 solution for globjects. If you need any information to help you help me, tell me, I will do my best.

Thanks in advance.

scheibel commented 5 years ago

The process you describe sounds like one of the intentionally supported ones. When using a glbinding build from source, the glbinding-config.cmake should be right in the root of the repository and the environment variable glbinding_DIR should point to the repository root. Alternatively, you can point the environment variable CMAKE_PREFIX_PATH to the directory containing the glbinding directory (which is then expected to be named glbinding, cf. https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html). There is one peculiarity regarding the CMake build: We expect a separate build directory and it is expected to be named build (cf. https://github.com/cginternals/glbinding/blob/master/glbinding-config.cmake#L49).

However, it seems as if there is an issue with finding the first glbinding-config.cmake file. Can you check why your source build seems to be missing this file although it should be provided with the sources?

GooksanGom commented 5 years ago

When using a glbinding build from source, the glbinding-config.cmake should be right in the root of the repository

omg I didn't even think that that file is what I was looking for. I was searching only in the build after I saw that glm generated its config file in its build. There is glbinding-config.cmake in the root of the repository, but I thought it is a different file that just have same name because CMake failed when I set glbinding_DIR to the root directory.

There is one peculiarity regarding the CMake build: We expect a separate build directory and it is expected to be named build

I had build directory in the root. (I see cmake, deploy, source directories with the build... so that means it is not separate right?) and I had created x86, x64 directories in the build. so... the actual name of build directory is not build. These might be the reason that CMake failed when I set glbinding_DIR to the root and also the reason that glbinding_DIR is set to not found in the CMake GUI.

I moved build out of the root directory, removed x86, x64 and moved all contents in x86 into build. I copied glbinding-config.cmake into build and now CMake works! (but what if I want to generate the x64 version too? do I have to just leave a room for x64 by putting the x86 version somewhere?)

Thanks!

scheibel commented 5 years ago

I assume the x68 and x64 directories were the problem. Anyone using Windows has a hint? @sbusch42 @cgcostume

GooksanGom commented 5 years ago

I think CMake with globjects works only if build is exactly one level out of the root directory. For example, CMake worked without any error in the following directory structure:

glbinding-3.1.0
├ 3rdparty
├ cmake
├ data
├ deploy
├ docs
├ source
└ [files including glbinding-config.cmake]
build
├ 3rdparty
└ whatever CMake generated for glbinding

However, CMake failed with the following error message if build is not in the same level of the root (I did manually set glbinding_DIR to glbinding-3.1.0).

CMake Error at source/globjects/CMakeLists.txt:7 (find_package):
  Found package configuration file:

    D:/Libraries/glbinding-3.1.0/glbinding-config.cmake

  but it set glbinding_FOUND to FALSE so package "glbinding" is considered to
  be NOT FOUND.

In the above case, the build is in ..\builds\x86\ from the root directory.

A question I have is, is the purpose of glbinding_DIR to locate the root directory of the glbinding sources or to locate build? I guessed it is for the root directory, because glmConfig.cmake tells CMake where the root directory of glm sources is. The glbinding-config.cmake is actually in the root directory so that I think CMake will succeed to find the root directory easily, and apparently it didn't.

I have been studying CMake in a tutorial website since when I faced this problem at the first place. but I still need to study hard in order to understand the CMake script and figure out how to edit it to make it work.

Any answer or opinion will help me to solve the problem and to study CMake. Thanks in advance.

EDIT: glm_DIR was actually GLM_INCLUDE_DIR. glmConfig.cmake has nothing to do with this. I misunderstood.

scheibel commented 5 years ago

We actually expect the build directory to be one level below the root:

glbinding-3.1.0
├ build
└ [remaining glbinding source files]

The purpose of glbinding_DIR is to point to the glbinding-config.cmake. From there, our script within this file tries to locate the auto-generated import files (such as glbinding-export.cmake). For this, we hard-coded some directories within the glbinding-config.cmake file, including a build directory that is located in the same directory as the config file.

GooksanGom commented 5 years ago

I copied glbinding-config.cmake into each build (builds\x86\build, builds\x64\build) and CMake succeeded to generate solutions. I am not sure that the file is supposed to be copied into build.

I tried building the generated solution and the build failed with many lines of error messages that says "'glbinding/callbacks.h': No such file or directory".

In the [globjects]-[properties]-[C/C++]-[General]-[Additional Include Directories], the following items are listed:

D:\Libraries\globjects-1.0.0-builds\vs15\x86-static\build\source\include
D:\Libraries\globjects-1.0.0\source\globjects\include
D:\Libraries\globjects-1.0.0-builds\vs15\x86-static\build\source\globjects\include
D:\Libraries\glm-0.9.9.5\glm
D:\Libraries\glbinding-3.1.0\source\glbinding\include
D:\Libraries\glbinding-3.1.0-builds\vs15\x86-static\build\source\glbinding\include
D:\Libraries\glbinding-3.1.0\3rdparty\KHR\include
%(AdditionalIncludeDirectories)

It seems that MSVC cannot find glbinding's files with the paths. Maybe glbinding-config.cmake was not supposed to be copied?

The copied glbinding-config.cmake could direct wrong include paths. Could you tell me some right include paths that CMake script originally intended to? I think I can manage to build globjects if I set these to the right paths.

Thanks!

sbusch42 commented 5 years ago

Don't copy the file into the build directory. This cannot work because the cmake file searches also for files which are not in the build directory (aka, the headers). Please try another approach: Just edit glbinding-config.cmake to fit your directory structure. At the end of the file, you see where we expect the build directory:

Just add your build directory location there and point glbinding_DIR (or better CMAKE_PREFIX_PATH) to glbinding's root directory. Let us know if this works.

GooksanGom commented 5 years ago

We actually expect the build directory to be one level below the root:

glbinding-3.1.0
├ build
└ [remaining glbinding source files]

The purpose of glbinding_DIR is to point to the glbinding-config.cmake. From there, our script within this file tries to locate the auto-generated import files (such as glbinding-export.cmake). For this, we hard-coded some directories within the glbinding-config.cmake file, including a build directory that is located in the same directory as the config file.

You mean, build and glbinding-config.cmake should be in glbinding-3.1.0, and there cannot be any intermediate directories such as x86 in build right?

Now I understand what I should have done and shouldn't. The problem was purely due to the x86 and 64 in build at the first place. Hmm... I have done misunderstand everything.

Forget about my last comments. I think it will solve the problem clearly. Thanks!

GooksanGom commented 5 years ago

Don't copy the file into the build directory. This cannot work because the cmake file searches also for files which are not in the build directory (aka, the headers). Please try another approach: Just edit glbinding-config.cmake to fit your directory structure. At the end of the file, you see where we expect the build directory:

  • find_modules("build/cmake")
  • find_modules("build-debug/cmake")

Just add your build directory location there and point glbinding_DIR (or better CMAKE_PREFIX_PATH) to glbinding's root directory. Let us know if this works.

I set CMake build directory to glbinding-3.1.0\build\x86 for Win32 target platform and edited the file as follows:

if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
        find_modules("build/x86/cmake")
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
        find_modules("build/x64/cmake")
endif()

It works without any errors. That is exactly what I was looking for.

Thanks!