Test C, C++, Fortran interface combinations

Previously the Fortran test created a single executable containing C,
C++, and Fortran sources.  This commit divides the executable into three
libraries corresponding to each language, and two executables testing
Fortran/C only and Fortran/C/C++ together.  The result tests more
combinations of using the languages together, and that language
requirements propagate through linking.
This commit is contained in:
Brad King 2009-08-04 14:06:45 -04:00
parent 39e0e04416
commit f3cd1e06f5
6 changed files with 35 additions and 11 deletions

View File

@ -30,7 +30,6 @@ function(test_fortran_c_interface_module)
endif(FORTRAN_C_MODULE_MANGLING_FOUND) endif(FORTRAN_C_MODULE_MANGLING_FOUND)
endif() endif()
set(FORTRAN_FUNCTIONS ${FORTRAN_FUNCTIONS} my_sub mysub ) set(FORTRAN_FUNCTIONS ${FORTRAN_FUNCTIONS} my_sub mysub )
set(srcs ${srcs} mysub.f foo.c foo.cxx)
create_fortran_c_interface("F_" FORTRAN_FUNCTIONS create_fortran_c_interface("F_" FORTRAN_FUNCTIONS
"${testf_BINARY_DIR}/foo.h") "${testf_BINARY_DIR}/foo.h")
include_directories("${testf_BINARY_DIR}") include_directories("${testf_BINARY_DIR}")
@ -61,7 +60,20 @@ function(test_fortran_c_interface_module)
endif() endif()
message("Fortran = ${CMAKE_Fortran_COMPILER_ID}") message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
message("C = ${CMAKE_C_COMPILER_ID}") message("C = ${CMAKE_C_COMPILER_ID}")
add_executable(foo ${srcs})
add_library(myfort mysub.f ${srcs})
add_library(myc myc.c)
target_link_libraries(myc myfort)
add_library(mycxx mycxx.cxx)
target_link_libraries(mycxx myc)
add_executable(mainc mainc.c)
target_link_libraries(mainc myc)
add_executable(maincxx maincxx.c)
target_link_libraries(maincxx mycxx)
# print out some stuff to help debug on machines via cdash # print out some stuff to help debug on machines via cdash
file(READ "${testf_BINARY_DIR}/foo.h" fooh) file(READ "${testf_BINARY_DIR}/foo.h" fooh)
message("foo.h contents:\n${fooh}") message("foo.h contents:\n${fooh}")

View File

@ -1,6 +0,0 @@
extern "C" int foo(void);
int main()
{
delete new int;
return foo();
}

5
Tests/Fortran/mainc.c Normal file
View File

@ -0,0 +1,5 @@
extern int myc(void);
int main()
{
return myc();
}

6
Tests/Fortran/maincxx.c Normal file
View File

@ -0,0 +1,6 @@
extern int myc(void);
extern int mycxx(void);
int main()
{
return myc() + mycxx();
}

View File

@ -1,11 +1,12 @@
#include "foo.h" #include "foo.h"
extern F_test_mod_sub(); extern F_test_mod_sub(void);
extern F_mysub(); extern F_mysub(void);
int foo() int myc(void)
{ {
F_mysub(); F_mysub();
F_my_sub(); F_my_sub();
#ifdef F_test_mod_sub #ifdef F_test_mod_sub
F_test_mod_sub(); F_test_mod_sub();
#endif #endif
return 0;
} }

6
Tests/Fortran/mycxx.cxx Normal file
View File

@ -0,0 +1,6 @@
extern "C" int myc(void);
extern "C" int mycxx(void)
{
delete new int;
return myc();
}