Much improved test, should now be executed on all UNIXes

Instead of relying on that some development package is installed on the
system, now a tiny library is built, which is the searched and used
during the test.

Alex
This commit is contained in:
Alex Neundorf 2011-08-16 22:31:26 +02:00
parent ec6982dc8c
commit 626fc717c6
6 changed files with 33 additions and 17 deletions

View File

@ -1,15 +1,15 @@
if("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Intel
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES XL
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES SunPro)
find_package(PNG)
# the test program links against the png lib, so test first whether it exists
if(PNG_FOUND AND UNIX AND "${CMAKE_GENERATOR}" MATCHES "Makefile")
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Makefile")
# build a library which we can search during the test
add_library(foo STATIC foo.cpp)
# configure a FindFoo.cmake so it knows where the library can be found
configure_file(FindFoo.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindFoo.cmake @ONLY)
# now set up the test:
get_target_property(cmakeExecutable cmake LOCATION)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in ${CMAKE_CURRENT_BINARY_DIR}/ConfMakefile @ONLY)
@ -18,5 +18,3 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES GNU
add_test(FindPackageModeMakefileTest ${CMAKE_MAKE_PROGRAM} -f ${CMAKE_CURRENT_BINARY_DIR}/ConfMakefile )
endif()
endif()

View File

@ -0,0 +1,8 @@
find_library(FOO_LIBRARY NAMES foo HINTS "@CMAKE_CURRENT_BINARY_DIR@" )
find_path(FOO_INCLUDE_DIR NAMES foo.h HINTS "@CMAKE_CURRENT_SOURCE_DIR@" )
set(FOO_LIBRARIES ${FOO_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Foo DEFAULT_MSG FOO_LIBRARY FOO_INCLUDE_DIR )

View File

@ -1,10 +1,10 @@
all: clean pngtest
main.o: main.cpp
"@CMAKE_CXX_COMPILER@" -c `"@cmakeExecutable@" --find-package -DNAME=PNG -DLANGUAGE=CXX -DCOMPILER_ID=@CMAKE_CXX_COMPILER_ID@ -DMODE=COMPILE` main.cpp
"@CMAKE_CXX_COMPILER@" -c `"@cmakeExecutable@" --find-package -DCMAKE_MODULE_PATH="@CMAKE_CURRENT_BINARY_DIR@" -DNAME=Foo -DLANGUAGE=CXX -DCOMPILER_ID=@CMAKE_CXX_COMPILER_ID@ -DMODE=COMPILE` main.cpp
pngtest: main.o
"@CMAKE_CXX_COMPILER@" -o pngtest main.o `"@cmakeExecutable@" --find-package -DNAME=PNG -DLANGUAGE=CXX -DCOMPILER_ID=@CMAKE_CXX_COMPILER_ID@ -DMODE=LINK`
"@CMAKE_CXX_COMPILER@" -o pngtest main.o `"@cmakeExecutable@" --find-package -DCMAKE_MODULE_PATH="@CMAKE_CURRENT_BINARY_DIR@" -DNAME=Foo -DLANGUAGE=CXX -DCOMPILER_ID=@CMAKE_CXX_COMPILER_ID@ -DMODE=LINK`
clean:
rm -f *.o pngtest

View File

@ -0,0 +1,4 @@
int foo()
{
return 1477;
}

View File

@ -0,0 +1,6 @@
#ifndef FOO_H
#define FOO_H
int foo();
#endif

View File

@ -1,8 +1,8 @@
#include <stdio.h>
#include <png.h>
#include <foo.h>
int main()
{
printf("PNG copyright: %s\n", png_get_copyright(NULL));
printf("foo is: %d\n", foo());
return 0;
}