cmake: oglplus can't find context initialization library (glfw) - cmake

I try to build oglplus (C++ wrapper for OpenGL) with cmake (on OS X 10.9 with Xcode 5 / Clang 5.0.0).
But to do so, there is a context initialization library neccesary (i.e. GLUT, GLFW, GLFW3, GL3W, QT4, SDL, wxWidgets). However I tried to compile and install GLFW and GLFW3 multiple times already: But the cmake file from oglplus still won't use them.
The cmake output says:
cmake -G Xcode
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Found GLEW: /usr/local/include /Library/Frameworks/GLEW.framework
-- Could NOT find GL3W
-- Could NOT compile or link with GLFW
-- Could NOT compile or link with GLFW3
-- Could NOT find GLUT (missing: GLUT_INCLUDE_DIR)
-- GLUT header file not found
-- Could NOT find wxWidgets (missing: wxWidgets_FOUND)
-- Could NOT find Qt4 (missing: QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR QT_QTCORE_INCLUDE_DIR QT_QTCORE_LIBRARY QT_QTGUI_INCLUDE_DIR QT_QTGUI_LIBRARY QT_QTOPENGL_INCLUDE_DIR QT_QTOPENGL_LIBRARY QT_UIC_EXECUTABLE)
-- Could NOT find SDL
-- GLM header files not found
-- Found PNG: /usr/local/include /usr/local/lib/libpng.dylib
-- Detecting support for c++11 feature 'SCOPED_ENUMS': TRUE
-- Detecting support for c++11 feature 'VARIADIC_MACROS': TRUE
-- Detecting support for c++11 feature 'VARIADIC_TEMPLATES': TRUE
-- Detecting support for c++11 feature 'UNIFIED_INITIALIZATION_SYNTAX': TRUE
-- Detecting support for c++11 feature 'INITIALIZER_LISTS': TRUE
-- Detecting support for c++11 feature 'DEFAULTED_FUNCTIONS': TRUE
-- Detecting support for c++11 feature 'DELETED_FUNCTIONS': TRUE
-- Detecting support for c++11 feature 'EXPLICIT_CONVERSION_OPERATORS': TRUE
-- Detecting support for c++11 feature 'FUNCTION_TEMPLATE_DEFAULT_ARGS': TRUE
-- Detecting support for c++11 feature 'UNICODE_LITERALS': TRUE
-- Detecting support for c++11 feature 'USER_DEFINED_LITERALS': TRUE
-- Detecting support for c++11 feature 'CONSTEXPR': TRUE
-- Detecting support for c++11 feature 'NOEXCEPT': TRUE
-- Detecting support for c++11 feature 'LAMBDAS': TRUE
-- Detecting support for c++11 feature 'NULLPTR': TRUE
-- Detecting support for c++11 feature 'CHRONO': TRUE
-- Detecting support for c++11 feature 'THREADS': TRUE
-- Could NOT find Boost
CMake Error at CMakeLists.txt:122 (message):
No OpenGL context initialization library found!
So it seems it can find GLFW/GLFW3, because for some reason it says Could NOT compile or link with * instead of Could NOT find *. I'm not really familiar with cmake scripts, so I don't know how to examine the reason here.
Any ideas what the problem could be here?

I've had a similar problem, it seems that GLFW is found and a test program is compiled to check that it works. Simply put, with the MSVC toolchain the test fails.
The simplest fix is to remove/rename the test program (oglplus/config/ext_lib/test_glfw.cpp and/or test_glfw3.cpp)

Have you read the documentation on GitHub? Direct extract:
CMake-based build configuration
The CMake script defines and uses several variables to modify the
build configuration, which can be specified on the command-line when
invoking cmake (with the -D option. see cmake manual for details):
HEADER_SEARCH_PATHS: (semicolon-separated) list of paths to additional directories to search when looking for 3rd-party headers like GL/glew.h, GL3/gl3.h, GL/glcorearb.h, etc.
LIBRARY_SEARCH_PATHS: (semicolon-separated) list of paths to additional directories to search when looking for 3rd-party binary libraries like GL, GLEW, GL3W, GLFW, SDL, GLUT, png, etc.
Furthermore, OGLplus is, in fact, a header-only library, so you could simply skip building examples/demos and tests so that no linkage with 3rd party libraries is required at all. You could even copy the headers to the location you want and just use it without running CMake (last time I used it, this approach worked fine, it might have changed, so check it at your own risk).

I know this is an old question, but I also had problems with it.
Just make sure that you specify the include- and lib-folders for glfw, glfw3 or whatever you want to use in cmake.

Related

cmake . -B build - Compiling Neural Graphic Primitives

I trying compile NGP but after cmake . -B build I get this lines:
I've installed
Visual Studio 2019
CUDA Toolkit 11.6
CMake 3.22
Python 3.10
Optix 7.6
C:\NGP\instant-ngp>cmake . -B build
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.29.30147.0
-- The CXX compiler identification is MSVC 19.29.30147.0
-- The CUDA compiler identification is NVIDIA 11.6.124
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- **Obtained CUDA architectures automatically from installed GPUs**
**CMake Error: The source directory "SOURCES/CMakeFiles/CMakeTmp" does not exist.**
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error at dependencies/tiny-cuda-nn/CMakeLists.txt:107 (try_run):
Failed to configure test project build system.
Call Stack (most recent call first):
dependencies/tiny-cuda-nn/CMakeLists.txt:146 (TCNN_AUTODETECT_CUDA_ARCHITECTURES)
-- Configuring incomplete, errors occurred!
See also "C:/NGP/instant-ngp/build/CMakeFiles/CMakeOutput.log".
I am not coder I just want to try NERF. It ss possible download somewhere compiled NGP or it doesn't work that way?
EDIT: Noticed that OP is using the -S flag implicitly the issue seems to be elsewhere, hence the updated answer:
UPDATED ANSWER
Please bare in mind that with the limited information at my disposal. This is again only a wild guess, based on what I tried.
After re-examining the output of CMake I've noticed that the issue is within one of the dependencies i.e.
CMake Error at dependencies/tiny-cuda-nn/CMakeLists.txt:107 (try_run):
I was not able to completely replicate the problem, however I do believe I know how to debug these issues. My wild guess here is that either:
The individual dependencies were incorrectly pulled or
The CMake files were poorly generated due to some issue and you didn't clean them.
I would recommend trying the following:
Delete the build folder, and run cmake -S. -Bbuild again. And if that fails you can try the second option.
Remove the git repository (folder called instant-ngp) and clone it again using exactly this command:
git clone --recursive https://github.com/nvlabs/instant-ngp
Please note that the --recursive option is very important due to the fact that you need to pull the dependant repositories as well.
Now if all of that fails. You still have one more option and that is to go to the folder dependencies/tiny-cuda-nn/ and generate the CMake files yourself, however I do not recommend that due to the fact that if you have limited experience you may not know what exactly to do.
I've also checked the variables you wanted to set, and you may do that by running this in Powershell
$Env:CMAKE_CUDA_ARCHITECTURES=YOUR_VALUE_HERE (in my case it is 75 because I have a RTX2080). However bare in mind that
You shouldn't need it, because the architecture is discovered for you
You need to delete the build folder in order to clean up the cached CMake files
Hope it helps!

CMake Setup for Dual Environment Builds

Goal
I am using CMake to make the build for my project which is an embedded firmware based on ARM Cortex platform built using arm-none-eabi-gcc-6.3.1 compiler, using VSCode Editor, and on Windows host. I am trying to make a second build for testing on the Windows system I am using for the same project.
The First Solution Problem
The issue I am having is that whenever I need to switch my build from production to test, I have to delete the build files and rerun the CMake command with the test argument, when I do not do that, the build does not change the ARM compiler to the one I intend to use (I am guessing it is a caching problem). I have tried make clean and make rebuild_cache thinking that it may clean the cache and solve the problem for me, and did not work.
A fresh build Example:
Project\build> cmake -G"MinGW Makefiles" -DTARGET_GROUP=test ..
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= C:/MinGW/bin/gcc.exe
CMAKE_CXX_COMPILER= C:/MinGW/bin/g++.exe
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: Path\to\Project\build
Project\build>make
(successful make)
The second build:
Project\build> cmake -G"MinGW Makefiles" -DTARGET_GROUP=production ..
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= Path/to/arm-gnu-toolchain/bin/arm-none-eabi-gcc.exe
CMAKE_CXX_COMPILER= Path/to/arm-gnu-toolchain/bin/arm-none-eabi-g++.exe
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: Path\to\Project\build
Project\build>make
(Cached make -did not change the compiler or the files to be built)
The CMakeLists.txt:
set(TARGET_GROUP test CACHE STRING "Group to build")
if(TARGET_GROUP STREQUAL production)
# ARM Lib
include("arm-gnu.cmake")
else()
include("win-gcc-for-testing.cmake")
endif()
# include the files based on the TARGET_GROUP value
# ...
Current Solution
Currently, I have a temporary solution by making a separate folder for each building type and they work perfectly.
The question
Is the current solution (making two build directories each is for a different environment) right in terms of best practices? If not, what could be a better one?
As #Tsyvarev says, you have to use different directories if you want different builds. Here you are trying to build both in the same build directory. Instead, create a subdirectory test to build the -DTARGET_GROUP=test, and a different subdirectory prod to build the -DTARGET_GROUP=production:
Project> mkdir test
Project> cd test
Project\test> cmake -G"MinGW Makefiles" -DTARGET_GROUP=test ..
Project\test> cd ..
Project> mkdir prod
Project> cd prod
Project\prod> cmake -G"MinGW Makefiles" -DTARGET_GROUP=production ..
Of course you can call the directories whatever you like.
Since you'd like this to integrate into VSCode, do the configuration change with the CMake build kits, which is what sets the compiler prior to calling CMake. You can specify additional user kit definitions, and in the VSCode interface choose between compiler kits.
Rewrite the CMake files just enough to condition everything else on the selection of compiler.
THEN, the VSCode cmake-tools extension supports variable expansion for the name of the build directory. Among the options are ${buildKit} and ${buildKitTargetArch}. Make this suffix part of the Build Directory setting (your choice of whether to set this only in your workspace, or more globally on your system).
Now, when you switch kits, CMake will pick up the directory change and happily exist with two different build directories.
Alternatively, cmake-tools now provides variants, which could be used to add additional Production and Test to the normal Release, Debug, RelWithDebInfo, etc. There are additional build directory expansion variables for information from the currently selected variant.

CMake automatically sets CXX upon first execution

I have a C++ project where I do not want to specify a "default" compiler, since it needs to be compiled with many different compilers in different contexts. (In unit testing and end-to-end testing, I do test it with a few different compilers.)
I tried to implement this in CMake by requiring that the user set the environment variable CXX before the initial CMake configuration (executing cmake). (I also have it drop a file to store the value to ensure that any subsequent invocation of make has the same value of CXX set, but that's irrelevant to the rest of the question.)
However, this doesn't actually work. Here is a minimal example and the execution output.
CMake configuration file:
project(test)
if(DEFINED ENV{CXX})
message("\$CXX = ${CXX}")
else()
message(SEND_ERROR "\$CXX must be defined by the user to compile this project.")
endif()
add_executable(test)
First execution of cmake:
-- The C compiler identification is GNU 4.3.4
-- The CXX compiler identification is GNU 4.3.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
$CXX =
-- Configuring done
CMake Error at CMakeLists.txt:9 (add_executable):
No SOURCES given to target: test
-- Build files have been written to: /hnfs/torcfs03n06a/vol/ret_users_sasquire/inactive/bugs/cmake
Second invocation of cmake in the same directory (with no cleanup):
CMake Error at CMakeLists.txt:6 (message):
$CXX must be defined to compile this project.
-- Configuring incomplete, errors occurred!
So the test whether CXX is defined is clearly working the second time, but not the first time.
Two questions:
How should I be implementing this?
I think that it is a somewhat reasonable behavior for cmake to set CXX internally if it wasn't set by the user, and I suspect that's what's happening in the first case. But why are the first and second runs different?
Some comments on item 1:
There are some obvious things, like introducing my own environment variable that is used to determine the compiler that cmake won't set on its own. But ideally I would just be able to get CMake to forego defining CXX, for example. Or perhaps there is functionality along the lines of GNU make's origin function, which can distinguish between variables set in the environment and variables set by default or in the makefile.
If the answer is basically "don't do that" (i.e. don't make the user define the compiler), then I am not going to consider it a constructive answer.
Comments on item 2:
To me, this looks like a bug in CMake, where it sets CXX while detecting the C++ compiler, and then it does not unset that variable afterwards. But is there a different way to look at this? Or is there documentation regarding this?
Just check CXX environment variable before project() call:
if(DEFINED ENV{CXX})
message("\$CXX = ${CXX}")
else()
message(SEND_ERROR "\$CXX must be defined by the user to compile this project.")
endif()
project(test)
CXX variable is used by CMake when detecting C++ compiler, and exactly project() call triggers that detection. So, why do you check the variable after the project() call if bad things have already happened?
As for setting the CXX environment variable internally by CMake, I would suggest to not care about that.
Anywhere, setting this variable for other purposes (not for compiler detection) would contradict with CMake usage of that variable.
For finding out which C++ compiler is used after the project() call, it is simpler to read CMAKE_CXX_COMPILER CMake variable.

CLion failing to detect C/C++ compiler ABI info

I have a custom toolchain for building projects. And by custom toolchain, I mean a derivative of the Clang C compiler, C++ compiler, and linker.
The project(s) build just fine, but I'm unable to use the Intellij features of CLion, because it can't build a tags database (or whatever it does under the hood) due to not being able to recognize the custom toolchain.
Thus, hitting Tools -> CMake -> Reset Cache and Reload Project spits out:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=~/<path-to-custom-toolchain>/Toolchain.cmake -G "CodeBlocks - Unix Makefiles" /Users/<project-directory>/src
-- Setting up Toolchain 1.0 at /Users/<tools>/build
-- Setting up Toolchain 1.0 at /Users/<tools>/build
-- The C compiler identification is Clang 7.0.0
-- The CXX compiler identification is Clang 7.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - failed
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- Configuring done
Screenshot of the preference options for the project (It's a link because I don't have the rep required to post images yet):
Project Preferences
So my question is, how should I go about solving this problem? Or does this problem exceed the limitations of CLion? Or do I have an incomplete understanding of the problem?

Cmake for Intel OpenVino project complains about feature_defs and missing OpenVino extensions directory

I tried to compile this OpenVino sample project: https://github.com/intel-iot-devkit/intruder-detector
When I do the cmake, I don't know why it is asking for feature_def, I don't understand what that means.
I'm also troubled at how /opt/intel//computer_vision_sdk_2018.4.420/deployment_tools/inference_engine/samples/extension is said to be a non-existent directory. It indeed does not exist. i tried reinstalling OpenVino several times, and that did not solve the problem. Please help, any advice will be appreciated. Thanks in advance.
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:11 (include):
include could not find load file:
feature_defs
CMake Error at CMakeLists.txt:13 (add_subdirectory):
add_subdirectory given source
"/opt/intel//computer_vision_sdk_2018.4.420/deployment_tools/inference_engine/samples/extension"
which is not an existing directory.
-- Configuring incomplete, errors occurred!
See also "/home/user/intruder- detector/application/build/CMakeFiles/CMakeOutput.log".
This seems like quite a complete problem as the repo isn't maintained properly. I do not have a full, direct solution to your problem but hopefully this will guide you in the right direction (if you don't want to wait for the owners to do the changes).
This fairly recent git issue asked for fixes for essentially the same exact problem you have, except on another project in that repo. That being said, it seems it has been fixed there.
Sadly, the fix commits are a massive reupload of the whole project with new, updated files; the CMakeLists included. The new CMakeLists.txt (found here) of that project is your best bet at fixing the issue yourself, by comparing it to yours and figuring out the changes here and there. However, since the whole thing was modified, it's possible that the dependencies and such aren't too similar but hopefully not missing.
That being said, I think that's a good starting point and you should also post an issue on that git so that the owner can do something about it asap.