Meson generator looks for source files in wrong folder, how to fix that? - meson-build

Im generating header sources in folder not within build directory:
gen_rpc = generator(protoc, \
output : [ '#BASENAME#.grpc.pb.cc', '#BASENAME#.grpc.pb.h','#BASENAME#.pb.cc', '#BASENAME#.pb.h'],
arguments : ['--proto_path=#CURRENT_SOURCE_DIR#/' + proto_path,'--grpc_out=#CURRENT_SOURCE_DIR#/' + grpc_proto_include_dir,'--cpp_out=#CURRENT_SOURCE_DIR#/' + grpc_proto_include_dir, '--plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin', '#INPUT#'])
generated_rpc = gen_rpc.process(proto_path + 'sources.proto')
and folder tree looks like this:
./proto/include/
'#BASENAME#.grpc.pb.cc', '#BASENAME#.grpc.pb.h','#BASENAME#.pb.cc', '#BASENAME#.pb.h'
./build/app.p/
and get this error:
Compiling C++ object app.p/meson-generated_sources.pb.cc.o
ccache c++ .... -MD -MQ app.p/meson-generated_sources.pb.cc.o -MF app.p/meson-generated_sources.pb.cc.o.d -o app.p/meson-generated_sources.pb.cc.o -c app.p/sources.pb.cc
cc1plus: fatal error: app.p/sources.pb.cc: No such file or directory
compilation terminated.
Not sure how to tell meson that source files are generated in other folder?

Related

How can I tell CMake to put include directory flags after the compiler option flags in its object compile command?

I am facing problems due to the target holding the include paths first and then the compiler options after. How can I set the include paths after the compiler options for compiling source files of a target?
My CMakeLists.txt file:
project(HelloWorld)
cmake_minimum_required(VERSION 3.0)
add_library(HELLO_WORLD_LIB
STATIC
src/helloWorld.cpp
)
target_include_directories(
HELLO_WORLD_LIB AFTER PUBLIC D:\\temp\\includes
)
target_compile_options(HELLO_WORLD_LIB BEFORE PUBLIC -cpp -remap)
set_target_properties(HELLO_WORLD_LIB
PROPERTIES
OUTPUT_NAME hello
ARCHIVE_OUTPUT_DIRECTORY D:\\temp\\CMakeHelloWorld
SUFFIX .a
)
My cmake call:
call cmake -GNinja -S ./.. -DCMAKE_INSTALL_PREFIX=../_bin
call cmake --build . --config Debug --verbose -d keeprsp
call cmake --install .
The console output:
-- Configuring done
-- Generating done
-- Build files have been written to: D:/temp/CMakeHelloWorld/_build
[1/2] C:\mingw\test25_comp_8.1.0_testversion\bin\c++.exe -ID:/temp/includes -cpp -remap -MD -MT CMakeFiles/HELLO_WORLD_LIB.dir/src/helloWorld.cpp.obj -MF CMakeFiles\HELLO_WORLD_LIB.dir\src\helloWorld.cpp.obj.d -o CMakeFiles/HELLO_WORLD_LIB.dir/src/helloWorld.cpp.obj -c ../src/helloWorld.cpp
[2/2] cmd.exe /C "cd . && C:\toolbase\_ldata\cmake\.8-3.20.2\bin\cmake.exe -E rm -f ..\libhello.a && C:\mingw\test25_comp_8.1.0_testversion\bin\ar.exe qc ..\libhello.a CMakeFiles/HELLO_WORLD_LIB.dir/src/helloWorld.cpp.obj && C:\toolbase\mingw\test25_comp_8.1.0_testversion\bin\ranlib.exe ..\libhello.a && cd ."
-- Install configuration: ""
However if I try to add the include paths after compiler options, it sits before the compiler options. How can I set the compiler options before the include directories? like C:\toolbase\mingw\test25_comp_8.1.0_testversion\bin\c++.exe -cpp -remap -ID:/temp/includes.
The relevant CMake variable is CMAKE_CXX_COMPILE_OBJECT, which is the configuration point for what template to use for the command to compile an object. The default value is set in Modules/CMakeCXXInformation.cmake, and overrides are specified in various Modules/Platform/* or Modules/Compiler/* files. If you're curious, you can grep for the overrides with the following regex: set.*CXX_COMPILE_OBJECT.
The default one is set like this:
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
You probably want something like this (set it in your own CMakeLists.txt file, or in a toolchain file):
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> <INCLUDES> -o <OBJECT> -c <SOURCE>")
As far as I can tell, this configuration point is "global". I'm not aware of how to specify it with different values for different targets or source files.
If you're working with the Ninja generator and need this kind of change to affect the generated .rsp files, I think you'd need to build a modified version of CMake from source, since that behaviour seems to be baked into the binaries instead of CMake script files in the Modules/ directory. The relecant source file is Source/cmNinjaTargetGenerator.cxx. Look at the lines of code that do rule.RspContent = and you'll see:
rule.RspContent =
cmStrCat(' ', scanVars.Defines, ' ', scanVars.Includes, ' ', scanFlags);
You'd probably need to switch the order of scanVars.Includes and scanVars.scanFlags.
If you choose to make a modified CMake binary, as always, make sure you comply with the software licence.

How to fix this gnu issue this is my output

[Running] cd "c:\Users\dead\Documents\vs code\C++" && g++ new -o c:\Users\dead\Documents\vs code\C++\new && "c:\Users\dead\Documents\vs code\C++"c:\Users\dead\Documents\vs code\C++\new
g++: error: code\C++\new: No such file or directory
[Done] exited with code=1 in 0.455 seconds
I assume you are using Code Runner.
In your output, you are trying to build a file called new, this is not acceptable by g++, you should change its name with .cpp or .cxx end.

Why is my MakeFile path setup getting a "No such file or directory" error?

I am trying to run a makefile. I think the makefile is trying to access this path:
/home/s/miniconda3/lib/python3.7/site-packages/tensorflow/include/unsupported/Eigen
But when I run it, I get a No such file or directory error:
(base) s#s-VirtualBox:~/Downloads/3d-psrnet-master$ make
make: Circular utils/tf_ops/cd/tf_nndistance_g.cu <- utils/tf_ops/cd/tf_nndistance_g.cu.o dependency dropped.
/usr/local/cuda-10.1/bin/nvcc -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o utils/tf_ops/cd/tf_nndistance_g.cu.o utils/tf_ops/cd/tf_nndistance_g.cu -I /home/s/miniconda3/lib/python3.7/site-packages -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
utils/tf_ops/cd/tf_nndistance_g.cu:3:10: fatal error: include/unsupported/Eigen: No such file or directory
#include "include/unsupported/Eigen"
^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [makefile:12: utils/tf_ops/cd/tf_nndistance_g.cu.o] Error 1
I have it set like this at the top of makefile: tensorflow = /home/s/miniconda3/lib/python3.7/site-packages (which is the path that shows up if I type into Terminal pip show tensorflow)
And then in tf_nndistance_g.cu I have:
#include "include/unsupported/Eigen/"
What might be the reason that this makefile isn't working? I'm using Python 3.7 on a Virtual Machine (ubuntu Virtualbox). Thanks.

Force CMake to use absolute include path

I have a project whose directory layout looks like:
- src/ #Contains main source code
- ext/ #Contains external libraries and headers from GitHub
- CMakeLists.txt
The problem is that no matter what I do, CMake always seems to pass ext/ to the compiler as a relative path, like this:
/usr/bin/c++ -I../ext mysrc.cpp
I've tried doing both:
include_directories("${PROJECT_SOURCE_DIR}/ext")
include_directories("/home/user/project/ext")
But it doesn't seem to matter. The directory is always passed to -I as ../ext.
Why does this matter? At the end of my build I invoke gcov -r <source file> which tells gcov to generate coverage reports from my source file and any relative paths found within. As a result, gcov is going into ext/ and generating reports for tons of stuff I don't care about and it's taking up a lot of time. If CMake would instead pass in -I/home/user/project/ext then gcov -r would ignore everything in ext/.
As far as I can tell from:
https://cmake.org/cmake/help/v3.13/command/include_directories.html ... this isn't possible, but maybe I'm just missing something?
Edit: This appears to be a problem with specifically the ninja generator. When using the Unix Makefiles generator, everything is passed via absolute paths.
https://gitlab.kitware.com/cmake/cmake/issues/18666
Edit2:
user#antimony:~/cmake_test$ ls
CMakeLists.txt ext src
user#antimony:~/cmake_test$ cat CMakeLists.txt
project(Hello)
add_subdirectory(src)
user#antimony:~/cmake_test$ cat src/CMakeLists.txt
include_directories(
.
${PROJECT_SOURCE_DIR}/ext
)
add_executable(hello_world hello.cpp)
user#antimony:~/cmake_test$ cat src/hello.cpp
#include <useless.h>
int main()
{
hello h;
return 0;
}
user#antimony:~/cmake_test$ cat ext/useless.h
struct hello {
int x;
};
user#antimony:~/cmake_test$ ~/Downloads/cmake-3.13.1-Linux-x86_64/bin/cmake --version
cmake version 3.13.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
user#antimony:~/cmake_test$ mkdir build && cd build
user#antimony:~/cmake_test/build$ ~/Downloads/cmake-3.13.1-Linux-x86_64/bin/cmake .. -G Ninja
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
...
-- Build files have been written to: /home/user/cmake_test/build
user#antimony:~/cmake_test/build$ ninja -v
[1/2] /usr/bin/c++ -I../src/. -I../ext -MD -MT src/CMakeFiles/hello_world.dir/hello.o -MF src/CMakeFiles/hello_world.dir/hello.o.d -o src/CMakeFiles/hello_world.dir/hello.o -c ../src/hello.cpp
[2/2] : && /usr/bin/c++ -rdynamic src/CMakeFiles/hello_world.dir/hello.o -o src/hello_world && :
user#antimony:~/cmake_test/build$ cat build.ninja
# CMAKE generated file: DO NOT EDIT!
# Generated by "Ninja" Generator, CMake Version 3.13
# This file contains all the build statements describing the
# compilation DAG.
...
#############################################
# Order-only phony target for hello_world
build cmake_object_order_depends_target_hello_world: phony || src/CMakeFiles/hello_world.dir
build src/CMakeFiles/hello_world.dir/hello.o: CXX_COMPILER__hello_world ../src/hello.cpp || cmake_object_order_depends_target_hello_world
DEP_FILE = src/CMakeFiles/hello_world.dir/hello.o.d
INCLUDES = -I../src/. -I../ext
OBJECT_DIR = src/CMakeFiles/hello_world.dir
OBJECT_FILE_DIR = src/CMakeFiles/hello_world.dir
TARGET_COMPILE_PDB = src/CMakeFiles/hello_world.dir/
TARGET_PDB = src/hello_world.pdb
# =============================================================================
# Link build statements for EXECUTABLE target hello_world
The example shows what may be considered an in-source build. That is when the build directory is the same or a sub-directory of the src folder (not that there is a hard definition or anything, but this does trigger the ninja issue of using relative paths on the command line). Try mkdir ~/cmake_build && cd ~/cmake_build && cmake ~/cmake_test then it should use absolute paths for everything.
Either way there really isn't a specific way to force one or the other. In general cmake generators will use absolute paths for everything that ends up used on the command line. There seems to be issues with Ninja that prevent the generator from using absolute paths for in-source builds (https://github.com/ninja-build/ninja/issues/1251).

generate CMakeList.text for OS X

I'm trying to create a plugin for OBS using C, and compiling it using cmake .. && make see - https://github.com/jp9000/obs-studio/wiki/Install-Instructions#mac-osx
when running cmake .. && make from cmd it gives me an error that cmake: command not found and when I run it from the program it gives me an error - CMake Error: The source directory "/Users/gerwin/Desktop/soOBS" does not appear to contain CMakeList.text specify --help for usage, or press the help button on the cmake GUI
How can I generate a CMakeList.Text to compile my soOBS script to a .so file?
One problem is that cmake is not in your path. So, if you type cmake from your command line it cannot be found. The other problem is that you are not specifying correctly your source directory: you have to specify as source directory the location of the main/root CMakeLists.txt.
So, proceed as follow:
Locate your cmake executable, obtaining your <full path to cmake>
Open a shell
Go to your source directory (location of the main/root of obs-studio CMakeLists.txt)
mkdir build
cd build
<full path to cmake> ..The first argument .. is your source directory, location of the main CMakeLists.txt
make