aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2020-11-02 13:06:55 +0100
committerRalf Habacker <ralf.habacker@freenet.de>2020-11-09 09:45:38 +0100
commit2821345eacb71222ed9acf31f193eda81daeec3f (patch)
tree27a74ed092adde7cf07aecbbcdd096a7db443cdd
parent53b1d71abe1c9d7c43eb68b91a0e94a27b948cdf (diff)
downloaddlfcn-win32-2821345eacb71222ed9acf31f193eda81daeec3f.tar.gz
dlfcn-win32-2821345eacb71222ed9acf31f193eda81daeec3f.tar.bz2
dlfcn-win32-2821345eacb71222ed9acf31f193eda81daeec3f.zip
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=<path> to the cmake command line. The cmake related macros were copied from https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/cmake/modules/Macros.cmake
-rw-r--r--CMakeLists.txt21
-rw-r--r--cmake/modules/Macros.cmake32
-rw-r--r--tests/CMakeLists.txt4
3 files changed, 55 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab20340..1c6fe4c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,9 +6,29 @@ endif ()
6 6
7project (dlfcn-win32 C) 7project (dlfcn-win32 C)
8 8
9list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
10include(Macros)
11
9option(BUILD_SHARED_LIBS "shared/static libs" ON) 12option(BUILD_SHARED_LIBS "shared/static libs" ON)
10option(BUILD_TESTS "tests?" OFF) 13option(BUILD_TESTS "tests?" OFF)
11 14
15if(WIN32 AND NOT CMAKE_HOST_WIN32 AND CMAKE_CROSSCOMPILING AND BUILD_TESTS)
16 add_auto_option(ENABLE_WINE "Enable running tests with wine" AUTO)
17 find_program(WINE_EXECUTABLE wine)
18 check_auto_option(ENABLE_WINE "wine support" WINE_EXECUTABLE "wine executable")
19 if(ENABLE_WINE AND WINE_EXECUTABLE)
20 set(WRAPPER ${WINE_EXECUTABLE})
21 set(RUN_TESTS 1)
22 message(STATUS "Support to run cross compiled tests - enabled")
23 endif()
24elseif(BUILD_TESTS)
25 set(RUN_TESTS 1)
26endif()
27
28if(RUN_TESTS)
29 enable_testing()
30endif()
31
12set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 32set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
13set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 33set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
14set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 34set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -16,6 +36,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
16add_subdirectory(src) 36add_subdirectory(src)
17 37
18if (BUILD_TESTS) 38if (BUILD_TESTS)
19 enable_testing()
20 add_subdirectory(tests) 39 add_subdirectory(tests)
21endif() 40endif()
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 @@
1#
2# provide option with three states AUTO, ON, OFF
3#
4macro(add_auto_option _name _text _default)
5 if(NOT DEFINED ${_name})
6 set(${_name} ${_default} CACHE STRING "${_text}" FORCE)
7 else()
8 set(${_name} ${_default} CACHE STRING "${_text}")
9 endif()
10 set_property(CACHE ${_name} PROPERTY STRINGS AUTO ON OFF)
11endmacro()
12
13#
14# Ensure that if a tristate ON/OFF/AUTO feature is set to ON,
15# its requirements have been met. Fail with a fatal error if not.
16#
17# _name: name of a variable ENABLE_FOO representing a tristate ON/OFF/AUTO feature
18# _text: human-readable description of the feature enabled by _name, for the
19# error message
20# _var: name of a variable representing a system property we checked for,
21# such as an executable that must exist for the feature enabled by _name to work
22# _vartext: what we checked for, for the error message
23#
24macro(check_auto_option _name _text _var _vartext)
25 set(_nameval ${${_name}})
26 set(_varval ${${_var}})
27 #message("debug: _name ${_name} ${_nameval} _var ${_var} ${_varval}")
28 if(_nameval AND NOT _nameval STREQUAL "AUTO" AND NOT _varval)
29 message(FATAL_ERROR "${_text} requested but ${_vartext} not found")
30 endif()
31endmacro()
32
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 "")
12 12
13add_executable(t_dlfcn test.c) 13add_executable(t_dlfcn test.c)
14target_link_libraries(t_dlfcn dl) 14target_link_libraries(t_dlfcn dl)
15add_test(NAME t_dlfcn COMMAND $<TARGET_FILE:t_dlfcn> WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn>) 15if(RUN_TESTS)
16 add_test(NAME t_dlfcn COMMAND ${WRAPPER} $<TARGET_FILE:t_dlfcn> WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn>)
17endif()