Skip to content

Commit

Permalink
cmake: use CROSSCOMPILING_EMULATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
xantares committed Apr 27, 2021
1 parent 4b34d7a commit a130887
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
21 changes: 4 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
8 changes: 2 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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>)
3 changes: 1 addition & 2 deletions tools/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
..
;;
Expand Down

0 comments on commit a130887

Please sign in to comment.