From 7ac7b437b8bfc344e0d7e451d419596ea809d439 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 26 May 2011 15:16:58 -0600 Subject: BundleUtilities: Work w/ non .app exes on Mac (#12034) Also add a test of BundleUtilities including an exe, some shared libs, a plugin, and a framework-style lib. This test presently runs (and this functionality works) on Linux, Mac and Windows. For now, the framework-style lib is built as a plain old shared lib because there is another yet-unresolved issue with local frameworks without rpaths on the Mac. --- Modules/BundleUtilities.cmake | 51 +++++++++++----------- Modules/GetPrerequisites.cmake | 4 +- Tests/BundleUtilities/CMakeLists.txt | 70 +++++++++++++++++++++++++++++++ Tests/BundleUtilities/bundleutils.cmake | 44 +++++++++++++++++++ Tests/BundleUtilities/framework.cpp | 8 ++++ Tests/BundleUtilities/framework.h | 17 ++++++++ Tests/BundleUtilities/module.cpp | 10 +++++ Tests/BundleUtilities/module.h | 7 ++++ Tests/BundleUtilities/shared.cpp | 8 ++++ Tests/BundleUtilities/shared.h | 17 ++++++++ Tests/BundleUtilities/shared2.cpp | 8 ++++ Tests/BundleUtilities/shared2.h | 17 ++++++++ Tests/BundleUtilities/testbundleutils.cpp | 23 ++++++++++ Tests/CMakeLists.txt | 19 +++++++++ 14 files changed, 275 insertions(+), 28 deletions(-) create mode 100644 Tests/BundleUtilities/CMakeLists.txt create mode 100644 Tests/BundleUtilities/bundleutils.cmake create mode 100644 Tests/BundleUtilities/framework.cpp create mode 100644 Tests/BundleUtilities/framework.h create mode 100644 Tests/BundleUtilities/module.cpp create mode 100644 Tests/BundleUtilities/module.h create mode 100644 Tests/BundleUtilities/shared.cpp create mode 100644 Tests/BundleUtilities/shared.h create mode 100644 Tests/BundleUtilities/shared2.cpp create mode 100644 Tests/BundleUtilities/shared2.h create mode 100644 Tests/BundleUtilities/testbundleutils.cpp diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index 44f2c20..40084b4 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -53,9 +53,8 @@ # # GET_DOTAPP_DIR( ) # Returns the nearest parent dir whose name ends with ".app" given the full -# path to an executable. If there is no such parent dir, then return a dir at -# the same level as the executable, named with the executable's base name and -# ending with ".app" +# path to an executable. If there is no such parent dir, then simply return +# the dir containing the executable. # # The returned directory may or may not exist. # @@ -227,35 +226,35 @@ endfunction(get_bundle_main_executable) function(get_dotapp_dir exe dotapp_dir_var) set(s "${exe}") - set(has_dotapp_parent 0) if(s MATCHES "^.*/.*\\.app/.*$") - set(has_dotapp_parent 1) - endif(s MATCHES "^.*/.*\\.app/.*$") - - set(done 0) - while(NOT ${done}) - get_filename_component(snamewe "${s}" NAME_WE) - get_filename_component(sname "${s}" NAME) - get_filename_component(sdir "${s}" PATH) - if(has_dotapp_parent) - # If there is a ".app" parent directory, - # ascend until we hit it: - # (typical of a Mac bundle executable) - # + # If there is a ".app" parent directory, + # ascend until we hit it: + # (typical of a Mac bundle executable) + # + set(done 0) + while(NOT ${done}) + get_filename_component(snamewe "${s}" NAME_WE) + get_filename_component(sname "${s}" NAME) + get_filename_component(sdir "${s}" PATH) set(s "${sdir}") if(sname MATCHES "\\.app$") set(done 1) set(dotapp_dir "${sdir}/${sname}") endif(sname MATCHES "\\.app$") - else(has_dotapp_parent) - # Otherwise use a directory named the same - # as the exe, but with a ".app" extension: - # (typical of a non-bundle executable on Mac, Windows or Linux) - # - set(done 1) - set(dotapp_dir "${sdir}/${snamewe}.app") - endif(has_dotapp_parent) - endwhile(NOT ${done}) + endwhile(NOT ${done}) + else(s MATCHES "^.*/.*\\.app/.*$") + # Otherwise use a directory containing the exe + # (typical of a non-bundle executable on Mac, Windows or Linux) + # + is_file_executable("${s}" is_executable) + if(is_executable) + get_filename_component(sdir "${s}" PATH) + set(dotapp_dir "${sdir}") + else(is_executable) + set(dotapp_dir "${s}") + endif(is_executable) + endif(s MATCHES "^.*/.*\\.app/.*$") + set(${dotapp_dir_var} "${dotapp_dir}" PARENT_SCOPE) endfunction(get_dotapp_dir) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index 853b1a1..f5c1b74 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -261,9 +261,9 @@ function(gp_resolve_item context item exepath dirs resolved_item_var) # Is it already resolved? # - if(EXISTS "${resolved_item}") + if(IS_ABSOLUTE "${resolved_item}" AND EXISTS "${resolved_item}") set(resolved 1) - endif(EXISTS "${resolved_item}") + endif(IS_ABSOLUTE "${resolved_item}" AND EXISTS "${resolved_item}") if(NOT resolved) if(item MATCHES "@executable_path") diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt new file mode 100644 index 0000000..2a649e4 --- /dev/null +++ b/Tests/BundleUtilities/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 2.8) +project(BundleUtilities) + +###### the various types of dependencies we can have + +# a shared library +add_library(shared SHARED shared.cpp shared.h) + +# another shared library +add_library(shared2 SHARED shared2.cpp shared2.h) + +# a loadable module (depends on shared2) +# test app will load this at runtime +add_library(module MODULE module.cpp module.h) +set_target_properties(module PROPERTIES PREFIX "") +get_target_property(module_loc module LOCATION) +target_link_libraries(module shared2) + +# a framework library +add_library(framework SHARED framework.cpp framework.h) +# TODO: fix problems with local frameworks without rpaths +#set_target_properties(framework PROPERTIES FRAMEWORK 1) + +# make sure rpaths are not helping BundleUtilities or the executables +set_target_properties(shared shared2 module framework PROPERTIES + SKIP_BUILD_RPATH 1) + + +###### test a Bundle application using dependencies + +set(TESTBUNDLEDIR "${CMAKE_CURRENT_BINARY_DIR}/testdir1") +add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils.cpp) +target_link_libraries(testbundleutils1 shared framework ${CMAKE_DL_LIBS}) +set_target_properties(testbundleutils1 PROPERTIES + INSTALL_RPATH "${TESTBUNDLEDIR}" + BUILD_WITH_INSTALL_RPATH 1) +get_target_property(loc testbundleutils1 LOCATION) + +add_custom_target(testbundleutils1_test ALL + COMMAND ${CMAKE_COMMAND} + "-DINPUT=${loc}" + "-DMODULE=${module_loc}" + "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" + "-DOUTPUTDIR=${TESTBUNDLEDIR}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" + ) + +add_dependencies(testbundleutils1_test testbundleutils1) + + + +###### test a non-Bundle application using dependencies + +set(TESTBUNDLEDIR "${CMAKE_CURRENT_BINARY_DIR}/testdir2") +add_executable(testbundleutils2 testbundleutils.cpp) +target_link_libraries(testbundleutils2 shared framework ${CMAKE_DL_LIBS}) +set_target_properties(testbundleutils2 PROPERTIES + INSTALL_RPATH "${TESTBUNDLEDIR}" + BUILD_WITH_INSTALL_RPATH 1) +get_target_property(loc testbundleutils2 LOCATION) + +add_custom_target(testbundleutils2_test ALL + COMMAND ${CMAKE_COMMAND} + "-DINPUT=${loc}" + "-DMODULE=${module_loc}" + "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" + "-DOUTPUTDIR=${TESTBUNDLEDIR}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" + ) +add_dependencies(testbundleutils2_test testbundleutils2) diff --git a/Tests/BundleUtilities/bundleutils.cmake b/Tests/BundleUtilities/bundleutils.cmake new file mode 100644 index 0000000..4a42a3a --- /dev/null +++ b/Tests/BundleUtilities/bundleutils.cmake @@ -0,0 +1,44 @@ + +# clean passed in arguments +get_filename_component(INPUT ${INPUT} ABSOLUTE) +get_filename_component(INPUTDIR ${INPUTDIR} ABSOLUTE) + +message("INPUT = ${INPUT}") +message("MODULE = ${MODULE}") +message("INPUTDIR = ${INPUTDIR}") +message("OUTPUTDIR = ${OUTPUTDIR}") + +# compute location to install/test things +file(RELATIVE_PATH relative_exe "${INPUTDIR}" "${INPUT}") +set(OUTPUT "${OUTPUTDIR}/${relative_exe}") +message("OUTPUT = ${OUTPUT}") +get_filename_component(EXE_DIR "${OUTPUT}" PATH) +get_filename_component(MODULE_NAME "${MODULE}" NAME) +set(OUTPUT_MODULE "${EXE_DIR}/${MODULE_NAME}") +message("OUTPUTMODULE = ${OUTPUT_MODULE}") + +# clean output dir +file(REMOVE_RECURSE "${OUTPUTDIR}") +# copy the app and plugin to installation/testing directory +configure_file("${INPUT}" "${OUTPUT}" COPYONLY) +configure_file("${MODULE}" "${OUTPUT_MODULE}" COPYONLY) + +# have BundleUtilities grab all dependencies and +# check that the app runs + +# for this test we'll override location to put all dependencies +# (in the same dir as the app) +# this shouldn't be necessary except for the non-bundle case on Mac +function(gp_item_default_embedded_path_override item path) + set(path "@executable_path" PARENT_SCOPE) +endfunction(gp_item_default_embedded_path_override) + +include(BundleUtilities) +fixup_bundle("${OUTPUT}" "${OUTPUT_MODULE}" "${INPUTDIR}") + +# make sure we can run the app +execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result) + +if(NOT result STREQUAL "0") + message(FATAL_ERROR " failed to execute test program") +endif(NOT result STREQUAL "0") diff --git a/Tests/BundleUtilities/framework.cpp b/Tests/BundleUtilities/framework.cpp new file mode 100644 index 0000000..abda195 --- /dev/null +++ b/Tests/BundleUtilities/framework.cpp @@ -0,0 +1,8 @@ + +#include "framework.h" +#include "stdio.h" + +void framework() +{ + printf("framework\n"); +} diff --git a/Tests/BundleUtilities/framework.h b/Tests/BundleUtilities/framework.h new file mode 100644 index 0000000..bdd10f0 --- /dev/null +++ b/Tests/BundleUtilities/framework.h @@ -0,0 +1,17 @@ + +#ifndef framework_h +#define framework_h + +#ifdef WIN32 +# ifdef framework_EXPORTS +# define FRAMEWORK_EXPORT __declspec(dllexport) +# else +# define FRAMEWORK_EXPORT __declspec(dllimport) +# endif +#else +# define FRAMEWORK_EXPORT +#endif + +void FRAMEWORK_EXPORT framework(); + +#endif diff --git a/Tests/BundleUtilities/module.cpp b/Tests/BundleUtilities/module.cpp new file mode 100644 index 0000000..ee1b542 --- /dev/null +++ b/Tests/BundleUtilities/module.cpp @@ -0,0 +1,10 @@ + +#include "module.h" +#include "stdio.h" +#include "shared2.h" + +void module() +{ + printf("module\n"); + shared2(); +} diff --git a/Tests/BundleUtilities/module.h b/Tests/BundleUtilities/module.h new file mode 100644 index 0000000..0659bc7 --- /dev/null +++ b/Tests/BundleUtilities/module.h @@ -0,0 +1,7 @@ + +#ifndef module_h +#define module_h + +void module(); + +#endif diff --git a/Tests/BundleUtilities/shared.cpp b/Tests/BundleUtilities/shared.cpp new file mode 100644 index 0000000..e5e7dc5 --- /dev/null +++ b/Tests/BundleUtilities/shared.cpp @@ -0,0 +1,8 @@ + +#include "shared.h" +#include "stdio.h" + +void shared() +{ + printf("shared\n"); +} diff --git a/Tests/BundleUtilities/shared.h b/Tests/BundleUtilities/shared.h new file mode 100644 index 0000000..3588fb8 --- /dev/null +++ b/Tests/BundleUtilities/shared.h @@ -0,0 +1,17 @@ + +#ifndef shared_h +#define shared_h + +#ifdef WIN32 +# ifdef shared_EXPORTS +# define SHARED_EXPORT __declspec(dllexport) +# else +# define SHARED_EXPORT __declspec(dllimport) +# endif +#else +# define SHARED_EXPORT +#endif + +void SHARED_EXPORT shared(); + +#endif diff --git a/Tests/BundleUtilities/shared2.cpp b/Tests/BundleUtilities/shared2.cpp new file mode 100644 index 0000000..84af5d0 --- /dev/null +++ b/Tests/BundleUtilities/shared2.cpp @@ -0,0 +1,8 @@ + +#include "shared2.h" +#include "stdio.h" + +void shared2() +{ + printf("shared2\n"); +} diff --git a/Tests/BundleUtilities/shared2.h b/Tests/BundleUtilities/shared2.h new file mode 100644 index 0000000..d53546c --- /dev/null +++ b/Tests/BundleUtilities/shared2.h @@ -0,0 +1,17 @@ + +#ifndef shared2_h +#define shared2_h + +#ifdef WIN32 +# ifdef shared2_EXPORTS +# define SHARED2_EXPORT __declspec(dllexport) +# else +# define SHARED2_EXPORT __declspec(dllimport) +# endif +#else +# define SHARED2_EXPORT +#endif + +void SHARED2_EXPORT shared2(); + +#endif diff --git a/Tests/BundleUtilities/testbundleutils.cpp b/Tests/BundleUtilities/testbundleutils.cpp new file mode 100644 index 0000000..0b1828f --- /dev/null +++ b/Tests/BundleUtilities/testbundleutils.cpp @@ -0,0 +1,23 @@ + +#include "framework.h" +#include "shared.h" + +#if defined(WIN32) +#include +#else +#include "dlfcn.h" +#endif + +int main(int, char**) +{ + framework(); + shared(); + +#if defined(WIN32) + HANDLE lib = LoadLibraryA("module.dll"); +#else + void* lib = dlopen("module.so", RTLD_LAZY); +#endif + + return lib == 0 ? 1 : 0; +} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index e9aed16..1c4a732 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -193,6 +193,25 @@ IF(BUILD_TESTING) LIST(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX}) + + # run test for BundleUtilities on supported platforms + if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR + CMAKE_SYSTEM_NAME MATCHES "Linux" OR + CMAKE_SYSTEM_NAME MATCHES "Darwin") + ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/BundleUtilities" + "${CMake_BINARY_DIR}/Tests/BundleUtilities" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-project BundleUtilities + --test-command testdir2/testbundleutils2 + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") + endif(CMAKE_SYSTEM_NAME MATCHES "Windows" OR + CMAKE_SYSTEM_NAME MATCHES "Linux" OR + CMAKE_SYSTEM_NAME MATCHES "Darwin") + SET(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly") SET(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly") CONFIGURE_FILE("${CMake_SOURCE_DIR}/Tests/CMakeBuildTest.cmake.in" -- cgit v0.12 From b68d3dc1b5a7b783b9624c6ae4a06e2a70e30b55 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Fri, 27 May 2011 16:48:22 -0600 Subject: BundleUtilities: Fix regex to extract dependents from ldd (#12034) This regex works with spaces in the path. --- Modules/GetPrerequisites.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index f5c1b74..023b8b5 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -548,7 +548,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa if("${gp_tool}" STREQUAL "ldd") set(gp_cmd_args "") - set(gp_regex "^[\t ]*[^\t ]+ => ([^\t ]+).*${eol_char}$") + set(gp_regex "^[\t ]*[^\t ]+ => ([^\t\(]+) .*${eol_char}$") set(gp_regex_error "not found${eol_char}$") set(gp_regex_fallback "^[\t ]*([^\t ]+) => ([^\t ]+).*${eol_char}$") set(gp_regex_cmp_count 1) -- cgit v0.12 From e40b79e79fc0beb0a71889817f21bf196a892b09 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Fri, 27 May 2011 17:06:35 -0600 Subject: BundleUtilities: Fix test when using xcode (#12034) --- Tests/BundleUtilities/bundleutils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/BundleUtilities/bundleutils.cmake b/Tests/BundleUtilities/bundleutils.cmake index 4a42a3a..4df2f2d 100644 --- a/Tests/BundleUtilities/bundleutils.cmake +++ b/Tests/BundleUtilities/bundleutils.cmake @@ -37,7 +37,7 @@ include(BundleUtilities) fixup_bundle("${OUTPUT}" "${OUTPUT_MODULE}" "${INPUTDIR}") # make sure we can run the app -execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result) +execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result WORKING_DIRECTORY "${EXE_DIR}") if(NOT result STREQUAL "0") message(FATAL_ERROR " failed to execute test program") -- cgit v0.12 From fa4dc08a1a69d0766cb17b03f1e3154e2dd0c0e7 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Tue, 31 May 2011 13:17:01 -0600 Subject: BundleUtilities: Fix issues with custom target DEPENDS in test (#12034) --- Tests/BundleUtilities/CMakeLists.txt | 2 ++ Tests/BundleUtilities/bundleutils.cmake | 5 +++-- Tests/BundleUtilities/testbundleutils.cpp | 6 ++++++ Tests/CMakeLists.txt | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt index 2a649e4..be2b058 100644 --- a/Tests/BundleUtilities/CMakeLists.txt +++ b/Tests/BundleUtilities/CMakeLists.txt @@ -43,6 +43,7 @@ add_custom_target(testbundleutils1_test ALL "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" "-DOUTPUTDIR=${TESTBUNDLEDIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" + DEPENDS testbundleutils1 module ) add_dependencies(testbundleutils1_test testbundleutils1) @@ -66,5 +67,6 @@ add_custom_target(testbundleutils2_test ALL "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" "-DOUTPUTDIR=${TESTBUNDLEDIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" + DEPENDS testbundleutils1 module ) add_dependencies(testbundleutils2_test testbundleutils2) diff --git a/Tests/BundleUtilities/bundleutils.cmake b/Tests/BundleUtilities/bundleutils.cmake index 4df2f2d..46765e7 100644 --- a/Tests/BundleUtilities/bundleutils.cmake +++ b/Tests/BundleUtilities/bundleutils.cmake @@ -37,8 +37,9 @@ include(BundleUtilities) fixup_bundle("${OUTPUT}" "${OUTPUT_MODULE}" "${INPUTDIR}") # make sure we can run the app -execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result WORKING_DIRECTORY "${EXE_DIR}") +message("Executing ${OUTPUT} in ${EXE_DIR}") +execute_process(COMMAND "${OUTPUT}" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE out WORKING_DIRECTORY "${EXE_DIR}") if(NOT result STREQUAL "0") - message(FATAL_ERROR " failed to execute test program") + message(FATAL_ERROR " failed to execute test program\n${out}") endif(NOT result STREQUAL "0") diff --git a/Tests/BundleUtilities/testbundleutils.cpp b/Tests/BundleUtilities/testbundleutils.cpp index 0b1828f..87eaae3 100644 --- a/Tests/BundleUtilities/testbundleutils.cpp +++ b/Tests/BundleUtilities/testbundleutils.cpp @@ -1,6 +1,7 @@ #include "framework.h" #include "shared.h" +#include "stdio.h" #if defined(WIN32) #include @@ -19,5 +20,10 @@ int main(int, char**) void* lib = dlopen("module.so", RTLD_LAZY); #endif + if(!lib) + { + printf("Failed to open module\n"); + } + return lib == 0 ? 1 : 0; } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 1c4a732..75ee7d9 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -205,7 +205,6 @@ IF(BUILD_TESTING) --build-generator ${CMAKE_TEST_GENERATOR} --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} --build-project BundleUtilities - --test-command testdir2/testbundleutils2 ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") endif(CMAKE_SYSTEM_NAME MATCHES "Windows" OR -- cgit v0.12 From 900bf98d0103567aa51f0d1d2fc0f5d5eb67c124 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Tue, 31 May 2011 22:15:34 -0600 Subject: BundleUtilities: Disable running test on Windows unless using MSVC. --- Tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 75ee7d9..d840b96 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -194,8 +194,8 @@ IF(BUILD_TESTING) LIST(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX}) - # run test for BundleUtilities on supported platforms - if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR + # run test for BundleUtilities on supported platforms/compilers + if(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} @@ -207,7 +207,7 @@ IF(BUILD_TESTING) --build-project BundleUtilities ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") - endif(CMAKE_SYSTEM_NAME MATCHES "Windows" OR + endif(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") -- cgit v0.12 From f3de459cec78eac3a7081379b6ee9c6cde36bb60 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Wed, 1 Jun 2011 10:53:06 -0600 Subject: BundleUtilities: Run test on Windows if either MSVC or dumpbin was found. --- Tests/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index d840b96..be0b3f9 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -195,7 +195,9 @@ IF(BUILD_TESTING) # run test for BundleUtilities on supported platforms/compilers - if(MSVC OR + find_program(DUMPBIN_EXECUTABLE NAMES dumpbin) + mark_as_advanced(DUMPBIN_EXECUTABLE) + if(MSVC OR DUMPBIN_EXECUTABLE OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} @@ -207,7 +209,7 @@ IF(BUILD_TESTING) --build-project BundleUtilities ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") - endif(MSVC OR + endif(MSVC OR DUMPBIN_EXECUTABLE OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") -- cgit v0.12 From 8064044c94a7ed8e4b8a699a730ebab1aafd925b Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Wed, 1 Jun 2011 10:59:34 -0600 Subject: BundleUtilities: Print reason for not loading module.so --- Tests/BundleUtilities/testbundleutils.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Tests/BundleUtilities/testbundleutils.cpp b/Tests/BundleUtilities/testbundleutils.cpp index 87eaae3..77fe4b0 100644 --- a/Tests/BundleUtilities/testbundleutils.cpp +++ b/Tests/BundleUtilities/testbundleutils.cpp @@ -16,14 +16,18 @@ int main(int, char**) #if defined(WIN32) HANDLE lib = LoadLibraryA("module.dll"); + if(!lib) + { + printf("Failed to open module\n"); + } #else void* lib = dlopen("module.so", RTLD_LAZY); -#endif - if(!lib) { - printf("Failed to open module\n"); + printf("Failed to open module\n%s\n", dlerror()); } +#endif + return lib == 0 ? 1 : 0; } -- cgit v0.12 From e17135e882188145e04c2ff455fad01273fdb375 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 2 Jun 2011 09:08:49 -0600 Subject: BundleUtilities: Add rpath to loadable modules in test. --- Tests/BundleUtilities/CMakeLists.txt | 54 ++++++++++++++++++------------ Tests/BundleUtilities/testbundleutils.cpp | 33 ------------------ Tests/BundleUtilities/testbundleutils1.cpp | 33 ++++++++++++++++++ Tests/BundleUtilities/testbundleutils2.cpp | 33 ++++++++++++++++++ 4 files changed, 99 insertions(+), 54 deletions(-) delete mode 100644 Tests/BundleUtilities/testbundleutils.cpp create mode 100644 Tests/BundleUtilities/testbundleutils1.cpp create mode 100644 Tests/BundleUtilities/testbundleutils2.cpp diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt index be2b058..6209c8f 100644 --- a/Tests/BundleUtilities/CMakeLists.txt +++ b/Tests/BundleUtilities/CMakeLists.txt @@ -9,12 +9,6 @@ add_library(shared SHARED shared.cpp shared.h) # another shared library add_library(shared2 SHARED shared2.cpp shared2.h) -# a loadable module (depends on shared2) -# test app will load this at runtime -add_library(module MODULE module.cpp module.h) -set_target_properties(module PROPERTIES PREFIX "") -get_target_property(module_loc module LOCATION) -target_link_libraries(module shared2) # a framework library add_library(framework SHARED framework.cpp framework.h) @@ -22,28 +16,37 @@ add_library(framework SHARED framework.cpp framework.h) #set_target_properties(framework PROPERTIES FRAMEWORK 1) # make sure rpaths are not helping BundleUtilities or the executables -set_target_properties(shared shared2 module framework PROPERTIES +set_target_properties(shared shared2 framework PROPERTIES SKIP_BUILD_RPATH 1) ###### test a Bundle application using dependencies -set(TESTBUNDLEDIR "${CMAKE_CURRENT_BINARY_DIR}/testdir1") -add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils.cpp) +# a loadable module (depends on shared2) +# testbundleutils1 will load this at runtime +add_library(module1 MODULE module.cpp module.h) +set_target_properties(module1 PROPERTIES PREFIX "") +get_target_property(module_loc module1 LOCATION) +target_link_libraries(module1 shared2) + +# a bundle application +add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils1.cpp) target_link_libraries(testbundleutils1 shared framework ${CMAKE_DL_LIBS}) -set_target_properties(testbundleutils1 PROPERTIES - INSTALL_RPATH "${TESTBUNDLEDIR}" - BUILD_WITH_INSTALL_RPATH 1) get_target_property(loc testbundleutils1 LOCATION) +set_target_properties(testbundleutils1 module1 PROPERTIES + INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir1" + BUILD_WITH_INSTALL_RPATH 1) + +# add custom target to install and test the app add_custom_target(testbundleutils1_test ALL COMMAND ${CMAKE_COMMAND} "-DINPUT=${loc}" "-DMODULE=${module_loc}" "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" - "-DOUTPUTDIR=${TESTBUNDLEDIR}" + "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir1" -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" - DEPENDS testbundleutils1 module + DEPENDS testbundleutils1 module1 ) add_dependencies(testbundleutils1_test testbundleutils1) @@ -52,21 +55,30 @@ add_dependencies(testbundleutils1_test testbundleutils1) ###### test a non-Bundle application using dependencies -set(TESTBUNDLEDIR "${CMAKE_CURRENT_BINARY_DIR}/testdir2") -add_executable(testbundleutils2 testbundleutils.cpp) +# a loadable module (depends on shared2) +# testbundleutils2 will load this at runtime +add_library(module2 MODULE module.cpp module.h) +set_target_properties(module2 PROPERTIES PREFIX "") +get_target_property(module_loc module2 LOCATION) +target_link_libraries(module2 shared2) + +# a non-bundle application +add_executable(testbundleutils2 testbundleutils2.cpp) target_link_libraries(testbundleutils2 shared framework ${CMAKE_DL_LIBS}) -set_target_properties(testbundleutils2 PROPERTIES - INSTALL_RPATH "${TESTBUNDLEDIR}" - BUILD_WITH_INSTALL_RPATH 1) get_target_property(loc testbundleutils2 LOCATION) +set_target_properties(testbundleutils2 module2 PROPERTIES + INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir2" + BUILD_WITH_INSTALL_RPATH 1) + +# add custom target to install and test the app add_custom_target(testbundleutils2_test ALL COMMAND ${CMAKE_COMMAND} "-DINPUT=${loc}" "-DMODULE=${module_loc}" "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" - "-DOUTPUTDIR=${TESTBUNDLEDIR}" + "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir2" -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" - DEPENDS testbundleutils1 module + DEPENDS testbundleutils1 module2 ) add_dependencies(testbundleutils2_test testbundleutils2) diff --git a/Tests/BundleUtilities/testbundleutils.cpp b/Tests/BundleUtilities/testbundleutils.cpp deleted file mode 100644 index 77fe4b0..0000000 --- a/Tests/BundleUtilities/testbundleutils.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include "framework.h" -#include "shared.h" -#include "stdio.h" - -#if defined(WIN32) -#include -#else -#include "dlfcn.h" -#endif - -int main(int, char**) -{ - framework(); - shared(); - -#if defined(WIN32) - HANDLE lib = LoadLibraryA("module.dll"); - if(!lib) - { - printf("Failed to open module\n"); - } -#else - void* lib = dlopen("module.so", RTLD_LAZY); - if(!lib) - { - printf("Failed to open module\n%s\n", dlerror()); - } -#endif - - - return lib == 0 ? 1 : 0; -} diff --git a/Tests/BundleUtilities/testbundleutils1.cpp b/Tests/BundleUtilities/testbundleutils1.cpp new file mode 100644 index 0000000..23d3cbd --- /dev/null +++ b/Tests/BundleUtilities/testbundleutils1.cpp @@ -0,0 +1,33 @@ + +#include "framework.h" +#include "shared.h" +#include "stdio.h" + +#if defined(WIN32) +#include +#else +#include "dlfcn.h" +#endif + +int main(int, char**) +{ + framework(); + shared(); + +#if defined(WIN32) + HANDLE lib = LoadLibraryA("module1.dll"); + if(!lib) + { + printf("Failed to open module1\n"); + } +#else + void* lib = dlopen("module1.so", RTLD_LAZY); + if(!lib) + { + printf("Failed to open module1\n%s\n", dlerror()); + } +#endif + + + return lib == 0 ? 1 : 0; +} diff --git a/Tests/BundleUtilities/testbundleutils2.cpp b/Tests/BundleUtilities/testbundleutils2.cpp new file mode 100644 index 0000000..319be89 --- /dev/null +++ b/Tests/BundleUtilities/testbundleutils2.cpp @@ -0,0 +1,33 @@ + +#include "framework.h" +#include "shared.h" +#include "stdio.h" + +#if defined(WIN32) +#include +#else +#include "dlfcn.h" +#endif + +int main(int, char**) +{ + framework(); + shared(); + +#if defined(WIN32) + HANDLE lib = LoadLibraryA("module2.dll"); + if(!lib) + { + printf("Failed to open module2\n"); + } +#else + void* lib = dlopen("module2.so", RTLD_LAZY); + if(!lib) + { + printf("Failed to open module2\n%s\n", dlerror()); + } +#endif + + + return lib == 0 ? 1 : 0; +} -- cgit v0.12 From 41f962a2cb239616e75f5de12d8987609dc4cde6 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 2 Jun 2011 09:09:14 -0600 Subject: Revert "BundleUtilities: Run test on Windows if either MSVC or dumpbin was found." This reverts commit f3de459cec78eac3a7081379b6ee9c6cde36bb60. There are some platforms without MSVC where this test doesn't work well. We can look into these later. --- Tests/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index be0b3f9..d840b96 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -195,9 +195,7 @@ IF(BUILD_TESTING) # run test for BundleUtilities on supported platforms/compilers - find_program(DUMPBIN_EXECUTABLE NAMES dumpbin) - mark_as_advanced(DUMPBIN_EXECUTABLE) - if(MSVC OR DUMPBIN_EXECUTABLE OR + if(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} @@ -209,7 +207,7 @@ IF(BUILD_TESTING) --build-project BundleUtilities ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") - endif(MSVC OR DUMPBIN_EXECUTABLE OR + endif(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") -- cgit v0.12 From 51e16c05f7c4e70d8bbf97a13243b1f1cfffa2d7 Mon Sep 17 00:00:00 2001 From: David Cole Date: Sat, 4 Jun 2011 19:52:45 -0400 Subject: BundleUtilities: Avoid test on Watcom dashboards (#12034) --- Tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index d840b96..8149847 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -198,6 +198,7 @@ IF(BUILD_TESTING) if(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") + if(NOT "${CMAKE_TEST_GENERATOR}" STREQUAL "Watcom WMake") ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/BundleUtilities" @@ -207,9 +208,8 @@ IF(BUILD_TESTING) --build-project BundleUtilities ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") - endif(MSVC OR - CMAKE_SYSTEM_NAME MATCHES "Linux" OR - CMAKE_SYSTEM_NAME MATCHES "Darwin") + endif() + endif() SET(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly") SET(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly") -- cgit v0.12