CMake illogic path parsing? - c++

I'm trying to include this project into my cmake code base.
I cloned the repo to my include/ dir and added this line to my CMakeLists.txtx:
add_subdirectory(${DIVISIBLE_INSTALL_INCLUDE_DIR}/cc.ublox.commsdsl)
include_directories(${DIVISIBLE_INSTALL_INCLUDE_DIR})
link_directories(${DIVISIBLE_INSTALL_INCLUDE_DIR})
But when I try to rebuild my project it says that it can't find the defined scheme files:
[WARNING]: failed to load external entity "/Users/pete/Documents/projekte/simple-dgps/dsl/main.xml"
If I add the project prefix(PROJECT_SOURCE_DIR) to the scheme files path the path appears twice.
ERROR: Failed to parse/Users/pete/Documents/projekte/simple-dgps/Users/pete/Documents/projekte/simple-dgps/include/cc.ublox.commsdsl/dsl/main.xml
And if I fill the missing part between simple-dgps and dsl (which would be include/cc.ublox.commsdsl) I get this error:
make[2]: *** No rule to make target `include/cc.ublox.commsdsl/include/cc.ublox.commsdsl/dsl/main.xml', needed by `output.tmp'. Stop.
make[1]: *** [include/cc.ublox.commsdsl/CMakeFiles/cc.ublox.commsdsl.dir/all] Error 2
make: *** [all] Error 2
Assuming that the first error relates to a wrong file location, what does the second mean then(although it clearly has the wrong path because it exists twice)

The problem definitely seems to be with defining the project path for cc.ublox.commsdsl vs the project path for your project.
If I add the project prefix(PROJECT_SOURCE_DIR) to the scheme files path the path appears twice.
Can you share what you added? /Users/pete/Documents/projekte/simple-dgps/include/cc.ublox.commsdsl/dsl/main.xml looks right for the cc.ublox.commsdsl path - but it seems you may have added the path such that it gets duplicated. Hard to tell what's wrong without looking at what you added.

Found the problem for the double path problem.
I added the project as subdir from my main project by adding this line:
add_subdirectory(${DIVISIBLE_INSTALL_INCLUDE_DIR}/cc.ublox.commsdsl)
The problem is that DIVISIBLE_INSTALL_INCLUDE_DIR is a absolute path and thus is added to the cmake source dir of the subdir.
This can be fixed by using:
add_subdirectory(include/cc.ublox.commsdsl)

Related

CMake fails to create directory with a specific name `models`

I am trying to create custom directories and copy files into a test folder during the build process of CMake. (This is needed so I can conveniently run a test script that tests another executable which requires certain directories to be available. The target does not actually build any real outputs.)
The goal is to create empty directories called models and logs in the build directory of my target, custom-test.
The CMake command I am using in CMakeLists.txt:
add_custom_target(custom-test ALL
COMMAND ${CMAKE_COMMAND} -E make_directory models logs
)
# Copy files into build dir and the dirs created above
configure_file("config.json" . COPYONLY)
configure_file("temp-model.txt" ./models COPYONLY)
When I build, the logs directory is always created successfully, but weirdly the models directory always produces a build error:
Error creating directory "models".
make[2]: *** [tests/custom-test/CMakeFiles/custom-test.dir/build.make:71: tests/custom-test/CMakeFiles/custom-test] Error 1
make[1]: *** [CMakeFiles/Makefile2:451: tests/custom-test/CMakeFiles/custom-test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
If I run ls -l tests/custom-test from the BUILD directory, I can see the following entries, which shows that logs was created but models is some kind of dead filepath:
drwxrwxr-x 2 reid reid 4096 Nov 1 10:58 logs
-rw-rw-r-- 1 reid reid 0 Nov 1 10:58 models
My question is why is it only failing to create the models directory? I tried renaming the directory name to modelsdir and other names instead and those all seem to work. But my other applications that I am testing expect there to be a directory called models.
Possibly important side-note: Previously, in my source code I had a subdirectory called models that created a cmake library target models. I have since completely refactored this to another name since I thought cmake might be getting confused, even though that library was unrelated to this test target. I have deleted and regenerated my build directory several times since the refactor which has not helped.
Any help is greatly appreciated :)
EDIT I actually think it may have more to do with the configure_file commands that copy into the newly created directory.

How to deal with the CMake Error: Target DependInfo.cmake file not found

I used CLion to write some c++ source files(The specific code are not important as far as this question is concerned). However, one project can only have one main() function although these main() functions are in different source files. So in the CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(_CODE__20220116_CppTyro)
set(CMAKE_CXX_STANDARD 17)
add_executable(_CODE__20220116_CppTyro main.cpp 0001HelloWorld.cpp 0002Square.cpp)
add_executable(0001HelloWorld 0001HelloWorld.cpp)
add_executable(0002Square 0002Square.cpp)
I wrote these in order to run two or more main() functions in one C++ project.
But an error occurred:
====================[ Build | 0001HelloWorld | Debug ]==========================
"D:\CLion 2021.2\bin\cmake\win\bin\cmake.exe" --build (Here is the path of source file)
CMake Error: Target DependInfo.cmake file not found
[ 50%] Building CXX object CMakeFiles/0001HelloWorld.dir/0001HelloWorld.cpp.obj
G__~1.EXE: error: (Here is the path of source file): No such file or directory
G__~1.EXE: fatal error: no input files
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles\0001HelloWorld.dir\build.make:71:
CMakeFiles/0001HelloWorld.dir/0001HelloWorld.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:112: CMakeFiles/0001HelloWorld.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:119: CMakeFiles/0001HelloWorld.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: 0001HelloWorld] Error 2
I don't know why this error occurred and how to deal with it.
With the help of kiner_shah, I found the solution.
That is, never let your name of project and path include '[' or ']', especially in the first letter.
In my question, I didn't give the specific path of the source file because I thought it was not important. However, I found every time I built this project a new folder would be generated whose name was similar to the path of project. For example:
The project path is
D:\[CODE]Language_Learning\[CODE]Cpp_Learning
And it will generate a folder named(pay attention to that there is no backword slash)
[CODE]Language_Learning[CODE]Cpp_Learning
in the disk D, and CLion will find related file in this folder!
Because this was a new folder, there was no file related to this project and an error occurred.
But if the project path is
D:\Language_Learning\Cpp_Learning
no error occurred.
The reason why it happened is not clear(maybe just a bug), but this question is solved.

CMake successful, resulting makefile error

This is a follow-up question to one that I asked previously, which if it pleases you may be found here. To summarize, I have been trying to understand the build process for linking necessary libraries into OpenGL. I am aware that there are boilerplates and other methods that make this process easier; I am interested in being able to do so autonomously.
My issue is that although CMake sucessfully processes my CMakeLists.txt file, the resulting Makefile throws an error. If helpful, my file structure is
contextualized here:
+ infuriating_project
+ bin // post compile results
+ src // my humble code
+ deps // external code
+glew
+ include
+ src
+glfw
+ include
+ src
+glm
+soil
+ lib
+ src
Here are the contents of my CMakeLists.txt file:
cmake_minimum_required (VERSION 3.0)
# Version Information ---------------------------------------------------------
project (openGL-practice)
SET (VERSION_MAJOR 1)
SET (VERSION_MINOR 0)
SET (VERSION_FEATURE 0)
SET (VERSION_PATCH 0)
SET (VERSION "${VERSION_MAJOR}.${VERSION_MINOR}")
SET (VERSION "${VERSION}.${VERSION_FEATURE}.${VERSION_PATCH}")
MESSAGE ("Version: ${VERSION}")
# Configure Binary Directories ------------------------------------------------
SET (PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}/bin")
MESSAGE ("Source path: ${PROJECT_SOURCE_DIR}")
MESSAGE ("Binary path: ${PROJECT_BINARY_DIR}")
# Configure Depenency Directories ---------------------------------------------
SET (deps "${PROJECT_SOURCE_DIR}/deps")
MESSAGE ("Dependencies path: ${deps}")
SET (glew_inc "${deps}/glew/include/GL/")
SET (glew_src "${deps}/glew/src/")
SET (glfw_inc "${deps}/glfw/include/GLFW/")
SET (glfw_src "${deps}/glfw/src/")
SET (glm "${deps}/glm/glm/")
SET (soil_lib "${deps}/lib/")
SET (soil_src "${deps}/src/")
# Include directories ---------------------------------------------------------
include_directories("
${PROJECT_SOURCE_DIR}
${glew_inc}
${glew_src}
${glfw_inc}
${glfw_src}
${glm}
${soil_lib}
${soil_src}
")
# Add executable --------------------------------------------------------------
add_executable(main ${PROJECT_SOURCE_DIR}/src/main.cpp)
Upon completion, I get the following error when running make:
CMakeFiles/main.dir/flags.make:10: *** missing separator. Stop.
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
My investigations of this error have led me to believe that there is a syntax error, likely a tabs vs spaces error as indicated here. I am sure that this is an issue on my behalf, and not a bug in CMake. I am confident that there should be a way to alter my CMakeLists file such that this issue does not occur.
The Makefile is a bit lengthy for this already lengthy post. If it would be helpful for me to upload it, I can edit this question with that information. Thank you very much in advance for any and all help or advice.
This is wrong:
include_directories("
${PROJECT_SOURCE_DIR}
${glew_inc}
${glew_src}
${glfw_inc}
${glfw_src}
${glm}
${soil_lib}
${soil_src}
")
Do not quote this as one long string: cmake will try to provide this string (including newlines) as the argument to -I in your compiler.
Use:
include_directories(
${PROJECT_SOURCE_DIR}
${glew_inc}
${glew_src}
${glfw_inc}
${glfw_src}
${glm}
${soil_lib}
${soil_src}
)
Or, quote each path individually if you want to.

Building mathgl on windows

I am kind of new to C++ (used to be a Java developer, where this is way easier...) and I have to write an application, which has to plot some graphs and charts. To do so I want to use the MathGL library. And I learned, that I have to compile it myself in order to use it. So that's what I'm trying to do the last few days...
I am using Windows with MinGW and the CLion IDE.
I started by extracting MathGL's source code into a folder and opening the folder with CLion.
Then I downloaded the source codes of zlib and libpng and set the INCLUDE_DIR variables in the MathGL project to the respective folders and PNG_PNG_LIBRARY to png32. When I try to compile mgl_example via CLion it gives me the following error:
In file included from [...]\mathgl-2.3.5.1\src\data_png.cpp:22:0:
[...]/libpng-1.6.29/png.h:361:27: fatal error: pnglibconf.h: No such file or directory
compilation terminated.
mingw32-make.exe[2]: *** [src/CMakeFiles/mgl.dir/data_png.cpp.obj] Error 1
mingw32-make.exe[2]: *** Waiting for unfinished jobs....
src\CMakeFiles\mgl.dir\build.make:465: recipe for target 'src/CMakeFiles/mgl.dir/data_png.cpp.obj' failed
mingw32-make.exe[2]: Leaving directory '[..]/mathgl-2.3.5.1/cmake-build-debug'
mingw32-make.exe[1]: *** [src/CMakeFiles/mgl.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
CMakeFiles\Makefile2:89: recipe for target 'src/CMakeFiles/mgl.dir/all' failed
mingw32-make.exe[1]: Leaving directory '[...]/mathgl-2.3.5.1/cmake-build-debug'
Makefile:129: recipe for target 'all' failed
EDIT: I managed to fix that first error by copying the prebuilt pnglibconf.h from the scripts directory of the libpng source code. After that the definition of byte in the MinGW header rpcndr.h seems to interfer with the byte(double) method in oPRCFile.cc, which I just fixed by renaming the method to byteN and calling it from a macro (#define byte(c) byteN(c)). Although this might not be the right way to go, it works.
But having that all fixed the linker seems to be configured wrongly: it says cannot find -lpng32. How can I fix that one?
EDIT: Alright, it's compiled. So I copied libmgl.a and put it into the project I want to use it it. I linked against it with cmake by calling target_link_libraries(Test ${CMAKE_SOURCE_DIR}/libmgl.a) but it just throws a bunch of undefined reference to errors (same if I use the procompiled binaries):
MakeFiles\Test.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAC2Ev':
c:/mingw/include/mgl2/abstract.h:156: undefined reference to `_imp___ZTV8mglDataA'
CMakeFiles\Test.dir/objects.a(main.cpp.obj): In function `ZN8mglDataAD2Ev':
c:/mingw/include/mgl2/abstract.h:157: undefined reference to `_imp___ZTV8mglDataA'
[...]
It looks like that missing header file is generated after running a configure for libpng (which under Windows you may be unable to do and need to generate yourself -> Cannot open include file: 'pnglibconf.h':No such file or directory)
But besides that, how did you get the impression that you need to build it from scratch in order to use it? You can also download the precompiled binaries and link them with your program (http://mathgl.sourceforge.net/doc_en/Installation.html - point 2).
edit: Looking at your edit, you need to specify the actual library file in Windows (probably something along the lines of png32.a or whatever your libpng compilation generated), assuming the linker also has the path where the library file is (see http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use)

CMAKE on (tortoisesvn) SVN project :: Error in configuring process, project files may be invalid

I have checked out a version of project from SVN. Below are the different kinds of errors I got while trying to CMAKE a project from SVN. Could it be that some of the files are not checked out? Please, go through the three kinds of errors and help me out with it.
==================Type 1==================================
CMake Error at CMakeLists.txt:184 (add_subdirectory):
add_subdirectory given source "google/gmock" which is not an existing
directory.
==================Type 2==================================
Subversion executable was not found.
CMake Error at CMakeLists.txt:14 (UpLinqSVN_WC_INFO):
Unknown CMake command "UpLinqSVN_WC_INFO".
Call Stack (most recent call first):
CMakeLists.txt:207 (CreateVersionInfo)
========================TYPE 3==========================================
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FFMPEG_AVCODEC_LIB
linked by target "UpLinq" in directory C:/Users/Krishna/Desktop/2.5/GUI
FFMPEG_AVCORE_LIB
linked by target "UpLinq" in directory C:/Users/Krishna/Desktop/2.5/GUI
FFMPEG_AVDEVICE_LIB
linked by target "UpLinq" in directory C:/Users/Krishna/Desktop/2.5/GUI
Configuring incomplete, errors occurred!
Error 1 indeed indicates that the CMakeLists.txt expected there to be a directory called google/gmock (relative to the CMakeLists.txt which is calling add_subdirectory at line 184).
Without more info, there's no way to tell if this is an error in the CMakeLists file or in the repository.
The first part of error 2 (can't find Subversion exe) looks like a custom error message. It may be looking for a ".svn" folder in the project root, and assuming that Subversion is available. Presumably it then looks for the Subversion exe and fails to find it (not in path maybe?)
The second part of error2 (unknown CMake command) is saying that at line 14 of CMakeLists.txt, there's a command called UpLinqSVN_WC_INFO being invoked. It doesn't recognise this as a valid command, which probably means that it's defined as a function or macro in another CMake file somewhere. It would need to be defined before it's invoked at line 14. It could be that the CMakeLists.txt you're executing is expected to be run as part of a larger build, which would define this function before starting on your CMakeLists.txt.
Error 3 is saying that there's a CMake target called "UpLinq" (an exe or lib) which has a dependency on ${FFMPEG_AVCODEC_LIB}. At some point, there's probably been a find_library call looking for the avcodec library which has also failed. The result of the search is held in the variable FFMPEG_AVCODEC, and it shows that ${FFMPEG_AVCODEC} has a value of FFMPEG_AVCODEC-NOTFOUND.
If you need more help than this, you'll need to put up a copy of the relevant parts of the CMakeLists files involved, and a bit more info about your environment / directory structures.