aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml9
-rw-r--r--CMakeLists.txt32
-rw-r--r--cmake/modules/Macros.cmake32
-rw-r--r--tests/CMakeLists.txt9
-rwxr-xr-xtools/ci-build.sh49
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
14env:
15 - ci_buildsys=cmake
16 - ci_buildsys=Makefile
12 17
13script: 18script:
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
7project (dlfcn-win32 C) 7project (dlfcn-win32 C)
8 8
9list(APPEND CMAKE_MODULE_PATH "${PROJECT_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
32set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
33set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
34set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
35
36if (MSVC)
37 add_compile_options(/W4)
38else()
39 add_compile_options(-Wall)
40endif()
41
12add_subdirectory(src) 42add_subdirectory(src)
13 43
14if (BUILD_TESTS) 44if (BUILD_TESTS)
15 add_subdirectory(tests) 45 add_subdirectory(tests)
16endif() 46endif()
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 64f85f7..5fc6c44 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,12 +1,17 @@
1enable_testing()
2include_directories(../src) 1include_directories(../src)
2
3add_library(testdll SHARED testdll.c) 3add_library(testdll SHARED testdll.c)
4set_target_properties(testdll PROPERTIES PREFIX "") 4set_target_properties(testdll PROPERTIES PREFIX "")
5
5add_library(testdll2 SHARED testdll2.c) 6add_library(testdll2 SHARED testdll2.c)
6set_target_properties(testdll2 PROPERTIES PREFIX "") 7set_target_properties(testdll2 PROPERTIES PREFIX "")
7target_link_libraries(testdll2 dl) 8target_link_libraries(testdll2 dl)
9
8add_library(testdll3 SHARED testdll3.c) 10add_library(testdll3 SHARED testdll3.c)
9set_target_properties(testdll3 PROPERTIES PREFIX "") 11set_target_properties(testdll3 PROPERTIES PREFIX "")
12
10add_executable(t_dlfcn test.c) 13add_executable(t_dlfcn test.c)
11target_link_libraries(t_dlfcn dl) 14target_link_libraries(t_dlfcn dl)
12add_test (NAME t_dlfcn COMMAND 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()
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
3set -euo pipefail
4set -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
14install_prefix=$(${ci_target}-gcc --print-sysroot)/${ci_target}
15
16case "$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 ;;
47esac
48
49# vim:set sw=4 sts=4 et: