Commit 010969070719fe14435f4b146ecef5e65df0098f

Silvio Traversaro 2021-04-29T09:44:52

Merge pull request #99 from xantares/wine cmake: use CROSSCOMPILING_EMULATOR

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e52b25b..160d787 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,23 +12,6 @@ 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)
@@ -44,5 +27,9 @@ if(WIN32)
 endif()
 
 if (BUILD_TESTS)
+    if (CMAKE_CROSSCOMPILING AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
+        message(WARNING "You might want to set CMAKE_CROSSCOMPILING_EMULATOR to wine path in order to run tests")
+    endif ()
+    enable_testing()
     add_subdirectory(tests)
 endif()
diff --git a/README.md b/README.md
index 9424e3c..c4ea414 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,8 @@ target_link_libraries(<target> ${CMAKE_DL_LIBS})
 ...
 ~~~
 
+When cross-compiling you might want to set CMAKE_CROSSCOMPILING_EMULATOR to the path of wine to run tests.
+
 Author
 ------
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 47fef38..cd321f2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -15,9 +15,7 @@ if(WIN32)
     add_executable(t_dlfcn test.c)
     target_link_libraries(t_dlfcn dl)
 
-    if(RUN_TESTS)
-        add_test(NAME t_dlfcn COMMAND ${WRAPPER} $<TARGET_FILE:t_dlfcn> WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn>)
-    endif()
+    add_test(NAME t_dlfcn COMMAND t_dlfcn WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn> )
 endif()
 
 add_executable(test-dladdr test-dladdr.c)
@@ -35,6 +33,4 @@ endif()
 
 install(TARGETS test-dladdr EXPORT dlfcn-win32-targets RUNTIME DESTINATION bin)
 
-if(RUN_TESTS)
-    add_test(NAME test-dladdr COMMAND ${WRAPPER} $<TARGET_FILE:test-dladdr> WORKING_DIRECTORY $<TARGET_FILE_DIR:test-dladdr>)
-endif()
+add_test(NAME test-dladdr COMMAND test-dladdr WORKING_DIRECTORY $<TARGET_FILE_DIR:test-dladdr>)
diff --git a/tools/ci-build.sh b/tools/ci-build.sh
index 196fd92..a8cb880 100755
--- a/tools/ci-build.sh
+++ b/tools/ci-build.sh
@@ -63,8 +63,7 @@ case "$ci_buildsys" in
                     -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY     \
                     -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY     \
                     -DCMAKE_SYSTEM_NAME=Windows                  \
-                    -DENABLE_WINE=ON                             \
-                    -DWINE_EXECUTABLE=/usr/bin/wine              \
+                    -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/wine              \
                     $cmake_options \
                     ..
                 ;;