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.
Related
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.
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)
I am asking this to verify that my code is implemented correctly. If it is, then that more than likely means that my library linkage is incorrect at some point, which narrows down the problem. I'm getting the following errors upon trying to build my test using make t1:
make[3]: *** No rule to make target `/home/esias/VL3/modular2/vlMain/test', needed by `vlMain/CMakeFiles/t1'. Stop.
make[2]: *** [vlMain/CMakeFiles/t1.dir/all] Error 2
make[1]: *** [vlMain/CMakeFiles/t1.dir/rule] Error 2
Suppose I would like to build executable "exec1" and test it. Ideally, this is done by tagging the executable to a target and running make <target> - please correct me if I'm wrong.
As far as I am aware, this is done by using the --build-and-test argument on add_test. This is the code I am using:
ADD_TEST(test1 exec1
--build-two-config
--build-and-test
"${CMAKE_SOURCE_DIR}/vlMain/vlMPIMain.cpp" #source to create from?
"${CMAKE_BINARY_DIR}/Tests/exec1" #output folder?
)
add_custom_target(t1 COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test1)
TARGET_LINK_LIBRARIES(t1
${GLEW_LIBRARY}
vlapp
vlrender
vldm
)
I would like to build an executable called "exec1" using ${CMAKE_SOURCE_DIR}/vlMain/vlMPIMain.cpp as source code, and put it into ${CMAKE_BINARY_DIR}/Tests/exec1 Then I would like to link a couple of libraries to it.
Is my implementation correct? Can it be improved?
Thanks.
I'm creating a software project and I wanted to use autotools to do the makefile and etc. script generation for me, I manually created Makefile.am and configure.in files, and I'm using the autogen.sh script from here. The problem comes when attempting to build the project in a separate 'build' directory, e.g. if I go:
mkdir build
cd build
../configure
make
The configure step works fine, but when running make I get:
make all-recursive
Making all in src
/bin/sh: line 0: cd: src: No such file or directory
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Any tips to get this working? Or should I give up and try something simpler/different.
I plan for this to be a reasonably simple C++ project, and the only dependency I plan to have is on the boost unit testing framework, and to do most development in Eclipse IDE.
there's a bug in your src/Makefile.am, line#17:
swin-adventure_SOURCES = src/main.cc
should really read:
swin-adventure_SOURCES = main.cc
since you are already in the src/ directory (unless there's a src/src/ subfolder)
there's another bug, as you are using special characters in your _SOURCES variabes: swin-adventure_SOURCES has the forbidden - character; try to normalize that to swin_adventure_SOURCES
finally, you are trying to assign a value to bin_PROGRAMS multiple times (and each time the same value), try to avoid that.
something like:
## Additional flags to pass to aclocal when it is invoked automatically at
## make time. The ${ACLOCAL_FLAGS} variable is picked up from the environment
## to provide a way for the user to supply additional arguments.
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
## Define an executable target "swin-adventure", which will be installed into the
## directory named by the predefined variable $(bindir).
bin_PROGRAMS = swin-adventure
## Define the list of source files for the "swin-adventure" target. The file
## extension .cc is recognized by Automake, and causes it to produce rules
## which invoke the C++ compiler to produce an object file (.o) from each
## source file. The ## header files (.h) do not result in object files by
## themselves, but will be included in distribution archives of the project.
swin_adventure_SOURCES = main.cc
I have downloaded the source of GoldenDict using Git, and run lrelease for the locales. Now I have a weird problem where I get this makefile log:
14:55:54: Running build steps for project goldendict...
14:55:54: Starting: "c:\qtsdk\desktop\qt\4.8.1\msvc2010\bin\qmake.exe" D:\GoldenDictSrc\goldendict\goldendict.pro -r -spec win32-msvc2010 "CONFIG+=release"
14:55:56: The process "c:\qtsdk\desktop\qt\4.8.1\msvc2010\bin\qmake.exe" exited normally.
14:55:56: Starting: "C:\QtSDK\QtCreator\bin\jom.exe"
C:\QtSDK\QtCreator\bin\jom.exe -f Makefile.Release
Error: dependent 'folding.cc' does not exist.
jom 1.0.8 - empower your cores
jom: D:\GoldenDictSrc\goldendict-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Release\Makefile [release] Error 2
14:55:56: The process "C:\QtSDK\QtCreator\bin\jom.exe" exited with code 2.
Error while building project goldendict (target: Desktop)
When executing build step 'Make'
while the file folding.cc is available in the same directory, in which the qmake file is.
I have even tried adding the absolute path of folding.cc to the qmake file, but no use.
I'm using QtCreator.
What can be causing this?
Thank you for any efforts.
I have the same problem, and narrowed it down to the fact that QT only supports 122 characters for the path+filename of all dependent files (#includes or .cpp files).
If the path (relative or otherwise) is 123 characters or more, qt gives this error.
Just shorten your folder names, or filename to get the full path+filename to 122 characters or less.