I have a file structure that looks like this:
Projects/
- ProjA/
- ProbB/
- src/
- CMakeLists.txt
- ProjC/
- backend/
- src/
- ll/
- os/
-zephyr/
- ll_driver.c
- include/
- ll/
- os/
- zephyr/
- ll_driver.h
I am trying to include a piece of code written for another project (ProjC/) in the ProjB/ project. The CMakeLists.txt for that project looks like this:
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(blinky-projb-test)
set(projc ../../ProjC/backend)
set(LLBC ${projc}/src/ll)
set(LLBC_Z ${projc}/src/ll/os/zephyr)
set(LLBH ${projc}/include/ll)
set(LLBH_Z ${projc}/include/ll/os/zephyr)
file(GLOB app_sources src/*.c)
file(GLOB extra_sources
${LLBC}/ll_driver.c)
target_sources(app PRIVATE ${app_sources} ${extra_sources})
target_include_directories(app PRIVATE
${LLBH}
${LLBH_Z}
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include
)
So, clearly, I am intending to include ../../ProjC/backend/..., but the build fails. In the error message it is stated cmake is trying to include something else, however. It tries to do this: -I../../../ProjC/backend/include/ll. It seems like there's an extra ../ there, and I don't know why. I have not found anything about this issue in the documentation.
I'd appreciate it if someone can tell me why it behaves like this, or direct me to some resources where I can read more about this.
Related
I would like to get the "expanded CMakeLists.txt" that replace each include(foo.cmake) with corresponding content. Don't know if it is possible.
For example, I have CMakeLists.txt with contents:
cmake_minimum_required(VERSION 3.20)
project(hello)
include(hello.cmake)
message(STATUS "***** hello_str is ${hello_str}")
and hello.cmake with contents:
set(hello_str "Hello, World")
I would get an expaned CMakeLists.txt with contents (yeah, just like C/C++'s preprocess)
cmake_minimum_required(VERSION 3.20)
project(hello)
set(hello_str "Hello, World") ##!!
message(STATUS "***** hello_str is ${hello_str}")
Is that possible? And how?
OK, due to people in the comments really didn't understand, I have to make it more clear.
In the cross-compilation stage, the commonly usage is:
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=qnx-aarch64.toolchain.cmake
cmake --build .
But actually the qnx-aarch64.toolchain.cmake contains one line:
include(linux-aarch64.toolchain.cmake)
Thus, people have to have both qnx-aarch64.toolchain.cmake and linux-aarch64.toolchain.cmake, instead only one qnx-aarch64.toolchain.cmake file.
What I expected is only one qnx-aarch64.toolchain.cmake file to finish the cross-compilation.
#fabian You don't understand my question and keep telling very simple stuffs and assumes I don't know those stuffs.
Is that possible?
No. CMake 3.22 (the current at time of writing) and below do not provide this feature.
Why this statement works if mylib is a static library and does not work if it's a dynamic(shared) one:
find_library(_found mylib PATHS ${mydirs})
where mydir keeps a list of directories, containing libraries (static and shared).
I'd like to find a dynamic library in the same manner as it is done for the static libraries (in order to get it close to the executable). There would be a list of directories but for simplicity sake, first this must be made working with a trivial test case:
cmake_minimum_required(VERSION 3.21)
project(myproj)
add_executable(myproj main.cpp)
find_library(a a${CMAKE_STATIC_LIBRARY_SUFFIX} PATHS "c:/work/libs/debug")
find_library(b b${CMAKE_SHARED_LIBRARY_SUFFIX} PATHS "c:/work/libs/debug")
message("dll=" "${CMAKE_SHARED_LIBRARY_SUFFIX}")
message("dll=" "${CMAKE_STATIC_LIBRARY_SUFFIX}")
message("a=" "${a}")
message("b=" "${b}")
And, the directory structure is as this:
c:/work (CMakeLists.txt_main.cpp)
\_libs
\_debug (a.lib b.dll)
\_release (a.lib b.dll)
The output:
1>a=C:/work/libs/debug/a.lib
1>b=b-NOTFOUND
1>dll=.dll
1>dll=.lib
Anything?
I am using a third-party cmake based project as a git submodule. Lets say we have the following structure:
+ my_project/
- CMakeLists.txt
+ their_project/
- CMakeLists.txt
+ cmake/
- foobar.cmake
their_project/CMakeLists.txt does
include(cmake/foobar.cmake)
Foo(42)
and inside cmake/foobar.cmake we have
macro(Foo)
...
endmacro()
Inside my_project/CMakeLists.txt I do, say,
macro(Foo)
...my definition...
endmacro()
add_subdirectory(their_project)
The result of all this is that their_project still uses their definition of Foo because they redefine it by including cmake/foobar.cmake.
What can I do inside my CMakeLists.txt file to stop this from happening, so that their_project will use my macro?
I have a simple CMakeLists for my shader code which currently just looks like this -
target_sources( JonsEngine
PRIVATE
AmbientPixel.hlsl
AvgLuminance.hlsl
BoxBlurPixel.hlsl
Common.hlsl
Constants.h
DepthReadback.hlsl
DirectionalLightPixel.hlsl
DirectionalLightPCF2X2Pixel.hlsl
DirectionalLightPCF3X3Pixel.hlsl
DirectionalLightPCF5X5Pixel.hlsl
DirectionalLightPCF7X7Pixel.hlsl
FullscreenTriangle.hlsl
FullscreenTriangleTexcoord.hlsl
FXAA.hlsl
FXAAPixel.hlsl
GBufferPixel.hlsl
GBufferVertex.hlsl
GBufferVertexAnimated.hlsl
GBufferVertexStatic.hlsl
OptimizedPCF.hlsl
PointLightPixel.hlsl
SDSMFinalCompute.hlsl
SDSMInitialCompute.hlsl
SimpleColorPixel.hlsl
SimpleTexturePixel.hlsl
SkyboxPixel.hlsl
SkyboxVertex.hlsl
SSAOPixel.hlsl
TerrainDomain.hlsl
TerrainHull.hlsl
TerrainPixel.hlsl
TerrainPixelDebug.hlsl
Tonemapping.hlsl
TransformAnimatedVertex.hlsl
TransformStaticInstancedVertex.hlsl
TransformStaticVertex.hlsl
)
I am trying to add a bunch of compile flags to some of them using like -
set_source_files_properties( AmbientPixel.hlsl PROPERTIES COMPILE_FLAGS "/E\"ps_main\" /ps\"_5_0\"" )
However when I generate the solution via CMake it seems to ignore this when I look at the compile options for that source file. What am I doing wrong?
EDIT: CMake 3.14+
CMake treats HLSL files as source extra, as it is not a first class language in CMake. Others have had your issue as well, which prompted CMake to add the VS_SHADER_FLAGS option.
Try something like this instead:
add_executable(JonsEngine)
# Set HLSL source file properties with VS_SHADER_FLAGS.
set_source_files_properties( AmbientPixel.hlsl PROPERTIES VS_SHADER_FLAGS "/E\"ps_main\" /ps\"_5_0\"")
# Associate these source extras with the executable defined above.
target_sources(JonsEngine PRIVATE
AmbientPixel.hlsl
AvgLuminance.hlsl
#
# ... other code files here ...
#
)
There are several other shader options CMake created for the Visual Studio generator, such as VS_SHADER_TYPE and VS_SHADER_ENTRYPOINT which provide additional build information to the shader compiler.
I'm trying to call add_library for all files with certain endings.
The dir structure is:
src
| - CMakeLists.txt (1)
| - main.cpp
| - gui
| - CMakeLists.txt (2)
| - some source and header files
So currently all cc files are in the gui directory.
(1) CMakeLists.txt:
file( GLOB_RECURSE my_sources *.cc )
message(STATUS "my_sources = ${my_sources}")
add_subdirectory( gui )
add_library( my_src ${my_SOURCES} )
target_link_libraries( my_src
my_gui
)
qt5_use_modules( my_src Core Gui Widgets)
(2) CMakeLists.txt:
file( GLOB my_gui_sources *.cc)
add_library( my_gui ${my_gui_sources} )
qt5_use_modules( my_gui Core Gui Widgets)
But I keep getting this output:
You have called ADD_LIBRARY for library my_src without any source files. This typically indicates a problem with your CMakeLists.txt file
-- my_sources = /home/bla/bla/src/gui/BorderLayout.cc;...;/home/bla/bla/my/src/gui/MainWindow.cc
-- my_gui_sources = /home/bla/bla/my/src/gui/BorderLayout.cc;...;/home/bla/bla/my/src/gui/MainWindow.cc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bla/bla/my/build
I know that I currently don't need the add_library in the first CMakeLists.txt, but later I will. I changed the first GLOB to GLOB_RECURSE, so that it finds at least anything.
For some reason your
file( GLOB my_gui_sources *.cc *.h)
Is not finding any file. To debug, you can print:
message(STATUS "my_gui_sources = ${my_gui_sources}")
Probably you want to use GLOB_RECURSE, which search in sub-directories:
file( GLOB_RECURSE my_gui_sources *.cc *.h)
Note that you don't need to add headers files to the source list.
Take care that you will have to rerun cmake every time you add a file to your project (cmake won't be called automatically, thing that instead happens if you touch one of the cmake files).
Link to documentation of command "file"
Edit:
The actual problem is that in your first CMakeLists.txt file you are using inconsistent naming for your variable (note that casing is important), therefore you have to change your add_library command to:
add_library( my_src ${my_sources} )
Note (off the records :-) ): the fact that casing is important for variable names might be confusing because, on the other hand, in cmake command names are case insensitive. It's also sometimes weird to notice that the character - (minus) might be used as part of the variable name: using _ (underscore) is most of the time preferable.