ENH: Added ExportImport test to test new export/import features.
This commit is contained in:
parent
1332b55794
commit
976b426b2d
|
@ -51,6 +51,7 @@ IF(BUILD_TESTING)
|
|||
ADD_TEST_MACRO(Assembler HelloAsm)
|
||||
ADD_TEST_MACRO(SourceGroups SourceGroups)
|
||||
ADD_TEST_MACRO(Preprocess Preprocess)
|
||||
ADD_TEST_MACRO(ExportImport ExportImport)
|
||||
|
||||
IF (CMAKE_STRICT)
|
||||
ADD_TEST_MACRO(DocTest DocTest)
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
project(ExportImport C)
|
||||
|
||||
# Wipe out the install tree to make sure the exporter works.
|
||||
add_custom_command(
|
||||
OUTPUT ${ExportImport_BINARY_DIR}/CleanupProject
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${ExportImport_BINARY_DIR}/Root
|
||||
)
|
||||
add_custom_target(CleanupTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/CleanupProject)
|
||||
|
||||
# Build and install the exporter.
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
set(Export_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
|
||||
else(CMAKE_CONFIGURATION_TYPES)
|
||||
set(Export_CONFIG_TYPE)
|
||||
endif(CMAKE_CONFIGURATION_TYPES)
|
||||
add_custom_command(
|
||||
OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} ${Export_CONFIG_TYPE}
|
||||
--build-and-test
|
||||
${ExportImport_SOURCE_DIR}/Export
|
||||
${ExportImport_BINARY_DIR}/Export
|
||||
--build-noclean
|
||||
--build-project Export
|
||||
--build-target install
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
|
||||
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
-DCMAKE_INSTALL_PREFIX=${ExportImport_BINARY_DIR}/Root
|
||||
)
|
||||
add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
|
||||
add_dependencies(ExportTarget CleanupTarget)
|
||||
|
||||
# Build and install the importer.
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
set(Import_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
|
||||
else(CMAKE_CONFIGURATION_TYPES)
|
||||
set(Import_CONFIG_TYPE)
|
||||
endif(CMAKE_CONFIGURATION_TYPES)
|
||||
add_custom_command(
|
||||
OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} ${Import_CONFIG_TYPE}
|
||||
--build-and-test
|
||||
${ExportImport_SOURCE_DIR}/Import
|
||||
${ExportImport_BINARY_DIR}/Import
|
||||
--build-noclean
|
||||
--build-project Import
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
|
||||
--build-options
|
||||
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
|
||||
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
-DCMAKE_INSTALL_PREFIX=${ExportImport_BINARY_DIR}/Root
|
||||
)
|
||||
add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
|
||||
add_dependencies(ImportTarget ExportTarget)
|
||||
|
||||
add_executable(ExportImport main.c)
|
||||
add_dependencies(ExportImport ImportTarget)
|
|
@ -0,0 +1,33 @@
|
|||
project(Export C)
|
||||
|
||||
# We need ansi C support.
|
||||
if(CMAKE_ANSI_CFLAGS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
|
||||
endif(CMAKE_ANSI_CFLAGS)
|
||||
|
||||
add_executable(testExe1 testExe1.c)
|
||||
|
||||
add_executable(testExe2 testExe2.c)
|
||||
set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
|
||||
|
||||
add_library(testLib1 STATIC testLib1.c)
|
||||
add_library(testLib2 STATIC testLib2.c)
|
||||
target_link_libraries(testLib2 testLib1)
|
||||
|
||||
add_library(testLib3 SHARED testLib3.c)
|
||||
|
||||
# Install and export from install tree.
|
||||
install(
|
||||
TARGETS testExe1 testLib1 testLib2 testExe2 testLib3
|
||||
EXPORT exp
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
|
||||
|
||||
# Export from build tree.
|
||||
export(TARGETS testExe1 testLib1 testLib2 testExe2 testLib3
|
||||
NAMESPACE bld_
|
||||
FILE ExportBuildTree.cmake
|
||||
)
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Must specify output file.\n");
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
FILE* f = fopen(argv[1], "w");
|
||||
if(f)
|
||||
{
|
||||
fprintf(f, "int generated_by_testExe1() { return 0; }\n");
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error writing to %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define testExe2_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define testExe2_EXPORT
|
||||
#endif
|
||||
|
||||
testExe2_EXPORT int testExe2Func(void) { return 123; }
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
int testLib1() { return 0; }
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
extern int testLib1();
|
||||
|
||||
int testLib2() { return testLib1(); }
|
|
@ -0,0 +1,7 @@
|
|||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define testLib3_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define testLib3_EXPORT
|
||||
#endif
|
||||
|
||||
testLib3_EXPORT int testLib3(void) { return 0; }
|
|
@ -0,0 +1,50 @@
|
|||
project(Import C)
|
||||
|
||||
# We need ansi C support.
|
||||
if(CMAKE_ANSI_CFLAGS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
|
||||
endif(CMAKE_ANSI_CFLAGS)
|
||||
|
||||
# Import targets from the exported build tree.
|
||||
include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake)
|
||||
|
||||
# Import targets from the exported install tree.
|
||||
include(${CMAKE_INSTALL_PREFIX}/lib/exp/exp.cmake)
|
||||
|
||||
# Try referencing an executable imported from the install tree.
|
||||
add_custom_command(
|
||||
OUTPUT ${Import_BINARY_DIR}/exp_generated.c
|
||||
COMMAND exp_testExe1 ${Import_BINARY_DIR}/exp_generated.c
|
||||
DEPENDS exp_testExe1
|
||||
)
|
||||
|
||||
add_executable(imp_testExe1
|
||||
imp_testExe1.c
|
||||
${Import_BINARY_DIR}/exp_generated.c
|
||||
)
|
||||
|
||||
# Try linking to a library imported from the install tree.
|
||||
target_link_libraries(imp_testExe1 exp_testLib2 exp_testLib3)
|
||||
|
||||
# Try building a plugin to an executable imported from the install tree.
|
||||
add_library(imp_mod1 MODULE imp_mod1.c)
|
||||
target_link_libraries(imp_mod1 exp_testExe2)
|
||||
|
||||
# Try referencing an executable imported from the build tree.
|
||||
add_custom_command(
|
||||
OUTPUT ${Import_BINARY_DIR}/bld_generated.c
|
||||
COMMAND bld_testExe1 ${Import_BINARY_DIR}/bld_generated.c
|
||||
DEPENDS bld_testExe1
|
||||
)
|
||||
|
||||
add_executable(imp_testExe1b
|
||||
imp_testExe1.c
|
||||
${Import_BINARY_DIR}/bld_generated.c
|
||||
)
|
||||
|
||||
# Try linking to a library imported from the build tree.
|
||||
target_link_libraries(imp_testExe1b bld_testLib2 bld_testLib3)
|
||||
|
||||
# Try building a plugin to an executable imported from the build tree.
|
||||
add_library(imp_mod1b MODULE imp_mod1.c)
|
||||
target_link_libraries(imp_mod1b bld_testExe2)
|
|
@ -0,0 +1,12 @@
|
|||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define testExe2_IMPORT __declspec(dllimport)
|
||||
#else
|
||||
# define testExe2_IMPORT
|
||||
#endif
|
||||
|
||||
testExe2_IMPORT int testExe2Func(void);
|
||||
|
||||
int imp_mod1()
|
||||
{
|
||||
return testExe2Func();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
extern int generated_by_testExe1();
|
||||
extern int testLib2();
|
||||
extern int testLib3();
|
||||
|
||||
int main()
|
||||
{
|
||||
return testLib2() + generated_by_testExe1() + testLib3();
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue