Commit c8d8e693 authored by Sebastien Barre's avatar Sebastien Barre
Browse files

Add documentation, comments. Move some 'Complex' sub-tests into 2 new...

Add documentation, comments. Move some 'Complex' sub-tests into 2 new 'Wrapping' and 'Testing' tests.
parent 30b3cc07
......@@ -12,28 +12,41 @@ ENDIF (CMAKE_ANSI_CXXFLAGS)
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
#
# Include vars from a file and from a cache
#
IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
INCLUDE(${Complex_SOURCE_DIR}/VarTests.cmake)
ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
LOAD_CACHE(${Complex_SOURCE_DIR})
#
# Configure file
# (plug vars to #define so that they can be tested)
#
CONFIGURE_FILE(
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
${Complex_BINARY_DIR}/cmTestConfigure.h)
#
# Specify include and lib dirs
#
INCLUDE_DIRECTORIES(
${Complex_BINARY_DIR}
${Complex_SOURCE_DIR}/Library
${Complex_SOURCE_DIR}/../../Source
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
LINK_DIRECTORIES(
${Complex_BINARY_DIR}/Library
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
#
# Lib and exe path
#
SET (LIBRARY_OUTPUT_PATH
${Complex_BINARY_DIR}/bin/ CACHE PATH
"Single output directory for building all libraries.")
......@@ -43,14 +56,8 @@ SET (EXECUTABLE_OUTPUT_PATH
"Single output directory for building all executables.")
#
# Where will executable tests be written ?
# Create the libs and the main exe
#
IF (EXECUTABLE_OUTPUT_PATH)
SET (CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
ELSE (EXECUTABLE_OUTPUT_PATH)
SET (CXX_TEST_PATH .)
ENDIF (EXECUTABLE_OUTPUT_PATH)
SUBDIRS(Library Executable)
SUBDIR_DEPENDS(Executable Library)
......@@ -68,30 +75,9 @@ ENDIF (NOT NO_EXEC_PROGRAM)
MARK_AS_ADVANCED(NO_EXEC_PROGRAM)
MARK_AS_ADVANCED(CLEAR NO_EXEC_PROGRAM)
#
# More coverage
#
ABSTRACT_FILES(
ExtraSources/file1.cxx
)
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
#
# Create directory.
# The 'complex' executable will then test if this dir exists,
# sadly it won't be able to remove it.
#
MAKE_DIRECTORY("${Complex_BINARY_DIR}/make_dir")
#
# Testing
#
ENABLE_TESTING()
#
# Test Cable
#
CABLE_CLASS_SET(Float float)
CABLE_CLASS_SET(Mesh "itk::Mesh<$Float>")
#
# Create exe.
#
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex CMakeTestLibrary)
TARGET_LINK_LIBRARIES(complex CMakeTestLibraryShared)
#
# Link to CMake lib
#
FIND_LIBRARY(CMAKE_LIB
CMakeLib
${Complex_BINARY_DIR}/../../Source
......@@ -12,15 +18,11 @@ FIND_LIBRARY(CMAKE_LIB
${Complex_BINARY_DIR}/../../Source/RelWithDebInfo)
TARGET_LINK_LIBRARIES(complex ${CMAKE_LIB})
LINK_LIBRARIES(${CMAKE_LIB})
#
# Testing
#
ADD_TEST(complex ${Complex_BINARY_DIR}/bin/complex)
#
# More coverage
# Extra coverage.Not used.
#
INSTALL_TARGETS(/tmp complex)
INSTALL_PROGRAMS(/tmp complex)
SOURCE_GROUP(A_GROUP ".cxx")
......@@ -8,18 +8,24 @@
int passed = 0;
int failed = 0;
// ======================================================================
void Failed(const char* Message, const char* m2= "")
{
std::cerr << "Failed: " << Message << m2 << "\n";
failed++;
}
// ======================================================================
void Passed(const char* Message, const char* m2="")
{
std::cout << "Passed: " << Message << m2 << "\n";
passed++;
}
// ======================================================================
void TestAndRemoveFile(const char* filename)
{
if (!cmSystemTools::FileExists(filename))
......@@ -39,6 +45,8 @@ void TestAndRemoveFile(const char* filename)
}
}
// ======================================================================
void TestDir(const char* filename)
{
if (!cmSystemTools::FileExists(filename))
......@@ -58,6 +66,7 @@ void TestDir(const char* filename)
}
}
// ======================================================================
int main()
{
......@@ -88,12 +97,18 @@ int main()
Passed("Call to file2 function returned 1.");
}
// ----------------------------------------------------------------------
// Test ADD_DEFINITIONS
#ifndef CMAKE_IS_FUN
Failed("CMake is not fun, so it is broken and should be fixed.");
#else
Passed("CMAKE_IS_FUN is defined.");
#endif
// ----------------------------------------------------------------------
// Test SET, VARIABLE_REQUIRES
#ifdef SHOULD_NOT_BE_DEFINED
Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
#else
......@@ -106,6 +121,42 @@ int main()
Passed("SHOULD_BE_DEFINED is defined.");
#endif
#ifndef ONE_VAR
Failed("cmakedefine is broken, ONE_VAR is not defined.");
#else
Passed("ONE_VAR is defined.");
#endif
#ifndef ONE_VAR_IS_DEFINED
Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
"ONE_VAR_IS_DEFINED is not defined.");
#else
Passed("ONE_VAR_IS_DEFINED is defined.");
#endif
#ifdef ZERO_VAR
Failed("cmakedefine is broken, ZERO_VAR is defined.");
#else
Passed("ZERO_VAR is not defined.");
#endif
#ifndef STRING_VAR
Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
#else
if(strcmp(STRING_VAR, "CMake is great") != 0)
{
Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
STRING_VAR);
}
else
{
Passed("STRING_VAR == ", STRING_VAR);
}
#endif
// ----------------------------------------------------------------------
// Test various IF/ELSE combinations
#ifdef SHOULD_NOT_BE_DEFINED_AND
Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
#else
......@@ -142,38 +193,8 @@ int main()
Passed("SHOULD_BE_DEFINED_MATCHES is defined.");
#endif
#ifndef ONE_VAR
Failed("cmakedefine is broken, ONE_VAR is not defined.");
#else
Passed("ONE_VAR is defined.");
#endif
#ifndef ONE_VAR_IS_DEFINED
Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
"ONE_VAR_IS_DEFINED is not defined.");
#else
Passed("ONE_VAR_IS_DEFINED is defined.");
#endif
#ifdef ZERO_VAR
Failed("cmakedefine is broken, ZERO_VAR is defined.");
#else
Passed("ZERO_VAR is not defined.");
#endif
#ifndef STRING_VAR
Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
#else
if(strcmp(STRING_VAR, "CMake is great") != 0)
{
Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
STRING_VAR);
}
else
{
Passed("STRING_VAR == ", STRING_VAR);
}
#endif
// ----------------------------------------------------------------------
// Test FOREACH
#ifndef FOREACH_VAR1
Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
......@@ -205,6 +226,9 @@ int main()
}
#endif
// ----------------------------------------------------------------------
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
#ifndef FILENAME_VAR_PATH_NAME
Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
"FILENAME_VAR_PATH_NAME is not defined.");
......@@ -280,6 +304,9 @@ int main()
}
#endif
// ----------------------------------------------------------------------
// Test LOAD_CACHE
#ifndef CACHE_TEST_VAR1
Failed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
"CACHE_TEST_VAR1 is not defined.");
......@@ -325,22 +352,26 @@ int main()
}
#endif
// ----------------------------------------------------------------------
// A post-build custom-command has been attached to the lib (see Library/).
// It run ${CREATE_FILE_EXE} which will create the file
// ${Complex_BINARY_DIR}/Library/postbuild.txt.
// It runs ${CREATE_FILE_EXE} which will create a file.
TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
// ----------------------------------------------------------------------
// A custom target has been created (see Library/).
// It run ${CREATE_FILE_EXE} which will create the file
// ${Complex_BINARY_DIR}/Library/custom_target1.txt.
// It runs ${CREATE_FILE_EXE} which will create a file.
TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
// ----------------------------------------------------------------------
// A directory has been created.
TestDir(BINARY_DIR "/make_dir");
// ----------------------------------------------------------------------
// Summary
std::cout << "Passed: " << passed << "\n";
if(failed)
{
......
AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
#
# Small utility used to create file
# UTILITY_SOURCE is used for coverage and for getting the exact name
# of the executable.
#
UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
ADD_EXECUTABLE(create_file create_file.cxx)
#
# Create static library
# SOURCE_FILES_REMOVE is used for Coverage
SOURCE_FILES(LibrarySources file2 GENERATED nonexisting_file)
SOURCE_FILES_REMOVE(LibrarySources GENERATED nonexisting_file)
#
AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
SOURCE_FILES(LibrarySources file2 create_file.cxx GENERATED nonexisting_file)
SOURCE_FILES_REMOVE(LibrarySources create_file.cxx GENERATED nonexisting_file)
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
SOURCE_FILES(SharedLibrarySources sharedFile)
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
#
# Small utility used to create file
# Create shared library
#
UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
ADD_EXECUTABLE(create_file create_file.cxx)
SOURCE_FILES(SharedLibrarySources sharedFile)
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
#
# Attach a post-build custom-command to the lib.
# It run ${CREATE_FILE_EXE} which will create the file
# ${Complex_BINARY_DIR}/Library/postbuild.txt.
# The 'complex' executable will then test if this file exists,
# and remove it.
# It runs ${CREATE_FILE_EXE} which will create a file.
# The 'complex' executable will then test if this file exists and remove it.
#
ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
......@@ -29,11 +34,10 @@ ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared
TARGET CMakeTestLibraryShared)
#
# Add custom target
# It run ${CREATE_FILE_EXE} which will create the file
# ${Complex_BINARY_DIR}/Library/custom_target1.txt.
# The 'complex' executable will then test if this file exists,
# and remove it.
# Add a custom target.
# It runs ${CREATE_FILE_EXE} which will create the file
# It runs ${CREATE_FILE_EXE} which will create a file.
# The 'complex' executable will then test if this file exists and remove it.
#
ADD_CUSTOM_TARGET(custom_target1
ALL
......@@ -42,6 +46,12 @@ ADD_CUSTOM_TARGET(custom_target1
ADD_DEPENDENCIES(custom_target1 create_file)
# More coverage
#
# Extra coverage
#
ABSTRACT_FILES(
ExtraSources/file1.cxx
)
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
SOURCE_GROUP(A_GROUP ".cxx")
#
# Test SET
#
SET (ZERO_VAR 0)
IF(ZERO_VAR)
......@@ -7,12 +10,18 @@ ELSE(ZERO_VAR)
ENDIF(ZERO_VAR)
SET(ONE_VAR 1)
SET(ONE_VAR2 1)
SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
#
# Test VARIABLE_REQUIRES
#
VARIABLE_REQUIRES(ONE_VAR
ONE_VAR_IS_DEFINED ONE_VAR)
SET (ONE_VAR2 1)
#
# Test various IF/ELSE combinations
#
IF(ONE_VAR AND ONE_VAR2)
ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_AND)
ELSE(ONE_VAR AND ONE_VAR2)
......@@ -25,32 +34,29 @@ ELSE(ZERO_VAR OR ONE_VAR2)
ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_OR)
ENDIF(ZERO_VAR OR ONE_VAR2)
SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
IF(STRING_VAR MATCHES "^CMake")
ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_MATCHES)
ELSE(STRING_VAR MATCHES "^CMake")
ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_MATCHES)
ENDIF(STRING_VAR MATCHES "^CMake")
#
# Test FOREACH
#
FOREACH (INDEX 1 2)
SET(FOREACH_VAR${INDEX} "VALUE${INDEX}")
ENDFOREACH(INDEX)
#
# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
#
FIND_FILE(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR})
GET_FILENAME_COMPONENT(FILENAME_VAR_PATH ${FILENAME_VAR} PATH)
GET_FILENAME_COMPONENT(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME)
GET_FILENAME_COMPONENT(FILENAME_VAR_NAME ${FILENAME_VAR} NAME)
GET_FILENAME_COMPONENT(FILENAME_VAR_EXT ${FILENAME_VAR} EXT)
GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE)
GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE)
FIND_PATH(PATH_VAR "VarTests.cmake" ${Complex_SOURCE_DIR})
GET_FILENAME_COMPONENT(PATH_VAR_NAME ${PATH_VAR} NAME)
# Coverage only
BUILD_COMMAND(BUILD_COMMAND_VAR ${CMAKE_MAKE_PROGRAM})
BUILD_NAME(BUILD_NAME_VAR)
SITE_NAME(SITE_NAME_VAR)
// Test SET, VARIABLE_REQUIRES
#cmakedefine ONE_VAR
#cmakedefine ONE_VAR_IS_DEFINED
#cmakedefine ZERO_VAR
#define STRING_VAR "${STRING_VAR}"
// Test FOREACH
#define FOREACH_VAR1 "${FOREACH_VAR1}"
#define FOREACH_VAR2 "${FOREACH_VAR2}"
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}"
#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}"
#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}"
......@@ -14,20 +20,18 @@
#define PATH_VAR_NAME "${PATH_VAR_NAME}"
#cmakedefine CMAKE_NO_STD_NAMESPACE
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
// Test LOAD_CACHE
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
#define CACHE_TEST_VAR2 "${CACHE_TEST_VAR2}"
#define CACHE_TEST_VAR3 "${CACHE_TEST_VAR3}"
// Needed to check for files
// Test internal CMake vars from C++ flags
#define BINARY_DIR "${Complex_BINARY_DIR}"
#cmakedefine CMAKE_NO_STD_NAMESPACE
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
// Coverage only
// Needed to check for files
#define BUILD_COMMAND_VAR "${BUILD_COMMAND_VAR}"
#define BUILD_NAME_VAR "${BUILD_NAME_VAR}"
#define SITE_NAME_VAR "${SITE_NAME_VAR}"
#define BINARY_DIR "${Complex_BINARY_DIR}"
......@@ -12,28 +12,41 @@ ENDIF (CMAKE_ANSI_CXXFLAGS)
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
#
# Include vars from a file and from a cache
#
IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
INCLUDE(${Complex_SOURCE_DIR}/VarTests.cmake)
ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
LOAD_CACHE(${Complex_SOURCE_DIR})
#
# Configure file
# (plug vars to #define so that they can be tested)
#
CONFIGURE_FILE(
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
${Complex_BINARY_DIR}/cmTestConfigure.h)
#
# Specify include and lib dirs
#
INCLUDE_DIRECTORIES(
${Complex_BINARY_DIR}
${Complex_SOURCE_DIR}/Library
${Complex_SOURCE_DIR}/../../Source
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
LINK_DIRECTORIES(
${Complex_BINARY_DIR}/Library
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
#
# Lib and exe path
#
SET (LIBRARY_OUTPUT_PATH
${Complex_BINARY_DIR}/bin/ CACHE PATH
"Single output directory for building all libraries.")
......@@ -43,14 +56,8 @@ SET (EXECUTABLE_OUTPUT_PATH
"Single output directory for building all executables.")
#
# Where will executable tests be written ?
# Create the libs and the main exe
#
IF (EXECUTABLE_OUTPUT_PATH)
SET (CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
ELSE (EXECUTABLE_OUTPUT_PATH)
SET (CXX_TEST_PATH .)
ENDIF (EXECUTABLE_OUTPUT_PATH)
SUBDIRS(Library Executable)
SUBDIR_DEPENDS(Executable Library)
......@@ -68,30 +75,9 @@ ENDIF (NOT NO_EXEC_PROGRAM)
MARK_AS_ADVANCED(NO_EXEC_PROGRAM)
MARK_AS_ADVANCED(CLEAR NO_EXEC_PROGRAM)
#
# More coverage
#
ABSTRACT_FILES(
ExtraSources/file1.cxx
)
INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
#
# Create directory.
# The 'complex' executable will then test if this dir exists,
# sadly it won't be able to remove it.
#
MAKE_DIRECTORY("${Complex_BINARY_DIR}/make_dir")
#
# Testing
#
ENABLE_TESTING()
#
# Test Cable
#
CABLE_CLASS_SET(Float float)
CABLE_CLASS_SET(Mesh "itk::Mesh<$Float>")
#
# Create exe.
#
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex CMakeTestLibrary)
TARGET_LINK_LIBRARIES(complex CMakeTestLibraryShared)
#
# Link to CMake lib
#
FIND_LIBRARY(CMAKE_LIB
CMakeLib
${Complex_BINARY_DIR}/../../Source
......@@ -12,15 +18,11 @@ FIND_LIBRARY(CMAKE_LIB
${Complex_BINARY_DIR}/../../Source/RelWithDebInfo)
TARGET_LINK_LIBRARIES(complex ${CMAKE_LIB})
LINK_LIBRARIES(${CMAKE_LIB})
#
# Testing
#
ADD_TEST(complex ${Complex_BINARY_DIR}/bin/complex)
#
# More coverage
# Extra coverage.Not used.
#
INSTALL_TARGETS(/tmp complex)
INSTALL_PROGRAMS(/tmp complex)
SOURCE_GROUP(A_GROUP ".cxx")
......@@ -8,18 +8,24 @@
int passed = 0;
int failed = 0;
// ======================================================================
void Failed(const char* Message, const char* m2= "")
{