diff options
author | Markus Henschel <markus.henschel@yager.de> | 2014-05-28 19:30:04 +0200 |
---|---|---|
committer | Markus Henschel <markus.henschel@yager.de> | 2014-05-28 19:30:04 +0200 |
commit | a408ad03411e2774e6f520c50a1fceb52d349b73 (patch) | |
tree | ba5214cbf2ea90c8c17effcb9bec3f2f458bbccf | |
parent | d512051754aa474bd94d8f728ce8689070a87d7c (diff) |
add test for building shared and static libraries with cmake
-rw-r--r-- | tests/cmake/target_library/CMakeLists.txt | 43 | ||||
-rw-r--r-- | tests/cmake/target_library/srcfile.cmake | 6 | ||||
-rw-r--r-- | tests/test_other.py | 13 |
3 files changed, 56 insertions, 6 deletions
diff --git a/tests/cmake/target_library/CMakeLists.txt b/tests/cmake/target_library/CMakeLists.txt new file mode 100644 index 00000000..c7023192 --- /dev/null +++ b/tests/cmake/target_library/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 2.8) + +project(test_cmake) + +option(BUILD_SHARED_LIBS "Build with shared libraries." OFF) + +if (CMAKE_BUILD_TYPE STREQUAL Debug) + SET(linkFlags "-g4") +else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled. + SET(linkFlags "-O2") +endif() + +set(MAX_SRC_FILE_INDEX 30) +SET(TEST_SRC_FILE_BASE_NAME "this_is_a_test_src_file_with_a_quite_lengthy_name_to_simulate_very_long_command_line_length_problems_on_windows_") + + +foreach(i RANGE ${MAX_SRC_FILE_INDEX}) + set (TEST_FUNCTION_NAME "FooBar_${i}") + configure_file("srcfile.cmake" "${TEST_SRC_FILE_BASE_NAME}${i}.c") + configure_file("srcfile.cmake" "${TEST_SRC_FILE_BASE_NAME}${i}.cpp") + list(APPEND TEST_SOURCES "${TEST_SRC_FILE_BASE_NAME}${i}.c" "${TEST_SRC_FILE_BASE_NAME}${i}.cpp") +endforeach() + +add_library(test_cmake ${TEST_SOURCES}) + +if (WIN32) + message(FATAL_ERROR "WIN32 should not be defined when cross-compiling!") +endif() + +if (APPLE) + message(FATAL_ERROR "APPLE should not be defined when cross-compiling!") +endif() + +if (NOT EMSCRIPTEN) + message(FATAL_ERROR "EMSCRIPTEN should be defined when cross-compiling!") +endif() + +if (NOT CMAKE_C_SIZEOF_DATA_PTR) + message(FATAL_ERROR "CMAKE_C_SIZEOF_DATA_PTR was not defined!") +endif() + +# GOTCHA: If your project has custom link flags, these must be set *before* calling any of the em_link_xxx functions! +set_target_properties(test_cmake PROPERTIES LINK_FLAGS "${linkFlags}") diff --git a/tests/cmake/target_library/srcfile.cmake b/tests/cmake/target_library/srcfile.cmake new file mode 100644 index 00000000..10e9e6f8 --- /dev/null +++ b/tests/cmake/target_library/srcfile.cmake @@ -0,0 +1,6 @@ +#include <stdio.h> + +void @TEST_FUNCTION_NAME@() +{ + printf("@TEST_FUNCTION_NAME@"); +} diff --git a/tests/test_other.py b/tests/test_other.py index 03859a4e..0b5e0d43 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -353,9 +353,10 @@ f.close() except KeyError: postbuild = None - cmake_cases = ['target_js', 'target_html'] - cmake_outputs = ['test_cmake.js', 'hello_world_gles.html'] - for i in range(0, 2): + cmake_cases = ['target_js', 'target_html', 'target_library', 'target_library'] + cmake_outputs = ['test_cmake.js', 'hello_world_gles.html', 'libtest_cmake.a', 'libtest_cmake.so'] + cmake_arguments = ['', '', '-DBUILD_SHARED_LIBS=OFF', '-DBUILD_SHARED_LIBS=ON'] + for i in range(0, len(cmake_cases)): for configuration in ['Debug', 'Release']: # CMake can be invoked in two ways, using 'emconfigure cmake', or by directly running 'cmake'. # Test both methods. @@ -373,11 +374,11 @@ f.close() if invoke_method == 'cmake': # Test invoking cmake directly. cmd = ['cmake', '-DCMAKE_TOOLCHAIN_FILE='+path_from_root('cmake', 'Platform', 'Emscripten.cmake'), - '-DCMAKE_BUILD_TYPE=' + configuration, '-G', generator, cmakelistsdir] + '-DCMAKE_BUILD_TYPE=' + configuration, cmake_arguments[i], '-G', generator, cmakelistsdir] else: # Test invoking via 'emconfigure cmake' - cmd = [emconfigure, 'cmake', '-DCMAKE_BUILD_TYPE=' + configuration, '-G', generator, cmakelistsdir] - + cmd = [emconfigure, 'cmake', '-DCMAKE_BUILD_TYPE=' + configuration, cmake_arguments[i], '-G', generator, cmakelistsdir] + ret = Popen(cmd, stdout=None if verbose_level >= 2 else PIPE, stderr=None if verbose_level >= 1 else PIPE).communicate() if len(ret) > 1 and ret[1] != None and len(ret[1].strip()) > 0: logging.error(ret[1]) # If there were any errors, print them directly to console for diagnostics. |