From 8efe38dadf4c4db2a3dab5d9ac5e0d3ebc39ad24 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 16 Jul 2016 23:04:22 +0200 Subject: [PATCH] Improve details in the build system - add target to run cross compiled Windows binaries with wine - quit tests if --help has been specified --- cmake/modules/AppTarget.cmake | 12 ++++++++++++ cmake/modules/BasicConfig.cmake | 5 +++++ cmake/modules/Doxygen.cmake | 1 + cmake/modules/LibraryTarget.cmake | 2 ++ cmake/modules/TestTarget.cmake | 12 ++++++++++++ cmake/modules/WindowsResources.cmake | 2 +- cmake/templates/Config.cmake.in | 1 + cmake/templates/config.h.in | 1 + scripts/wine.sh | 6 ++++++ tests/testutils.cpp | 4 ++++ 10 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 scripts/wine.sh diff --git a/cmake/modules/AppTarget.cmake b/cmake/modules/AppTarget.cmake index a29b3a4..4fadbb5 100644 --- a/cmake/modules/AppTarget.cmake +++ b/cmake/modules/AppTarget.cmake @@ -71,6 +71,18 @@ if(NOT TARGET install-mingw-w64-strip) ) endif() +# add target for launching application with wine ensuring the WINEPATH is set correctly so wine is able to find all required *.dll files +# requires script from c++utilities, hence the sources of c++utilities must be present +if(MINGW AND CMAKE_CROSSCOMPILING AND CPP_UTILITIES_SOURCE_DIR) + if(NOT TARGET ${META_PROJECT_NAME}_run) + if(CMAKE_FIND_ROOT_PATH) + list(APPEND RUNTIME_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/bin") + endif() + add_custom_target(${META_PROJECT_NAME}_run COMMAND "${CPP_UTILITIES_SOURCE_DIR}/scripts/wine.sh" "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}.${WINDOWS_EXT}" ${RUNTIME_LIBRARY_PATH}) + add_dependencies(${META_PROJECT_NAME}_run ${META_PROJECT_NAME}) + endif() +endif() + # find template for *.desktop files include(TemplateFinder) find_template_file("desktop" CPP_UTILITIES APP_DESKTOP_TEMPLATE_FILE) diff --git a/cmake/modules/BasicConfig.cmake b/cmake/modules/BasicConfig.cmake index 89a27c2..49180af 100644 --- a/cmake/modules/BasicConfig.cmake +++ b/cmake/modules/BasicConfig.cmake @@ -10,6 +10,9 @@ if(HAS_PARENT) set(${META_PROJECT_VARNAME}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) set(${META_PROJECT_VARNAME}_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE) set(${META_PROJECT_NAME}_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE) + if(CMAKE_FIND_ROOT_PATH AND MINGW) + set(RUNTIME_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}" ${RUNTIME_LIBRARY_PATH} PARENT_SCOPE) + endif() endif() # stringify the meta data @@ -50,6 +53,8 @@ option(FORCE_OLD_ABI "specifies whether usage of old ABI should be forced" OFF) if(FORCE_OLD_ABI) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) message(STATUS "Forcing usage of old CXX11 ABI.") +else() + message(STATUS "Using default CXX11 ABI (not forcing old CX11 ABI).") endif() # enable debug-only code when doing a debug build diff --git a/cmake/modules/Doxygen.cmake b/cmake/modules/Doxygen.cmake index cfdd2b3..f7e1747 100644 --- a/cmake/modules/Doxygen.cmake +++ b/cmake/modules/Doxygen.cmake @@ -17,6 +17,7 @@ if(DOT_BIN) else() set(HAVE_DOT "NO") endif() + if(NOT DOXYGEN_BIN) message(WARNING "Doxygen not found, unable to add target for generating API documentation.") diff --git a/cmake/modules/LibraryTarget.cmake b/cmake/modules/LibraryTarget.cmake index fa7f2a1..6ec17b0 100644 --- a/cmake/modules/LibraryTarget.cmake +++ b/cmake/modules/LibraryTarget.cmake @@ -20,6 +20,7 @@ endif() # set install destination for the CMake modules, config files and header files set(HEADER_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/include") +set(BIN_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") set(LIB_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${SELECTED_LIB_SUFFIX}") set(CMAKE_MODULE_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${META_PROJECT_NAME}/cmake/modules") set(CMAKE_CONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${META_PROJECT_NAME}/cmake") @@ -34,6 +35,7 @@ configure_package_config_file( CMAKE_MODULE_INSTALL_DESTINATION CMAKE_CONFIG_INSTALL_DESTINATION HEADER_INSTALL_DESTINATION + BIN_INSTALL_DESTINATION LIB_INSTALL_DESTINATION ) diff --git a/cmake/modules/TestTarget.cmake b/cmake/modules/TestTarget.cmake index e314a30..e4d8534 100644 --- a/cmake/modules/TestTarget.cmake +++ b/cmake/modules/TestTarget.cmake @@ -15,3 +15,15 @@ add_test(NAME ${META_PROJECT_NAME}_cppunit COMMAND ${META_PROJECT_NAME}_tests -p # add the test executable to the dependencies of the check target add_dependencies(check ${META_PROJECT_NAME}_tests) + +# add target for launching tests with wine ensuring the WINEPATH is set correctly so wine is able to find all required *.dll files +# requires script from c++utilities, hence the sources of c++utilities must be present +if(MINGW AND CMAKE_CROSSCOMPILING AND CPP_UTILITIES_SOURCE_DIR) + if(NOT TARGET ${META_PROJECT_NAME}_run_tests) + if(CMAKE_FIND_ROOT_PATH) + list(APPEND RUNTIME_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/bin") + endif() + add_custom_target(${META_PROJECT_NAME}_run_tests COMMAND "${CPP_UTILITIES_SOURCE_DIR}/scripts/wine.sh" "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}_tests.${WINDOWS_EXT}" ${RUNTIME_LIBRARY_PATH}) + add_dependencies(${META_PROJECT_NAME}_run_tests ${META_PROJECT_NAME}) + endif() +endif() diff --git a/cmake/modules/WindowsResources.cmake b/cmake/modules/WindowsResources.cmake index ddcca7f..44d8a76 100644 --- a/cmake/modules/WindowsResources.cmake +++ b/cmake/modules/WindowsResources.cmake @@ -33,7 +33,7 @@ if(MINGW) "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc" ) # set windres as resource compiler - set(RES_FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc") + list(APPEND RES_FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc") set(CMAKE_RC_COMPILER_INIT windres) set(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") enable_language(RC) diff --git a/cmake/templates/Config.cmake.in b/cmake/templates/Config.cmake.in index c03d2f1..900f92d 100644 --- a/cmake/templates/Config.cmake.in +++ b/cmake/templates/Config.cmake.in @@ -2,6 +2,7 @@ set(@META_PROJECT_VARNAME@_LIBS "@META_PROJECT_NAME@") set(@META_PROJECT_VARNAME@_INCLUDE_DIRS "@PACKAGE_HEADER_INSTALL_DESTINATION@") +set(@META_PROJECT_VARNAME@_BIN_DIR "@PACKAGE_BIN_INSTALL_DESTINATION@") set(@META_PROJECT_VARNAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DESTINATION@") set(@META_PROJECT_VARNAME@_MODULE_DIRS "@PACKAGE_CMAKE_MODULE_INSTALL_DESTINATION@") set(@META_PROJECT_VARNAME@_CONFIG_DIRS "@PACKAGE_CMAKE_CONFIG_INSTALL_DESTINATION@") diff --git a/cmake/templates/config.h.in b/cmake/templates/config.h.in index 82ef75d..d4f6695 100644 --- a/cmake/templates/config.h.in +++ b/cmake/templates/config.h.in @@ -6,4 +6,5 @@ # define APP_AUTHOR @META_APP_AUTHOR_STR@ # define APP_URL @META_APP_URL_STR@ # define APP_DESCRIPTION @META_APP_DESCRIPTION_STR@ +# define APP_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #endif // APP_METADATA_AVAIL diff --git a/scripts/wine.sh b/scripts/wine.sh new file mode 100755 index 0000000..95f9c28 --- /dev/null +++ b/scripts/wine.sh @@ -0,0 +1,6 @@ +#!/bin/bash +for arg in "${@:2}"; do + WINEPATH="${arg};${WINEPATH}" +done +export WINEPATH; +wine "${@:1:1}" diff --git a/tests/testutils.cpp b/tests/testutils.cpp index 34c4c43..adcfc50 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -69,6 +69,10 @@ TestApplication::TestApplication(int argc, char **argv) : // parse arguments try { m_parser.parseArgs(argc, argv); + if(m_helpArg.isPresent()) { + m_valid = false; + exit(0); + } cerr << "Directories used to search for testfiles:" << endl; if(m_testFilesPathArg.isPresent()) { if(*m_testFilesPathArg.values().front()) {