I am trying to set up a simple Qt project with a unit test (written in QTest) using CMake in Windows.
I can compile the project without problem and execute the test inside Qt Creator.
The problem comes when I try to run the test using CTest (ctest -C Release --output-on-failure --test-dir C:\SRC\MyTests\Test_SO\build), as it ends in failure (exit code 0xc0000135).
How can I make the tests to pass in CTest like they do in Qt Creator?
If possible, I'd like to avoid having to copy all DLLs needed to the executable folder.
Test output
Qt Creator
CTest
Internal ctest changing into directory: C:/SRC/MyTests/Test_SO/build
Test project C:/SRC/MyTests/Test_SO/build
Start 1: tst_MyTest
1/1 Test #1: tst_MyTest .......................Exit code 0xc0000135
***Exception: 0.02 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.02 sec
The following tests FAILED:
1 - tst_MyTest (Exit code 0xc0000135
)
Things tried
Tell CTest to use Qt's installation dir as working directory: --build-run-dir C:\Qt\5.12.10\msvc2017_64\bin
Add Qt's installation directory to the Windows path in the main CMake file:
set(CUSTOM_PATH "${CMAKE_BASE_DIR}/bin;$ENV{PATH}")
cmake_path(CONVERT "${CUSTOM_PATH}" TO_NATIVE_PATH_LIST CUSTOM_PATH NORMALIZE)
string(REPLACE ";" "\\;" CUSTOM_PATH "${CUSTOM_PATH}")
set(ENV{PATH} "${CUSTOM_PATH}")
Set the ENVIRONMENT property directly at test level:
list(APPEND QT_DLL_PATH "${QT_BASE_DIR}/bin")
cmake_path(APPEND_STRING QT_DLL_PATH ";$ENV{PATH}")
cmake_path(CONVERT "${QT_DLL_PATH}" TO_NATIVE_PATH_LIST QT_DLL_PATH NORMALIZE)
string(REPLACE ";" "\\;" QT_DLL_PATH "${QT_DLL_PATH}")
add_test(NAME "${TEST_EXECUTABLE_NAME}" COMMAND "${TEST_EXECUTABLE_NAME}" WORKING_DIRECTORY "${QT_DLL_PATH}")
set_tests_properties("${TEST_EXECUTABLE_NAME}" PROPERTIES ENVIRONMENT "PATH=${QT_DLL_PATH}")
Project structure
src/
|_ CMakeLists.txt
|_ HelloWorld/
| |_CMakeLists.txt
| |_HelloWorld.h
| |_HelloWorld.cpp
|_Tests
|_CMakeLists.txt
|_MyTest/
|_MyTest.cpp
Source CMakeLists.txt
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(TestSO VERSION 1.0.0 LANGUAGES CXX DESCRIPTION "A test project with CMake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_SHARED_LIBS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Initial guess for Qt's installation path.
cmake_path(SET QT_BASE_DIR NORMALIZE "C:/Qt/5.12.10/msvc2017_64")
cmake_path(SET QT_INSTALL_DIR NORMALIZE "${QT_BASE_DIR}/lib/cmake/Qt5")
set(Qt5_DIR "${QT_INSTALL_DIR}" CACHE PATH "Path to the Qt installation folder with the CMake configuration files." FORCE)
# TEST STILL FAILS #
# set(CUSTOM_PATH "${CMAKE_BASE_DIR}/bin;$ENV{PATH}")
# cmake_path(CONVERT "${CUSTOM_PATH}" TO_NATIVE_PATH_LIST CUSTOM_PATH NORMALIZE)
# string(REPLACE ";" "\\;" CUSTOM_PATH "${CUSTOM_PATH}")
# set(ENV{PATH} "${CUSTOM_PATH}")
find_package(Qt5 REQUIRED COMPONENTS
Core
Widgets
QuickWidgets
)
set(QT_DIR "${Qt5_DIR}")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_subdirectory(HelloWorld)
enable_testing()
add_subdirectory(Tests)
HelloWorld CMakeLists.txt
set(LIB_NAME HelloWorldLib)
add_library("${LIB_NAME}" STATIC
HelloWorld.h
HelloWorld.cpp
)
target_link_libraries("${LIB_NAME}" PUBLIC Qt5::Core)
target_include_directories("${LIB_NAME}" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
HelloWorld.h
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#include <QObject>
#include <QString>
class HelloWorld final : public QObject
{
Q_OBJECT
public:
HelloWorld() = default;
QString getMsg() const;
private slots:
void myslot();
};
#endif // HELLOWORLD_H
HelloWorld.cpp
#include "HelloWorld.h"
#include <QDebug>
QString HelloWorld::getMsg() const
{
return "HELLO WORLD";
}
void HelloWorld::myslot()
{
qDebug() << "SLOT";
}
Test CMakeLists.txt
find_package(Qt5 REQUIRED COMPONENTS Test)
# TEST STILL FAILS #
#list(APPEND QT_DLL_PATH "${QT_BASE_DIR}/bin")
#cmake_path(APPEND_STRING QT_DLL_PATH ";$ENV{PATH}")
#cmake_path(CONVERT "${QT_DLL_PATH}" TO_NATIVE_PATH_LIST QT_DLL_PATH NORMALIZE)
## this is the vital line, without it CMake set_tests_properties mangles the ENVIRONMENT
#string(REPLACE ";" "\\;" QT_DLL_PATH "${QT_DLL_PATH}")
#
set(TEST_NAME "MyTest")
set(TEST_EXECUTABLE_NAME "tst_${TEST_NAME}")
add_executable("${TEST_EXECUTABLE_NAME}" "MyTest/${TEST_NAME}.cpp")
target_include_directories("${TEST_EXECUTABLE_NAME}" PRIVATE .)
target_link_libraries("${TEST_EXECUTABLE_NAME}" PRIVATE HelloWorldLib PRIVATE Qt5::Test )
add_test(NAME "${TEST_EXECUTABLE_NAME}" COMMAND "${TEST_EXECUTABLE_NAME}")
# TEST STILL FAILS #
# add_test(NAME "${TEST_EXECUTABLE_NAME}" COMMAND "${TEST_EXECUTABLE_NAME}" WORKING_DIRECTORY "${QT_DLL_PATH}")
#set_tests_properties("${TEST_EXECUTABLE_NAME}" PROPERTIES ENVIRONMENT "PATH=${QT_DLL_PATH}")
#
Test HelloWorld
#include <QtTest/QTest>
#include "HelloWorld.h"
class MyTest : public QObject
{
Q_OBJECT
private slots:
void init()
{
qDebug() << "INIT";
}
void test_MyTest()
{
QCOMPARE(true, true);
HelloWorld h;
QCOMPARE(h.getMsg(), "HELLO WORLD");
}
};
QTEST_MAIN(MyTest);
#include "MyTest.moc"
Related
Given the project structure
src
MyModule.cpp
test
TestMyModule.cpp
How does one import MyModule in TestMyModule.cpp?
Edit: apparently a environment issue is making me unable to import it
My CMakeList.txt:
cmake_minimum_required (VERSION 3.8)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET FocusApp PROPERTY CXX_STANDARD 20)
endif()
project ("App")
enable_testing()
add_executable (App "src/EntryPoint.ixx" "src/Time.ixx" )
add_executable(TestTime "src/Time.ixx" "test/TestTime.ixx" )
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(test)
endif()
add_test("testerino" TestTime.exe)
I have gotten the two libraries necessary for my cpp application.
https://github.com/rbock/sqlpp11
https://github.com/rbock/sqlpp11-connector-mysql
I have them downloaded along with libmysqlclient-dev and the date library. All of the library tests work when I create a build dir in each of the project cmake .. and make and run make tests.
I import both the libraries in the root directory of the project using import_library(), and there are no errors with cmake .. from the build dir. When I run a make the code is unable to find the includes for <sqlpp11/sqlpp11.h> even though the cmake .. runs ok. The following is my root CMakeLists.txt and my src CMakeLists.txt.
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "${PROJECT_SOURCE_DIR}/date")
find_library(sqlpp11 REQUIRED)
include_directories(${sqlpp11_INCLUDE_DIRS})
find_library(sqlpp11-connector-mysql REQUIRED)
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
and
add_executable(mysql_sample main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
Edit 1
In response to the comment the error is
Maker Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find Sqlpp11-connector-mysql (missing:
sqlpp11-connector-mysql_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
CMake/FindSqlpp11-connector-mysql.cmake:7 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:15 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/andrew/cpp_work/sql_sample_project/build/CMakeFiles/CMakeOutput.log".
See also "/home/andrew/cpp_work/sql_sample_project/build/CMakeFiles/CMakeError.log".
With CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "${PROJECT_SOURCE_DIR}/date")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
find_package(Sqlpp11 REQUIRED)
include_directories(${sqlpp11_INCLUDE_DIRS})
set(include_dir "${PROJECT_SOURCE_DIR}/include")
file(GLOB_RECURSE sqlpp_headers ${include_dir}/*.h ${SQLPP11_INCLUDE_DIR}/*.h)
include_directories(${include_dir})
find_package(Sqlpp11-connector-mysql REQUIRED)
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
file(GLOB_RECURSE sqlpp11-connector-mysql_headers ${include_dir}/*.h ${sqlpp11-connector-mysql_INCLUDE_DIR}/*.h)
include_directories(${include_dir})
add_executable(mysql_sample src/main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
and FindSqlpp11.cmake
find_path(SQLPP11_INCLUDE_DIR sqlpp11.h
${PROJECT_SOURCE_DIR}/sqlpp11
${PROJECT_SOURCE_DIR}/include/sqlpp11
)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlpp11 DEFAULT_MSG SQLPP11_INCLUDE_DIR)
mark_as_advanced(SQLPP11_INCLUDE_DIR)
and FindSqlpp11-connector-mysql.cmake
find_path(Sqlpp11-connector-mysql_INCLUDE_DIR sqlpp11-connector-mysql.h
${PROJECT_SOURCE_DIR}/sqlpp11-connector-mysql
${PROJECT_SOURCE_DIR}/include/sqlpp11-connector-mysql
)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlpp11-connector-mysql DEFAULT_MSG sqlpp11-connector-mysql_INCLUDE_DIR)
mark_as_advanced(Sqlpp11-connector-mysql_INCLUDE_DIR)
Why is there an error here and am I on the right track?
Edit 2
I managed to get the above working, my issue was that I was not installing properly. I now get the following error from this code.
main.cpp:(.text+0x124): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::con
nection_config> const&)'
main.cpp:(.text+0x12e): undefined reference to `sqlpp::mysql::connection::~connection()'
collect2: error: ld returned 1 exit status
CMakeFiles/mysql_sample.dir/build.make:94: recipe for target 'mysql_sample' failed
make[2]: *** [mysql_sample] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mysql_sample.dir/all' failed
make[1]: *** [CMakeFiles/mysql_sample.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Code:
include "TabSample.h"
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>
namespace mysql = sqlpp::mysql;
int main()
{
auto config = std::make_shared<mysql::connection_config>();
config->user = "root";
config->database = "sqlpp_mysql";
config->debug = true;
mysql::connection db(config);
TabSample tab;
for(const auto& row : db.run(sqlpp::select(all_of(tab)).from(tab).unconditionally()))
{
std::cerr << "row.alpha: " << row.alpha << ", row.beta: " << row.beta << ", row.gamma: " << row.gamma << std::endl;
};
return 0;
}
I am using gcc 4.9 and there are no errors with the make / make install, am I missing something in my CMakeLists.txt?
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "/usr/local/lib/date")
include_directories(/usr/local/lib/date)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set(SQLPP11_INCLUDE_DIR /usr/local/include)
find_package(Sqlpp11 REQUIRED)
add_executable(mysql_sample src/main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "/usr/local/lib/date")
include_directories(/usr/local/lib/date)
set(CMAKE_CXX_STANDARD 11)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set(SQLPP11_INCLUDE_DIR /usr/local/include)
find_package(Sqlpp11 REQUIRED)
add_executable(mysql_sample src/main.cpp)
include_directories(${sqlpp11_INCLUDE_DIRS})
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
target_link_libraries(mysql_sample mysqlclient)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
FindSqlpp11-connector-mysql.cmake
## -----------------------------------------------------------------------------
## Check for the library
find_library (sqlpp11-connector-mysql-mysql_LIBRARIES sqlpp11-connector-mysql-mysql
PATHS usr/local/cmake /usr/local/cmake/sqlpp11-connector-mysql-mysql /usr/local/lib /usr/lib /lib /sw/lib /usr/local/include
)
## -----------------------------------------------------------------------------
## Actions taken when all components have been found
if (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
set (HAVE_sqlpp11-connector-mysql-mysql TRUE)
else (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
if (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
if (NOT sqlpp11-connector-mysql-mysql_INCLUDES)
message (STATUS "Unable to find sqlpp11-connector-mysql-mysql header files!")
endif (NOT sqlpp11-connector-mysql-mysql_INCLUDES)
if (NOT sqlpp11-connector-mysql-mysql_LIBRARIES)
message (STATUS "Unable to find sqlpp11-connector-mysql-mysql library files!")
endif (NOT sqlpp11-connector-mysql-mysql_LIBRARIES)
endif (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
endif (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
if (HAVE_sqlpp11-connector-mysql-mysql)
if (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
message (STATUS "Found components for sqlpp11-connector-mysql-mysql")
message (STATUS "sqlpp11-connector-mysql-mysql_INCLUDES = ${sqlpp11-connector-mysql-mysql_INCLUDES}")
message (STATUS "sqlpp11-connector-mysql-mysql_LIBRARIES = ${sqlpp11-connector-mysql-mysql_LIBRARIES}")
endif (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
else (HAVE_sqlpp11-connector-mysql-mysql)
if (sqlpp11-connector-mysql-mysql_FIND_REQUIRED)
message (FATAL_ERROR "Could not find sqlpp11-connector-mysql-mysql!")
endif (sqlpp11-connector-mysql-mysql_FIND_REQUIRED)
endif (HAVE_sqlpp11-connector-mysql-mysql)
mark_as_advanced (
HAVE_sqlpp11-connector-mysql-mysql
sqlpp11-connector-mysql-mysql_LIBRARIES
sqlpp11-connector-mysql-mysql_INCLUDES
)
and the error output:
root#beaglebone:~/cpp_work/sql_sample_project/build# cmake ..
-- Attempting to find SQLPP11 FILES
-- Unable to find SQLPP11 library files!
-- Unable to find sqlpp11-connector-mysql-mysql header files!
-- Unable to find sqlpp11-connector-mysql-mysql library files!
-- Configuring done
-- Generating done
I am trying to compile the example code from the github page of docopt. I am getting a linker error though:
/tmp/test-d3ed6b.o: In function `main':
test.cpp:(.text+0xf3): undefined reference to `docopt::docopt(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, bool, std::string const&, bool)'
test.cpp:(.text+0x1c8): undefined reference to `docopt::operator<<(std::ostream&, docopt::value const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have a file test.cpp and a directory docopt with all the docopt files in it.
test.cpp:
#include <iostream>
#include "docopt/docopt.h"
static const char USAGE[] =
R"(Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored | --drifting]
naval_fate (-h | --help)
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
)";
int main(int argc, const char** argv)
{
std::map<std::string, docopt::value> args
= docopt::docopt(USAGE,
{ argv + 1, argv + argc },
true, // show help if requested
"Naval Fate 2.0"); // version string
for(auto const& arg : args) {
std::cout << arg.first << arg.second << std::endl;
}
return 0;
}
what is with that error? How can I fix that? I have tried clang-3.5 and g++
I ran into this as well.
I resolved the problem using cmake and some specific configuration in my CMakeLists.txt. The following configuration worked for me:
cmake_minimum_required (VERSION 3.5)
project(my_project)
include(ExternalProject)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(DOCOPT_ROOT ${PROJECT_SOURCE_DIR}/external/docopt)
set(DOCOPT_INCLUDE_DIRS ${DOCOPT_ROOT}/include/docopt)
set(DOCOPT_LIBRARIES ${DOCOPT_ROOT}/lib/libdocopt.a)
set(docopt_INSTALL_DIR "${DOCOPT_ROOT}")
set(docopt_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${docopt_INSTALL_DIR})
ExternalProject_Add(docopt
PREFIX ${DOCOPT_ROOT}
GIT_REPOSITORY https://github.com/docopt/docopt.cpp.git
BINARY_DIR ${DOCOPT_ROOT}
INSTALL_DIR ${DOCOPT_ROOT}
CMAKE_ARGS ${docopt_CMAKE_ARGS}
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
add_library(libdocopt STATIC IMPORTED)
set_target_properties(libdocopt PROPERTIES IMPORTED_LOCATION ${DOCOPT_LIBRARIES})
add_dependencies(libdocopt docopt)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${DOCOPT_INCLUDE_DIRS})
file(GLOB projector_src
"*.h"
"*.cpp"
)
add_executable(my_project ${my_project_src})
target_link_libraries(projector libdocopt)
Obviously, you don't need to use cmake, but instead you'll need to either put the source for docopt.cpp in with your own code or else you'll need to tell the linker where to look for it. cmake does take care of this for you, but it's one more thing to worry about.
Modified Jeremiah Peschka's answer to work out of the box independently of any other sources.
Project structure:
├── CMakeLists.txt
├── build
└── main.cpp
CMakeLists.txt
cmake_minimum_required (VERSION 3.5)
project(my_project)
include(ExternalProject)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(DOCOPT_ROOT ${PROJECT_SOURCE_DIR}/external/docopt)
set(DOCOPT_INCLUDE_DIRS ${DOCOPT_ROOT}/include/docopt)
set(DOCOPT_LIBRARIES ${DOCOPT_ROOT}/lib/libdocopt.a)
set(docopt_INSTALL_DIR "${DOCOPT_ROOT}")
set(docopt_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${docopt_INSTALL_DIR})
ExternalProject_Add(docopt
PREFIX ${DOCOPT_ROOT}
GIT_REPOSITORY https://github.com/docopt/docopt.cpp.git
BINARY_DIR ${DOCOPT_ROOT}
INSTALL_DIR ${DOCOPT_ROOT}
CMAKE_ARGS ${docopt_CMAKE_ARGS}
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
add_library(libdocopt STATIC IMPORTED)
set_target_properties(libdocopt PROPERTIES IMPORTED_LOCATION ${DOCOPT_LIBRARIES})
add_dependencies(libdocopt docopt)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${DOCOPT_INCLUDE_DIRS})
file(GLOB src
"*.h"
"*.cpp"
)
add_executable(my_project ${src})
target_link_libraries(my_project libdocopt)
I am clueless as to why the following CMakeLists.txt file complies but does not run. The error I am getting is:
[rosrun] Couldn't find executable named main_GUI1 below /home/jay/fuerte/sandbox/tum_ardrone
My CMakeLists.txt is (sorry to include it all but its the best way I think):
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
# ------------------- add dynamic reconfigure api ------------------------------------
rosbuild_find_ros_package(dynamic_reconfigure)
include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
gencfg()
# ------------------- add common files ------------------------------------
set(COMMON_SOURCE_FILES
src/UINode/tum_ardrone_gui.cpp
src/UINode/RosThread.cpp
src/UINode/PingThread.cpp
)
set(COMMON_HEADER_FILES
src/UINode/tum_ardrone_gui.h
src/UINode/RosThread.h
src/UINode/PingThread.h
)
#------------------set required libs and headers---------------------------
include_directories(
${PROJECT_SOURCE_DIR}/thirdparty/TooN/include
${PROJECT_SOURCE_DIR}/thirdparty/libcvd/include
${PROJECT_SOURCE_DIR}/thirdparty/gvars3/include
)
link_directories(
${PROJECT_SOURCE_DIR}/thirdparty/libcvd/lib
${PROJECT_SOURCE_DIR}/thirdparty/gvars3/lib
)
# ---------------------------- TEST --------------------------------------------------
# set header and source files
set(GUIA_SOURCE_FILES
${COMMON_SOURCE_FILES}
src/commands/main_GUI1.cpp
)
set(GUIA_HEADER_FILES
${COMMON_HEADER_FILES}
src/pathplanning/AStarAlgorithm.h
)
# *.ui
set(GUIA_UI_FILES
src/UINode/tum_ardrone_gui.ui
)
# *.qrc
set(GUIA_RESOURCE_FILES
)
# do QT stuff
ADD_DEFINITIONS( -Wall ) #this is fine
find_package(Qt4 REQUIRED) #this is fine
include(${QT_USE_FILE}) #this is fine
QT4_ADD_RESOURCES(GUIA_RESOURCE_FILES_CPP ${GUIA_RESOURCE_FILES}) #this is fine
QT4_WRAP_UI(GUIA_UI_FILES_HPP ${GUIA_UI_FILES}) #this is fine
QT4_WRAP_CPP(GUIA_HEADER_FILES_HPP ${GUIA_HEADER_FILES}) #error goes if i remove include_directories(${CMAKE_CURRENT_BINARY_DIR}) above
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# build!
rosbuild_add_executable(main_GUI1 ${GUIA_SOURCE_FILES} ${GUIA_RESOURCE_FILES_CPP} ${GUIA_UI_FILES_HPP} ${GUIA_HEADER_FILES_HPP})
target_link_libraries(main_GUI1 ${QT_LIBRARIES} cvd)
# ---------------------------- Messages & Services --------------------------------------------------
#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
rosbuild_gensrv()
I have the main_GUI1.cpp in src/commands so I do not know why I am getting this error. Thanks in advance!
I have a small Qt4 project which I want to build with cmake.
It has a QTcpServer and a QThread, which both include the Q_OBJECT macro.
When I'm running make I always get an RCC Parse Error after generating qrc_tcpserver.cxx.
The exact failure output is:
[ 9%] Generating qrc_tcpserver.cxx
RCC Parse Error: '/home/path/server/include/tcpserver.h' Line: 1 Column: 1 [error occurred while parsing element]
make[2]: *** [qrc_tcpserver.cxx] Fehler 1
make[1]: *** [CMakeFiles/TcpServer.dir/all] Fehler 2
make: *** [all] Fehler 2
My cmake file looks like this:
set(PROJECT_NAME TcpServer)
PROJECT(${PROJECT_NAME} )
cmake_minimum_required(VERSION 2.6)
# FOR QT4
find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
SET(CMAKE_PACKAGE_QTGUI FALSE)
SET( QT_WRAP_CPP TRUE )
set(QT_USE_QTXML TRUE)
# ENABLE WARNINGS
ADD_DEFINITIONS( -Wall )
#FOR GOOGLETEST
if(test)
find_package(GTest REQUIRED)
enable_testing()
endif()
set(QT_USE_QTNETWORK TRUE)
set(INCLUDES ${PROJECT_SOURCE_DIR}/include)
set(${PROJECT_NAME}_Qt_SRC
${INCLUDES}/tcpworkerthread.h
${INCLUDES}/tcpserver.h
)
set(${PROJECT_NAME}_Qt_UI
)
set(${PROJECT_NAME}_Qt_RES
)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
IF(QT_WRAP_CPP)
MESSAGE("Wrap cpp!")
QT4_WRAP_CPP(${PROJECT_NAME}_MOC_CPP ${${PROJECT_NAME}_Qt_SRC})
ENDIF(QT_WRAP_CPP)
QT4_WRAP_UI(${PROJECT_NAME}_UI_CPP ${${PROJECT_NAME}_Qt_UI})
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_SRC})
if(test)
include_directories(${GTEST_INCLUDE_DIRS} ${INCLUDES} ${QT_QTNETWORK_INCLUDE_DIR})
else()
include_directories(${INCLUDES} ${QT_QTNETWORK_INCLUDE_DIR})
endif()
if(test)
set(${PROJECT_NAME}_SRC_TEST
src_test/main.cpp
src_test/tcpservertest.cpp
src_test/tcpworkerthreadtest.cpp
)
set(PROJECT_TEST_NAME "${PROJECT_NAME}_test")
set(${PROJECT_NAME}_SRC
src/tcpserver.cpp
src/tcpworkerthread.cpp
)
else()
set(${PROJECT_NAME}_SRC
main.cpp
src/tcpserver.cpp
src/tcpworkerthread.cpp
)
endif()
set(${PROJECT_NAME}_LIB
${QT_LIBRARIES}
${QT_QTNETWORK_LIBRARIES}
)
if(test)
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_SRC} )
add_executable(${PROJECT_TEST_NAME} ${${PROJECT_NAME}_SRC_TEST})
target_link_libraries(${PROJECT_TEST_NAME} ${PROJECT_NAME} ${${PROJECT_NAME}_LIB} ${GTEST_BOTH_LIBRARIES} pthread)
add_test(${PROJECT_TEST_NAME} ${PROJECT_TEST_NAME})
else()
add_executable( ${PROJECT_NAME} ${${PROJECT_NAME}_SRC} ${${PROJECT_NAME}_MOC_CPP} ${${PROJECT_NAME}_UI_CPP} ${${PROJECT_NAME}_RES_H})
target_link_libraries( ${PROJECT_NAME} ${${PROJECT_NAME}_LIB} )
endif()
I execute it without test variable, so this is set to false(I use it for generating gtest, which is not so important for me, just for playing around).
Any idea where my failure is?
I'm not very familar with CMake, but it seems you're feeding a wrong list of files to QT4_ADD_RESOURCES.
The line
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_SRC})
should probably be
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_RES})