From 11c80b8e04feaa7b72cdbada92d5417dce7146dd Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 2 Nov 2020 12:37:36 +0100 Subject: cmake: place all generated binaries into one place This is required for running test applications, because by default cmake places binaries into the associated subdir. --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 64f85f7..25e9eea 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,4 +9,4 @@ add_library(testdll3 SHARED testdll3.c) set_target_properties(testdll3 PROPERTIES PREFIX "") add_executable(t_dlfcn test.c) target_link_libraries(t_dlfcn dl) -add_test (NAME t_dlfcn COMMAND t_dlfcn) +add_test(NAME t_dlfcn COMMAND $ WORKING_DIRECTORY $) -- cgit v1.2.3-55-g6feb From 3292a13718d18e7dd1b32ececc73b534398872dd Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 2 Nov 2020 12:50:41 +0100 Subject: cmake: Let make target 'test' be accessable from topmost build directory The cmake command enable_testing() must be placed in the topmost CMakeLists.txt so that the make target 'test' is available in the topmost build directory. --- CMakeLists.txt | 3 ++- tests/CMakeLists.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/CMakeLists.txt b/CMakeLists.txt index 321cfd1..ab20340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,5 +16,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) add_subdirectory(src) if (BUILD_TESTS) - add_subdirectory(tests) + enable_testing() + add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 25e9eea..be1c359 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,3 @@ -enable_testing() include_directories(../src) add_library(testdll SHARED testdll.c) set_target_properties(testdll PROPERTIES PREFIX "") -- cgit v1.2.3-55-g6feb From 53b1d71abe1c9d7c43eb68b91a0e94a27b948cdf Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 3 Nov 2020 10:45:36 +0100 Subject: cmake: separate targets in tests subdir for reasier reading --- tests/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index be1c359..35b6931 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,11 +1,15 @@ include_directories(../src) + add_library(testdll SHARED testdll.c) set_target_properties(testdll PROPERTIES PREFIX "") + add_library(testdll2 SHARED testdll2.c) set_target_properties(testdll2 PROPERTIES PREFIX "") target_link_libraries(testdll2 dl) + add_library(testdll3 SHARED testdll3.c) set_target_properties(testdll3 PROPERTIES PREFIX "") + add_executable(t_dlfcn test.c) target_link_libraries(t_dlfcn dl) add_test(NAME t_dlfcn COMMAND $ WORKING_DIRECTORY $) -- cgit v1.2.3-55-g6feb From 2821345eacb71222ed9acf31f193eda81daeec3f Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 2 Nov 2020 13:06:55 +0100 Subject: cmake: add option ENABLE_WINE to enable support for running cross compiled tests with wine For details about the ENABLE_WINE option, which support three modes AUTO|ON|OFF see the documentation of cmake macro check_auto_option(). A custom path for the wine executable can be specified by adding -DWINE_EXECUTABLE= to the cmake command line. The cmake related macros were copied from https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/cmake/modules/Macros.cmake --- CMakeLists.txt | 21 ++++++++++++++++++++- cmake/modules/Macros.cmake | 32 ++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 4 +++- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/Macros.cmake (limited to 'tests') diff --git a/CMakeLists.txt b/CMakeLists.txt index ab20340..1c6fe4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,29 @@ endif () project (dlfcn-win32 C) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") +include(Macros) + option(BUILD_SHARED_LIBS "shared/static libs" ON) option(BUILD_TESTS "tests?" OFF) +if(WIN32 AND NOT CMAKE_HOST_WIN32 AND CMAKE_CROSSCOMPILING AND BUILD_TESTS) + add_auto_option(ENABLE_WINE "Enable running tests with wine" AUTO) + find_program(WINE_EXECUTABLE wine) + check_auto_option(ENABLE_WINE "wine support" WINE_EXECUTABLE "wine executable") + if(ENABLE_WINE AND WINE_EXECUTABLE) + set(WRAPPER ${WINE_EXECUTABLE}) + set(RUN_TESTS 1) + message(STATUS "Support to run cross compiled tests - enabled") + endif() +elseif(BUILD_TESTS) + set(RUN_TESTS 1) +endif() + +if(RUN_TESTS) + enable_testing() +endif() + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -16,6 +36,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) add_subdirectory(src) if (BUILD_TESTS) - enable_testing() add_subdirectory(tests) endif() diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake new file mode 100644 index 0000000..fa0f1fc --- /dev/null +++ b/cmake/modules/Macros.cmake @@ -0,0 +1,32 @@ +# +# provide option with three states AUTO, ON, OFF +# +macro(add_auto_option _name _text _default) + if(NOT DEFINED ${_name}) + set(${_name} ${_default} CACHE STRING "${_text}" FORCE) + else() + set(${_name} ${_default} CACHE STRING "${_text}") + endif() + set_property(CACHE ${_name} PROPERTY STRINGS AUTO ON OFF) +endmacro() + +# +# Ensure that if a tristate ON/OFF/AUTO feature is set to ON, +# its requirements have been met. Fail with a fatal error if not. +# +# _name: name of a variable ENABLE_FOO representing a tristate ON/OFF/AUTO feature +# _text: human-readable description of the feature enabled by _name, for the +# error message +# _var: name of a variable representing a system property we checked for, +# such as an executable that must exist for the feature enabled by _name to work +# _vartext: what we checked for, for the error message +# +macro(check_auto_option _name _text _var _vartext) + set(_nameval ${${_name}}) + set(_varval ${${_var}}) + #message("debug: _name ${_name} ${_nameval} _var ${_var} ${_varval}") + if(_nameval AND NOT _nameval STREQUAL "AUTO" AND NOT _varval) + message(FATAL_ERROR "${_text} requested but ${_vartext} not found") + endif() +endmacro() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 35b6931..5fc6c44 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,4 +12,6 @@ set_target_properties(testdll3 PROPERTIES PREFIX "") add_executable(t_dlfcn test.c) target_link_libraries(t_dlfcn dl) -add_test(NAME t_dlfcn COMMAND $ WORKING_DIRECTORY $) +if(RUN_TESTS) + add_test(NAME t_dlfcn COMMAND ${WRAPPER} $ WORKING_DIRECTORY $) +endif() -- cgit v1.2.3-55-g6feb