mirror of
https://github.com/reactos/CMake.git
synced 2024-11-25 12:40:06 +00:00
OS X: Add test for rpaths on Mac.
This also tests rpaths through export/import.
This commit is contained in:
parent
8576b3f978
commit
dc1d025197
@ -1219,6 +1219,16 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE AND "${DARWIN_MAJOR_VERSION}" GREATER 9)
|
||||
add_test(MacRuntimePath ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/MacRuntimePath"
|
||||
"${CMake_BINARY_DIR}/Tests/MacRuntimePath"
|
||||
${build_generator_args}
|
||||
--build-project MacRuntimePath
|
||||
)
|
||||
endif()
|
||||
|
||||
add_test(linkorder1 ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/LinkLineOrder"
|
||||
|
63
Tests/MacRuntimePath/A/CMakeLists.txt
Normal file
63
Tests/MacRuntimePath/A/CMakeLists.txt
Normal file
@ -0,0 +1,63 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(MacRuntimePath_A)
|
||||
|
||||
# a shared library
|
||||
add_library(shared SHARED shared.cpp shared.h)
|
||||
set_target_properties(shared PROPERTIES MACOSX_RPATH 1)
|
||||
|
||||
# a shared library with custom set @rpath
|
||||
add_library(shared2 SHARED shared.cpp shared.h)
|
||||
set_target_properties(shared2 PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
|
||||
|
||||
# a framework library
|
||||
add_library(framework SHARED framework.cpp framework.h)
|
||||
set_target_properties(framework PROPERTIES MACOSX_RPATH 1 FRAMEWORK 1)
|
||||
|
||||
# executable to test a shared library dependency with install rpaths
|
||||
add_executable(test1 test1.cpp)
|
||||
target_link_libraries(test1 shared)
|
||||
set_target_properties(test1 PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH 1 INSTALL_RPATH "@loader_path/../lib")
|
||||
|
||||
# executable to test a framework library dependency with install rpaths
|
||||
add_executable(test2 test2.cpp)
|
||||
target_link_libraries(test2 framework)
|
||||
set_target_properties(test2 PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH 1 INSTALL_RPATH "@loader_path/../lib")
|
||||
|
||||
# executable to test a framework library dependency with build tree rpaths
|
||||
add_executable(test3 test3.cpp)
|
||||
target_link_libraries(test3 framework)
|
||||
|
||||
# executable to test a framework library dependency with build tree rpaths
|
||||
add_executable(test4 test1.cpp)
|
||||
target_link_libraries(test4 shared2)
|
||||
|
||||
set_target_properties(shared shared2 framework PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
|
||||
set_target_properties(test1 test2 test3 test4 PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
||||
foreach(config ${CMAKE_CONFIGURATION_TYPES})
|
||||
string(TOUPPER ${config} CONFIG)
|
||||
set_target_properties(shared shared2 framework PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY_${CONFIG}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${config}/lib")
|
||||
set_target_properties(test1 test2 test3 test4 PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${CONFIG}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${config}/bin")
|
||||
endforeach()
|
||||
|
||||
foreach(test test1 test2 test3 test4)
|
||||
add_custom_target(${test}_run ALL
|
||||
COMMAND ${test}
|
||||
DEPENDS ${test}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
export(TARGETS shared shared2 framework FILE "${CMAKE_CURRENT_BINARY_DIR}/exp.cmake")
|
||||
|
||||
install(TARGETS shared EXPORT MyExport DESTINATION lib)
|
||||
install(TARGETS shared2 EXPORT MyExport DESTINATION lib2)
|
||||
install(TARGETS framework EXPORT MyExport DESTINATION lib-fw)
|
||||
install(EXPORT MyExport DESTINATION lib FILE exp.cmake)
|
8
Tests/MacRuntimePath/A/framework.cpp
Normal file
8
Tests/MacRuntimePath/A/framework.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "framework.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void framework()
|
||||
{
|
||||
printf("framework\n");
|
||||
}
|
17
Tests/MacRuntimePath/A/framework.h
Normal file
17
Tests/MacRuntimePath/A/framework.h
Normal file
@ -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
|
8
Tests/MacRuntimePath/A/shared.cpp
Normal file
8
Tests/MacRuntimePath/A/shared.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "shared.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void shared()
|
||||
{
|
||||
printf("shared\n");
|
||||
}
|
17
Tests/MacRuntimePath/A/shared.h
Normal file
17
Tests/MacRuntimePath/A/shared.h
Normal file
@ -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
|
8
Tests/MacRuntimePath/A/test1.cpp
Normal file
8
Tests/MacRuntimePath/A/test1.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
shared();
|
||||
return 0;
|
||||
}
|
8
Tests/MacRuntimePath/A/test2.cpp
Normal file
8
Tests/MacRuntimePath/A/test2.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
framework();
|
||||
return 0;
|
||||
}
|
8
Tests/MacRuntimePath/A/test3.cpp
Normal file
8
Tests/MacRuntimePath/A/test3.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
framework();
|
||||
return 0;
|
||||
}
|
17
Tests/MacRuntimePath/B/CMakeLists.txt
Normal file
17
Tests/MacRuntimePath/B/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(MacRuntimePath_B)
|
||||
|
||||
include(${MacRuntimePath_B_BINARY_DIR}/../Root/lib/exp.cmake)
|
||||
|
||||
add_executable(testb ${MacRuntimePath_B_SOURCE_DIR}/../A/test3.cpp)
|
||||
|
||||
# test link with rpath enabled targets
|
||||
target_link_libraries(testb shared framework)
|
||||
|
||||
# test link with rpath enabled library by filename
|
||||
target_link_libraries(testb $<TARGET_LINKER_FILE:shared2> framework)
|
||||
|
||||
add_custom_target(testb_run ALL
|
||||
COMMAND testb
|
||||
DEPENDS testb
|
||||
)
|
72
Tests/MacRuntimePath/CMakeLists.txt
Normal file
72
Tests/MacRuntimePath/CMakeLists.txt
Normal file
@ -0,0 +1,72 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project(MacRuntimePath)
|
||||
|
||||
|
||||
# Wipe out the install tree to make sure the exporter works.
|
||||
add_custom_command(
|
||||
OUTPUT ${MacRuntimePath_BINARY_DIR}/CleanupProject
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${MacRuntimePath_BINARY_DIR}/Root
|
||||
)
|
||||
add_custom_target(CleanupTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/CleanupProject)
|
||||
set_property(
|
||||
SOURCE ${MacRuntimePath_BINARY_DIR}/CleanupProject
|
||||
PROPERTY SYMBOLIC 1
|
||||
)
|
||||
|
||||
configure_file(${MacRuntimePath_SOURCE_DIR}/InitialCache.cmake.in
|
||||
${MacRuntimePath_BINARY_DIR}/InitialCache.cmake @ONLY)
|
||||
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
|
||||
else()
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
|
||||
else()
|
||||
set(NESTED_CONFIG_TYPE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Build and install the exporter.
|
||||
add_custom_command(
|
||||
OUTPUT ${MacRuntimePath_BINARY_DIR}/ExportProject
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
|
||||
--build-and-test
|
||||
${MacRuntimePath_SOURCE_DIR}/A
|
||||
${MacRuntimePath_BINARY_DIR}/A
|
||||
--build-noclean
|
||||
--build-project MacRuntimePath_A
|
||||
--build-target install
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-options -C${MacRuntimePath_BINARY_DIR}/InitialCache.cmake
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(ExportTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/ExportProject)
|
||||
add_dependencies(ExportTarget CleanupTarget)
|
||||
set_property(
|
||||
SOURCE ${MacRuntimePath_BINARY_DIR}/ExportProject
|
||||
PROPERTY SYMBOLIC 1
|
||||
)
|
||||
|
||||
# Build the importer.
|
||||
add_custom_command(
|
||||
OUTPUT ${MacRuntimePath_BINARY_DIR}/ImportProject
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
|
||||
--build-and-test
|
||||
${MacRuntimePath_SOURCE_DIR}/B
|
||||
${MacRuntimePath_BINARY_DIR}/B
|
||||
--build-noclean
|
||||
--build-project MacRuntimePath_B
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-options -C${MacRuntimePath_BINARY_DIR}/InitialCache.cmake
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(ImportTarget ALL DEPENDS ${MacRuntimePath_BINARY_DIR}/ImportProject)
|
||||
add_dependencies(ImportTarget ExportTarget)
|
||||
set_property(
|
||||
SOURCE ${MacRuntimePath_BINARY_DIR}/ImportProject
|
||||
PROPERTY SYMBOLIC 1
|
||||
)
|
13
Tests/MacRuntimePath/InitialCache.cmake.in
Normal file
13
Tests/MacRuntimePath/InitialCache.cmake.in
Normal file
@ -0,0 +1,13 @@
|
||||
set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@" CACHE STRING "C Compiler")
|
||||
set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@" CACHE STRING "C Flags")
|
||||
set(CMAKE_C_FLAGS_DEBUG "@CMAKE_C_FLAGS_DEBUG@" CACHE STRING "C Flags")
|
||||
set(CMAKE_C_FLAGS_RELEASE "@CMAKE_C_FLAGS_RELEASE@" CACHE STRING "C Flags")
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL "@CMAKE_C_FLAGS_MINSIZEREL@" CACHE STRING "C Flags")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "@CMAKE_C_FLAGS_RELWITHDEBINFO@" CACHE STRING "C Flags")
|
||||
set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@" CACHE STRING "C++ Compiler")
|
||||
set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@" CACHE STRING "C++ Flags")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "@CMAKE_CXX_FLAGS_DEBUG@" CACHE STRING "C++ Flags")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "@CMAKE_CXX_FLAGS_RELEASE@" CACHE STRING "C++ Flags")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "@CMAKE_CXX_FLAGS_MINSIZEREL@" CACHE STRING "C++ Flags")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "@CMAKE_CXX_FLAGS_RELWITHDEBINFO@" CACHE STRING "C++ Flags")
|
||||
set(CMAKE_INSTALL_PREFIX "@MacRuntimePath_BINARY_DIR@/Root" CACHE STRING "Installation Prefix")
|
Loading…
Reference in New Issue
Block a user