summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-02-12 08:14:10 (GMT)
committerAndreas Schneider <asn@cryptomilk.org>2015-02-12 15:59:22 (GMT)
commit8798b43ea565927b3dbdc387cd0649dc422cdcd8 (patch)
treee5e79218939830df73cb520d742ffa04c4fe247f
parentc180601e564bcbf2ec2d143963ca22a3effdb9fe (diff)
downloadcmocka-8798b43ea565927b3dbdc387cd0649dc422cdcd8.zip
cmocka-8798b43ea565927b3dbdc387cd0649dc422cdcd8.tar.gz
cmocka-8798b43ea565927b3dbdc387cd0649dc422cdcd8.tar.bz2
cmake: Fix executing test examples on Windows.
The executable need the path to dll set so they can be run successfully. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--example/CMakeLists.txt43
-rw-r--r--example/chef_wrap/CMakeLists.txt3
-rw-r--r--src/CMakeLists.txt40
3 files changed, 74 insertions, 12 deletions
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 9e0889e..c343244 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -13,17 +13,37 @@ set_source_files_properties(
PROPERTIES
COMPILE_DEFINITIONS UNIT_TESTING=1)
+if (WIN32)
+ set(DLL_PATH_ENV "${CMOCKA_DLL_PATH};$ENV{PATH}")
+
+ #
+ # IMPORTANT NOTE: The set_tests_properties(), below, internally
+ # stores its name/value pairs with a semicolon delimiter.
+ # because of this we must protect the semicolons in the path
+ #
+ string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}")
+endif (WIN32)
+
+
### The most simple test
add_executable(simple_test simple_test.c)
target_link_libraries(simple_test ${CMOCKA_SHARED_LIBRARY})
add_test(simple_test ${CMAKE_CURRENT_BINARY_DIR}/simple_test)
+if (WIN32)
+ set_tests_properties(simple_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Calulator test
add_executable(calculator_test calculator.c calculator_test.c)
target_link_libraries(calculator_test ${CMOCKA_SHARED_LIBRARY})
add_test(calculator_test ${CMAKE_CURRENT_BINARY_DIR}/calculator_test)
+if (WIN32)
+ set_tests_properties(calculator_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Allocate module test
add_executable(allocate_module_test allocate_module.c allocate_module_test.c)
target_link_libraries(allocate_module_test ${CMOCKA_SHARED_LIBRARY})
@@ -35,7 +55,11 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 3 test"
)
+if (WIN32)
+ set_tests_properties(allocate_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Assert macro test
add_executable(assert_macro_test assert_macro.c assert_macro_test.c)
target_link_libraries(assert_macro_test ${CMOCKA_SHARED_LIBRARY})
@@ -46,7 +70,11 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 2 test"
)
+if (WIN32)
+ set_tests_properties(assert_macro_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Assert module test
add_executable(assert_module_test assert_module.c assert_module_test.c)
target_link_libraries(assert_module_test ${CMOCKA_SHARED_LIBRARY})
@@ -57,17 +85,29 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 2 test"
)
+if (WIN32)
+ set_tests_properties(assert_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Customer database test
add_executable(customer_database_test customer_database.c customer_database_test.c)
target_link_libraries(customer_database_test ${CMOCKA_SHARED_LIBRARY})
add_test(customer_database_test ${CMAKE_CURRENT_BINARY_DIR}/customer_database_test)
+if (WIN32)
+ set_tests_properties(customer_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Key Value Test
add_executable(key_value_test key_value.c key_value_test.c)
target_link_libraries(key_value_test ${CMOCKA_SHARED_LIBRARY})
add_test(key_value_test ${CMAKE_CURRENT_BINARY_DIR}/key_value_test)
+if (WIN32)
+ set_tests_properties(key_value_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
+### Product database test
add_executable(product_database_test product_database.c product_database_test.c)
target_link_libraries(product_database_test ${CMOCKA_SHARED_LIBRARY})
@@ -78,6 +118,9 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 2 test"
)
+if (WIN32)
+ set_tests_properties(product_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
# TODO Execute "$CMAKE_LINKER --help" and check for --wrap
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE)
diff --git a/example/chef_wrap/CMakeLists.txt b/example/chef_wrap/CMakeLists.txt
index 60d5a36..5902438 100644
--- a/example/chef_wrap/CMakeLists.txt
+++ b/example/chef_wrap/CMakeLists.txt
@@ -15,3 +15,6 @@ set_target_properties(waiter_test_wrap
PROPERTIES
LINK_FLAGS "-Wl,--wrap=chef_cook"
)
+if (WIN32)
+ set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
+endif (WIN32)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4ab084e..6aa2741 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,18 +54,20 @@ add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS})
target_link_libraries(${CMOCKA_SHARED_LIBRARY} ${CMOCKA_LINK_LIBRARIES})
-set_target_properties(
- ${CMOCKA_SHARED_LIBRARY}
- PROPERTIES
- VERSION
- ${LIBRARY_VERSION}
- SOVERSION
- ${LIBRARY_SOVERSION}
- OUTPUT_NAME
- cmocka
- DEFINE_SYMBOL
- CMOCKA_EXPORTS
-)
+if (NOT WIN32)
+ set_target_properties(
+ ${CMOCKA_SHARED_LIBRARY}
+ PROPERTIES
+ VERSION
+ ${LIBRARY_VERSION}
+ SOVERSION
+ ${LIBRARY_SOVERSION}
+ OUTPUT_NAME
+ cmocka
+ DEFINE_SYMBOL
+ CMOCKA_EXPORTS
+ )
+endif (NOT WIN32)
install(
TARGETS ${CMOCKA_SHARED_LIBRARY}
@@ -96,3 +98,17 @@ if (WITH_STATIC_LIB)
)
endif (WITH_STATIC_LIB)
+if (POLICY CMP0026)
+ cmake_policy(SET CMP0026 OLD)
+endif()
+
+#
+# In order to run tests we will need to set the approriate environment
+# variable so that the test program can locate its dependent DLL's. First
+# we want to know what directory our dependent DLL was installed into:
+#
+get_target_property(_cmocka_dir cmocka_shared LOCATION_${CMOCKA_BUILD_TYPE})
+get_filename_component(_cmocka_path "${_cmocka_dir}" PATH)
+file(TO_NATIVE_PATH "${_cmocka_path}" _cmocka_path_native)
+
+set(CMOCKA_DLL_PATH "${_cmocka_path_native}" PARENT_SCOPE)