diff options
-rw-r--r-- | .travis.yml | 9 | ||||
-rw-r--r-- | CMakeLists.txt | 32 | ||||
-rw-r--r-- | cmake/modules/Macros.cmake | 32 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 9 | ||||
-rwxr-xr-x | tools/ci-build.sh | 49 |
5 files changed, 125 insertions, 6 deletions
diff --git a/.travis.yml b/.travis.yml index 3205fa9..4df8ce7 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -9,8 +9,11 @@ addons: | |||
9 | packages: | 9 | packages: |
10 | - gcc-mingw-w64 | 10 | - gcc-mingw-w64 |
11 | - wine | 11 | - wine |
12 | - cmake | ||
13 | |||
14 | env: | ||
15 | - ci_buildsys=cmake | ||
16 | - ci_buildsys=Makefile | ||
12 | 17 | ||
13 | script: | 18 | script: |
14 | - ./configure --enable-shared --enable-static --enable-wine --cross-prefix=${CC%-*}- | 19 | - ci_target=${CC%-*} ./tools/ci-build.sh |
15 | - make | ||
16 | - make test | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d3fc4..2202c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -6,11 +6,41 @@ endif () | |||
6 | 6 | ||
7 | project (dlfcn-win32 C) | 7 | project (dlfcn-win32 C) |
8 | 8 | ||
9 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") | ||
10 | include(Macros) | ||
11 | |||
9 | option(BUILD_SHARED_LIBS "shared/static libs" ON) | 12 | option(BUILD_SHARED_LIBS "shared/static libs" ON) |
10 | option(BUILD_TESTS "tests?" OFF) | 13 | option(BUILD_TESTS "tests?" OFF) |
11 | 14 | ||
15 | if(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() | ||
24 | elseif(BUILD_TESTS) | ||
25 | set(RUN_TESTS 1) | ||
26 | endif() | ||
27 | |||
28 | if(RUN_TESTS) | ||
29 | enable_testing() | ||
30 | endif() | ||
31 | |||
32 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
33 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
34 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
35 | |||
36 | if (MSVC) | ||
37 | add_compile_options(/W4) | ||
38 | else() | ||
39 | add_compile_options(-Wall) | ||
40 | endif() | ||
41 | |||
12 | add_subdirectory(src) | 42 | add_subdirectory(src) |
13 | 43 | ||
14 | if (BUILD_TESTS) | 44 | if (BUILD_TESTS) |
15 | add_subdirectory(tests) | 45 | add_subdirectory(tests) |
16 | endif() | 46 | 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 @@ | |||
1 | # | ||
2 | # provide option with three states AUTO, ON, OFF | ||
3 | # | ||
4 | macro(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) | ||
11 | endmacro() | ||
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 | # | ||
24 | macro(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() | ||
31 | endmacro() | ||
32 | |||
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 64f85f7..5fc6c44 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -1,12 +1,17 @@ | |||
1 | enable_testing() | ||
2 | include_directories(../src) | 1 | include_directories(../src) |
2 | |||
3 | add_library(testdll SHARED testdll.c) | 3 | add_library(testdll SHARED testdll.c) |
4 | set_target_properties(testdll PROPERTIES PREFIX "") | 4 | set_target_properties(testdll PROPERTIES PREFIX "") |
5 | |||
5 | add_library(testdll2 SHARED testdll2.c) | 6 | add_library(testdll2 SHARED testdll2.c) |
6 | set_target_properties(testdll2 PROPERTIES PREFIX "") | 7 | set_target_properties(testdll2 PROPERTIES PREFIX "") |
7 | target_link_libraries(testdll2 dl) | 8 | target_link_libraries(testdll2 dl) |
9 | |||
8 | add_library(testdll3 SHARED testdll3.c) | 10 | add_library(testdll3 SHARED testdll3.c) |
9 | set_target_properties(testdll3 PROPERTIES PREFIX "") | 11 | set_target_properties(testdll3 PROPERTIES PREFIX "") |
12 | |||
10 | add_executable(t_dlfcn test.c) | 13 | add_executable(t_dlfcn test.c) |
11 | target_link_libraries(t_dlfcn dl) | 14 | target_link_libraries(t_dlfcn dl) |
12 | add_test (NAME t_dlfcn COMMAND t_dlfcn) | 15 | if(RUN_TESTS) |
16 | add_test(NAME t_dlfcn COMMAND ${WRAPPER} $<TARGET_FILE:t_dlfcn> WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn>) | ||
17 | endif() | ||
diff --git a/tools/ci-build.sh b/tools/ci-build.sh new file mode 100755 index 0000000..a7d79b1 --- /dev/null +++ b/tools/ci-build.sh | |||
@@ -0,0 +1,49 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -euo pipefail | ||
4 | set -x | ||
5 | |||
6 | # ci_buildsys: | ||
7 | # Build system under test: Makefile or cmake | ||
8 | : "${ci_buildsys:=cmake}" | ||
9 | |||
10 | # ci_target: | ||
11 | # target to build for | ||
12 | : "${ci_target:=${CROSS_COMPILE%-}}" | ||
13 | |||
14 | install_prefix=$(${ci_target}-gcc --print-sysroot)/${ci_target} | ||
15 | |||
16 | case "$ci_buildsys" in | ||
17 | (Makefile) | ||
18 | ./configure --enable-shared --enable-static --enable-wine --cross-prefix=${ci_target}- | ||
19 | make | ||
20 | make test | ||
21 | ;; | ||
22 | |||
23 | (cmake) | ||
24 | cmake --version | ||
25 | rm -rf build | ||
26 | mkdir build | ||
27 | cd build | ||
28 | cmake \ | ||
29 | --no-warn-unused-cli \ | ||
30 | -DCMAKE_FIND_ROOT_PATH=$install_prefix \ | ||
31 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ | ||
32 | -DCMAKE_C_COMPILER=$(which ${ci_target}-gcc) \ | ||
33 | -DCMAKE_SYSTEM_PROCESSOR=${ci_target%-*-*} \ | ||
34 | -DCMAKE_CROSSCOMPILING=TRUE \ | ||
35 | -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ | ||
36 | -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ | ||
37 | -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ | ||
38 | -DCMAKE_SYSTEM_NAME=Windows \ | ||
39 | -DBUILD_TESTS=1 \ | ||
40 | -DENABLE_WINE=ON \ | ||
41 | -DWINE_EXECUTABLE=/usr/bin/wine \ | ||
42 | .. | ||
43 | make | ||
44 | ctest --output-on-failure | ||
45 | make install DESTDIR=$(pwd)/DESTDIR | ||
46 | ;; | ||
47 | esac | ||
48 | |||
49 | # vim:set sw=4 sts=4 et: | ||