CMake target_sources with different targets
With cmake we can split a project in multiple subfolders. From the top CMakeLists.txt we then call the sub CMakeLists.txt With
add_subdirectory(moduleb)
And each sub CMakeLists.txt will have an
target_sources(target SOURCES)
But what if I want to use the sub CMakeLists in multiple different top level projects? The limited understanding of CMakeLists I have seems to sugests I have to go on each sub folders and edit the CMakeList changing the target name. There must be an smarter way of dealing with this, isn't?
See also questions close to this topic
-
trying to understand C++ code, reading a file
float process(float Beta, std::ifstream & INPUT, float mass, float energy, int Juse = 1, int Jerror = 1, int intype = 1) { float crosscons = 8 * M_PI * mass * mass / energy; //Creates a constant that is used to calculate the cross section int dwarf_count = 0; int dcol = 0; string line; string item; int header = 0; string skip("#"); INPUT.seekg(0, ios::beg); while (getline(INPUT, line)) { if (contains(line, skip)) { header++; } else { break; } }
This first bit I know it's reading a file, but I have no idea where it's reading the file or where it gets it from. Inside the function I know it's trying to skip to the data because it looks like the file is filled with
#
I'm really new to C++ so i'm sorry if this really simple and stupid. Anything helps thanks! -
use "-I" to define g++ include path:why it only works when I set ".../include" instead of ".../include/boost"?
My application need boost lib. There is a boost lib in /usr/lib and boost include in /usr/include/boost, but they aren's what I need. So I compile new boost lib in my home , /home/js/anaconda/.../include/boost and /home/js/anaconda/.../lib.
To use boost in home, I use "-I/home/js/anaconda/.../include/boost" to define the include path, however, It complain error because it find boost in the "/usr/..." path. Then I try use "-I/home/js/anaconda/.../include" (the parent directory) and it works fine!
My question is 1)why it works when I specify the parent directory "/home/.../include" instead of "/home/.../include/boost"? what is the right directory I should specify when I use "-I"?
2)when I use "-I" to specify some directory, will these directory always be the one prior to the /usr directory?
-
Error LNK2038 : mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in XX.obj
I'm very new to c++ and was getting this error while trying to build Release versions of my c++ OpenGL project. After some googling I went ahead and changed the Runtime Library in the C/C++ > Code Generation menu to Multi-Threaded Debug GLL (/MDd), which then fixed the issue. I'm wondering if that's the right thing to do though.
I created a new empty project as a test, and the default Runtime Library setting in Release mode is Multi-Threaded (/MD). The default Runtime Library for Debug mode is Multi-Threaded Debug (/MDd). Despite having different Runtime Libraries, both configs build successfully, which makes me wonder if there's been a mess up in my project setup at some point.
Another detail that made me curious was the output log while trying to build in Release x64:
D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\LoggerFactory.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\ConsoleAndFileLogger.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Component.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Physics.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Rotator.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\IEntitySpawnHandler.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\SpaceScene.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\ActionManager.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\DeviceManager.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Device.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Mouse.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\MouseAxis.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\MouseButton.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\InputAction.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\InputAxis.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Scene.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\GUI.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\GLFWKeyboardKeyData.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Keyboard.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\GLFWPCInputDeviceFactory.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Random.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\IndexBuffer.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Main.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Material.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Mesh.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\OpenGLUtilities.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Square.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Shader.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\ShaderManager.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\VertexArray.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\VertexBuffer.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\SceneManager.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Singleton.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\glm.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\imgui.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\imgui_demo.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\imgui_draw.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\imgui_impl_glfw_gl3.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\x64\Release\Window.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Camera.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Color.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Debug.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\ObjectRenderer.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Entity.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\SpaceShip.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Star.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Input.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\KeyboardKey.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Math.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Renderer.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Time.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Transform.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Vector2.obj D:\Documents_Projects_FAT\Gios_OpenGL\bin\intermediates\Win32\Debug\Vector3.obj
I've highlighted two lines where the intermediate file path changes from
bin\x64\Release
tobin\intermediates\Win32\Debug
, and was wondering if this might help with the issue.Thanks in advance!
-
Setting CMake compilation options in VS Code
I recently started using VS Code and I have a question. How do I set the values of the compilation options defined in CMakeList.txt? For example if the following option is set in the CMakeList.txt: option(BUILD_WITH_TESTS "Build with tests." OFF) Then I can set this value when building using for example the CMake GUI: selecting option value
Does a similar toolkit exist in VS Code? What are the ways to set value BUILD_WITH_TESTS when building a project in VS Code?
At the moment I'm using VS Code with the plugin CMake Tools 1.5.3. But I do not find such functionality as a CMake GUI there.
-
How do you pass Menuconfig variables to your cmake file ( in ESP-IDF )
I am trying to configure to my build process for ESP-IDF to slim down the build. What I have tried : I've added custom entries to the menuconfig:
menu "Install Sensor Device Drivers" config LISD3H_CHECK bool "Include LISD3H Accel Sensor" default "n" help Install required drivers for LISD3H and check if device present config SHT30_CHECK bool "Include SHT30 Temp & Hum Sensor" default "n" help Install required drivers for SHT30 and check if device present endmenu
and tried using these to reduce unnecessary components getting compiled into the project. The config variables are correctly created and accessible within the source code. Now, I tried to control the build within the top level cmake file:
set(component_dirs "${CMAKE_CURRENT_LIST_DIR}/../components/comp1") message(STATUS ${component_dirs}) message(STATUS ${CONFIG_LISD3H_CHECK}) message(STATUS ${CONFIG_SHT30_CHECK}) if(CONFIG_LISD3H_CHECK) list(APPEND component_dirs "${CMAKE_CURRENT_LIST_DIR}/../components/comp2" ) message(STATUS ${component_dirs}) else() message(STATUS "config not equal to whategver...") endif()
However, the if statement is always false because cmake cannot see the CONFIG_XXXX variables from Kconfig (the messages are blank) Is there a way to access Kconfig varaibles inside cmake? Or a means of using menuconfig to control the build?
Basically, How do you exclude a component from the build? Should I just use C precompile directives inside the source code and ignore what gets compiled, since it will get optimised out of the final binary?
-
CMake for Swift alternative to target_compile_definitions
The project I am working on uses CMake to build and I'm a little new to CMake. I am trying to setup a unit test target in the project to test some SWIFT code. The project contains several examples of setting up unit test in ObjC but none with SWIFT which means it's up to me to figure it out. The way the testing code is set up if there is any UT specific code in the code base it is contained inside a pair of
#ifdef SOME_DEFINE #endif
. That way we can define things that are strictly for testing purposes but won't compile into the finished product.Now comes the part I'm having issues with. SWIFT doesn't have
#define
and uses global constants instead. Consequently I can't usetarget_compile_definitions
to create a define that I can use to tell the compiler not to compile a section of code. When I try to usetarget_compile_definitions
I get a compile error saying<unknown>:0: error: error opening input file 'SOME_DEFINE' (No such file or directory)
. What is a good work around for this?