I'm trying to convert my previous qmake approach to cmake. I have a static lib called shared that links with different applications as a common ground. Each application has it's own static lib called common to link with the different targets of the same application (standalone, plugin-format-1, plugin-format-2, etc).
shared/
├── CMakeLists.txt
├── shared.cmake
│ .
project/
├── CMakeLists.txt
├── common/
├── common/CMakeLists.txt
│ common/common.cmake
│ .
When I'm developing and debbuging I want to avoid the hassle of compiling each lib individually so in debug mode I would usually include shared.pri and common.pri and when compiling the application, everything would compile smoothly, all toghether. I'm trying to replicate this include pattern using .cmake files.
#project.pro
include(../shared/shared.pri)
include(common/common.pri)
When I want to make a final and release version of the application I have a build script that compile the shared static lib, the common static lib and then links the different targets with this libs.
I have already created the CMakeLists.txt for the shared and common static libs. My problem now is how to replicate the pattern described above with cmake because when including the shared.cmake and common.cmake in the application CMakeLists.txt, the paths are not compatible. It seems that when you include(xxx.cmake), the path will always be relative to the parent CMakeLists.txt.
What would be the right way of achieving this with CMake? Is this even possible?
Use add_subdirectory() instead of include. For shared, which is "out-of-tree", you'll also need to specify the binary directory (the place to put the generated and compiled files).
add_subdirectory(../shared shared)
add_subdirectory(common)
Any targets created in those subprojects will now be available for you to link with target_link_libraries in your main project.
When you build your separate versions, consider using export() and/or install(EXPORT) to produce cmake files that you can include from your application projects instead of using add_subdirectory(), so that can be the only change you need to make.
Related
I have a project and I need to prepare a CMakeLists.txt file for it.
I also have tests which I need to get an executables for after building the project.
Tests are located in a separate backEndTest folder with their own CMakeLists.txt file.
In order to achieve that I decided to use qtwindeploy tool for that. However, when I compile everything and try to run backEndText.exe file I have errors related to missing dlls.
That's what my main CMakeLists.txt file looks like:
add_subdirectory(backEndTest)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Test)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)
set(QtBinDir "C:/Qt/6.2.3/mingw_64/bin")
set(winDeploy "${QtBinDir}/windeployqt.exe")
set(backEndTest ${CMAKE_BINARY_DIR}/backEndTest/backEndTest.exe)
set(testBackEnd TRUE)
if (testBackEnd)
execute_process(COMMAND ${winDeploy} ${backEndTest} --compiler-runtime )
endif()
Do you have any idea why dlls are not getting linked?
I woud like to make a Robot Framework project with multiple (levels of) test suits and test cases.
Is it possible to define a list of settings, specifically importing of libraries, resources and global variable (.py files), only once in one place?
As far as I'm aware this is not possible. You have to import libraries, resources and variable files explicitily in each .robot test case file that uses them. The init file in a directory can only be used for other settings, not imports.
But I would like to keep things DRY and import resourse that I use everywhere only once and in one place.
Is this not possible, or am I missing something?
Note: I'm still a RF newbie.
Thanks!
It's easily doable, and quite a common pattern - have a resource file, that has all the common keywords, variables, imports of other robot or py files, etc, and in every test suite - import it.
Say your project's directory structure is like this:
root_folder/
├── resources/
│ ├── common_resource.robot
│ ├── helpers.robot
│ ├── specific_page.robot
└── suites/
├── login_page.robot
└── specific_page.robot
The file resources/common_resource.robot has all those common elements - say, imports helpers.robot as a resource.
Every suite file imports the common file; e.g. both login_page.robot and specific_page.robot start-off with (path-relative) imports:
*** Settings ***
# other imports, documentation, etc
Resource ../resources/common_resource.robot
On top of that, each suite imports any other specific keyword files - like resources/specific_page.robot.
It's a convention, that once established ("every suite must import common_resource.robot") is easy to follow.
If there is a new keyword, variable or library that has to be used in all - or most - suites, just add it to the common file, and it will be instantly accessible.
TL;DR: Is there a way to build a target from a .pro file in a different project without using TEMPLATE = subdirs?
Long version:
I have a complex project (mycomplexproject) with lots of subirs and *.pro files. One module (moduleA) depends on a DLL built in a different project outside of this project (anotherproject). Because reasons I cannot create a *.pro file with a subdirs template in somerootdir.
Is there a way to add a dependency in moduleA.pro so anotherproject is built whenever moduleA is built and anotherproject.dll does not exist without having to create a *.pro file in somerootdir?
somerootdir/
anotherproject/ // must be independent of mycomplexproject
anotherproject.pro
lib/
anotherproject.dll // the result of building anotherproject
[...]
mycomplexproject/
core/
core.pro
modules/
moduleA/
moduleA.pro // depends on anotherproject.dll built from anotherproject.pro
moduleB/
moduleB.pro
modules.pro // uses subdir template
mycomplexproject.pro // uses subdir template
P.S.: moduleA is only built under certain circumstances, and building anotherproject is only necessary if moduleAis built.
I have a project with some folders which happen to contain source files with the same names.
My source tree looks like this:
project.pro
foo/
conflict.h
conflict.cpp
bar/
conflict.h
conflict.cpp
some.h
other.h
files.h
main.cpp
Per default, qmake generates a Makefile which will produce a build tree like this:
conflict.o
main.o
target
Where conflict.o is the object file resulting for both foo/conflict.cpp and foo/conflict.h.
I can't to change their names because they are generated using an external tool and forcing different file names would imply to change their contents, so this is not an option.
I also don't want to use qmake SUBDIRS template because this would imply that (1) every subdir is built separately as a library and thus very much complicate the overall build process (in my eyes at least) and (2) in the top level directory I can't have any source files. Or am I wrong?
Can't I just tell qmake to write the object files into separate directories within the build directory? So my build tree will look like this:
foo/
conflict.o
bar/
conflict.o
main.o
target
Or are there any other solutions neither requiring to rename the source files nor introducing something complicated like static libraries? I just can't believe that Qt didn't solve this (in my eyes simple) problem for years. (I already hat this problem 4 years ago but could rename the files in that project, while here I can't.)
If it's important: I use Qt 4.8 on both Ubuntu with G++ and Windows with mingw32.
Are you tied to qmake? If not, an alternative could be to use cmake. I just verified your usecase with a simple CMakeLists.txt like
cmake_minimum_required (VERSION 2.6)
project (conflict)
add_executable(conflict foo/conflict.cpp bar/conflict.cpp main.cpp)
which even included a source file in the top level directory (main.cpp). This properly builds the executable - the object files are created in sub directories like
./CMakeFiles/conflict.dir/main.cpp.o
./CMakeFiles/conflict.dir/bar/conflict.cpp.o
./CMakeFiles/conflict.dir/foo/conflict.cpp.o
cmake also includes support for Qt4, to automatically pull in the required include paths and libraries. It might require some effort to migrate from qmake to cmake, but given the requirements you have I would give it a try.
In the manifest file for an eclipse plugin its possible to add jar files and
folders to the classpath (on the Runtime tab).
In the root of my plugin I have a folder lib containing a-1.0.1.jar, b-1.0.0-SNAPSHOT.jar. But only when I select each jar separately:
Bundle-ClassPath: .,
lib/a-1.0.1.jar,
lib/b-1.0.0-SNAPSHOT.jar
...can they be used inside my project. Why is it not possible to add them to the classpath by adding the common root folder only:
Bundle-ClassPath: .,
lib/
?
No, you can't. Eclipse is based on OSGi, which is the platform providing MANIFEST.MF support to build plugins.
When you set values under Bundle-ClassPath, OSGi search into each one to find class files. So you can put folders containing Java packages and class files. When you put a jar file, it is uncompressed in memory and viewed by OSGi as a regular folder, still searching for class files.
Unfortunately, there is no way to load all jar from a folder. No wildcard mechanism or something like that is allowed here.