ENH: tests ADD_DEPENDENCIES and ADD_CUSTOM_COMMAND
This commit is contained in:
parent
201764e166
commit
e8c4fbef82
|
@ -1,31 +1,53 @@
|
|||
# a simple test case
|
||||
#
|
||||
# A simple test case
|
||||
#
|
||||
PROJECT (Complex)
|
||||
|
||||
# use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
# Use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
IF (CMAKE_ANSI_CXXFLAGS)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
|
||||
ENDIF (CMAKE_ANSI_CXXFLAGS)
|
||||
|
||||
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
|
||||
SUBDIRS(Library Executable)
|
||||
SUBDIR_DEPENDS(Executable Library)
|
||||
|
||||
INCLUDE(${Complex_SOURCE_DIR}/VarTests.txt)
|
||||
|
||||
CONFIGURE_FILE(
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}/Library
|
||||
${Complex_BINARY_DIR}/Library
|
||||
)
|
||||
|
||||
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
|
||||
|
||||
SET (LIBRARY_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all libraries.")
|
||||
SET (EXECUTABLE_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all executables.")
|
||||
SET (LIBRARY_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all libraries.")
|
||||
|
||||
SET (EXECUTABLE_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all executables.")
|
||||
|
||||
#
|
||||
# Where will executable tests be written ?
|
||||
#
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
#include "file2.h"
|
||||
#include "sharedFile.h"
|
||||
#include "cmStandardIncludes.h"
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#define _unlink unlink
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
@ -38,6 +49,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file1 function returned 1.");
|
||||
}
|
||||
|
||||
if(file2() != 1)
|
||||
{
|
||||
Failed("Call to file2 function from library failed.");
|
||||
|
@ -46,6 +58,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file2 function returned 1.");
|
||||
}
|
||||
|
||||
#ifndef CMAKE_IS_FUN
|
||||
Failed("CMake is not fun, so it is broken and should be fixed.");
|
||||
#else
|
||||
|
@ -76,8 +89,6 @@ int main()
|
|||
Passed("ZERO_VAR is not defined.");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef STRING_VAR
|
||||
Failed("configureFile is broken, STRING_VAR is not defined.");
|
||||
#else
|
||||
|
@ -92,13 +103,32 @@ int main()
|
|||
Passed("STRING_VAR == ", STRING_VAR);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Attach a post-build custom-command to the lib.
|
||||
// It run ${CREATE_FILE_EXE} which will create the file
|
||||
// ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
// The 'complex' executable will then test if this file exists,
|
||||
// and remove it.
|
||||
|
||||
struct stat fs;
|
||||
if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0)
|
||||
{
|
||||
Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib).");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unlink(BINARY_DIR "/postbuild.txt") != 0)
|
||||
{
|
||||
Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed).");
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Passed:" << passed << "\n";
|
||||
if(failed)
|
||||
{
|
||||
std::cout << "Failed: " << failed << "\n";
|
||||
return failed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,23 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
|
|||
|
||||
SOURCE_FILES(LibrarySources file2)
|
||||
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
|
||||
|
||||
SOURCE_FILES(SharedLibrarySources sharedFile)
|
||||
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
|
||||
|
||||
UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
|
||||
ADD_EXECUTABLE(create_file create_file.cxx)
|
||||
|
||||
ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
|
||||
|
||||
# Attach a post-build custom-command to the lib.
|
||||
# It run ${CREATE_FILE_EXE} which will create the file
|
||||
# ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
# The 'complex' executable will then test if this file exists,
|
||||
# and remove it.
|
||||
|
||||
ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared
|
||||
COMMAND ${CREATE_FILE_EXE}
|
||||
ARGS "${Complex_BINARY_DIR}/postbuild.txt"
|
||||
TARGET CMakeTestLibraryShared)
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Missing name of file to create.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
FILE *stream = fopen(argv[1], "w");
|
||||
if(stream == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(fclose(stream))
|
||||
{
|
||||
fprintf(stderr, "Unable to close %s!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Creating %s!\n", argv[1]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#cmakedefine ZERO_VAR
|
||||
#define STRING_VAR "${STRING_VAR}"
|
||||
|
||||
#define BINARY_DIR "${Complex_BINARY_DIR}"
|
||||
|
||||
#cmakedefine CMAKE_NO_STD_NAMESPACE
|
||||
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
|
||||
|
|
|
@ -1,31 +1,53 @@
|
|||
# a simple test case
|
||||
#
|
||||
# A simple test case
|
||||
#
|
||||
PROJECT (Complex)
|
||||
|
||||
# use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
# Use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
IF (CMAKE_ANSI_CXXFLAGS)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
|
||||
ENDIF (CMAKE_ANSI_CXXFLAGS)
|
||||
|
||||
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
|
||||
SUBDIRS(Library Executable)
|
||||
SUBDIR_DEPENDS(Executable Library)
|
||||
|
||||
INCLUDE(${Complex_SOURCE_DIR}/VarTests.txt)
|
||||
|
||||
CONFIGURE_FILE(
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}/Library
|
||||
${Complex_BINARY_DIR}/Library
|
||||
)
|
||||
|
||||
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
|
||||
|
||||
SET (LIBRARY_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all libraries.")
|
||||
SET (EXECUTABLE_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all executables.")
|
||||
SET (LIBRARY_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all libraries.")
|
||||
|
||||
SET (EXECUTABLE_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all executables.")
|
||||
|
||||
#
|
||||
# Where will executable tests be written ?
|
||||
#
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
#include "file2.h"
|
||||
#include "sharedFile.h"
|
||||
#include "cmStandardIncludes.h"
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#define _unlink unlink
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
@ -38,6 +49,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file1 function returned 1.");
|
||||
}
|
||||
|
||||
if(file2() != 1)
|
||||
{
|
||||
Failed("Call to file2 function from library failed.");
|
||||
|
@ -46,6 +58,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file2 function returned 1.");
|
||||
}
|
||||
|
||||
#ifndef CMAKE_IS_FUN
|
||||
Failed("CMake is not fun, so it is broken and should be fixed.");
|
||||
#else
|
||||
|
@ -76,8 +89,6 @@ int main()
|
|||
Passed("ZERO_VAR is not defined.");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef STRING_VAR
|
||||
Failed("configureFile is broken, STRING_VAR is not defined.");
|
||||
#else
|
||||
|
@ -92,13 +103,32 @@ int main()
|
|||
Passed("STRING_VAR == ", STRING_VAR);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Attach a post-build custom-command to the lib.
|
||||
// It run ${CREATE_FILE_EXE} which will create the file
|
||||
// ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
// The 'complex' executable will then test if this file exists,
|
||||
// and remove it.
|
||||
|
||||
struct stat fs;
|
||||
if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0)
|
||||
{
|
||||
Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib).");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unlink(BINARY_DIR "/postbuild.txt") != 0)
|
||||
{
|
||||
Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed).");
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Passed:" << passed << "\n";
|
||||
if(failed)
|
||||
{
|
||||
std::cout << "Failed: " << failed << "\n";
|
||||
return failed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,23 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
|
|||
|
||||
SOURCE_FILES(LibrarySources file2)
|
||||
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
|
||||
|
||||
SOURCE_FILES(SharedLibrarySources sharedFile)
|
||||
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
|
||||
|
||||
UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
|
||||
ADD_EXECUTABLE(create_file create_file.cxx)
|
||||
|
||||
ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
|
||||
|
||||
# Attach a post-build custom-command to the lib.
|
||||
# It run ${CREATE_FILE_EXE} which will create the file
|
||||
# ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
# The 'complex' executable will then test if this file exists,
|
||||
# and remove it.
|
||||
|
||||
ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared
|
||||
COMMAND ${CREATE_FILE_EXE}
|
||||
ARGS "${Complex_BINARY_DIR}/postbuild.txt"
|
||||
TARGET CMakeTestLibraryShared)
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Missing name of file to create.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
FILE *stream = fopen(argv[1], "w");
|
||||
if(stream == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(fclose(stream))
|
||||
{
|
||||
fprintf(stderr, "Unable to close %s!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Creating %s!\n", argv[1]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#cmakedefine ZERO_VAR
|
||||
#define STRING_VAR "${STRING_VAR}"
|
||||
|
||||
#define BINARY_DIR "${Complex_BINARY_DIR}"
|
||||
|
||||
#cmakedefine CMAKE_NO_STD_NAMESPACE
|
||||
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
|
||||
|
|
|
@ -1,31 +1,53 @@
|
|||
# a simple test case
|
||||
#
|
||||
# A simple test case
|
||||
#
|
||||
PROJECT (Complex)
|
||||
|
||||
# use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
# Use the ansi CXX compile flag for building cmake
|
||||
#
|
||||
IF (CMAKE_ANSI_CXXFLAGS)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
|
||||
ENDIF (CMAKE_ANSI_CXXFLAGS)
|
||||
|
||||
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
|
||||
SUBDIRS(Library Executable)
|
||||
SUBDIR_DEPENDS(Executable Library)
|
||||
|
||||
INCLUDE(${Complex_SOURCE_DIR}/VarTests.txt)
|
||||
|
||||
CONFIGURE_FILE(
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
|
||||
${Complex_BINARY_DIR}/cmTestConfigure.h)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
${Complex_BINARY_DIR}
|
||||
${Complex_SOURCE_DIR}/Library
|
||||
${Complex_SOURCE_DIR}/../../Source
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
${Complex_BINARY_DIR}/Library
|
||||
${Complex_BINARY_DIR}/Library
|
||||
)
|
||||
|
||||
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
|
||||
|
||||
SET (LIBRARY_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all libraries.")
|
||||
SET (EXECUTABLE_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all executables.")
|
||||
SET (LIBRARY_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all libraries.")
|
||||
|
||||
SET (EXECUTABLE_OUTPUT_PATH
|
||||
${Complex_BINARY_DIR}/bin/ CACHE PATH
|
||||
"Single output directory for building all executables.")
|
||||
|
||||
#
|
||||
# Where will executable tests be written ?
|
||||
#
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
#include "file2.h"
|
||||
#include "sharedFile.h"
|
||||
#include "cmStandardIncludes.h"
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#define _unlink unlink
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
@ -38,6 +49,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file1 function returned 1.");
|
||||
}
|
||||
|
||||
if(file2() != 1)
|
||||
{
|
||||
Failed("Call to file2 function from library failed.");
|
||||
|
@ -46,6 +58,7 @@ int main()
|
|||
{
|
||||
Passed("Call to file2 function returned 1.");
|
||||
}
|
||||
|
||||
#ifndef CMAKE_IS_FUN
|
||||
Failed("CMake is not fun, so it is broken and should be fixed.");
|
||||
#else
|
||||
|
@ -76,8 +89,6 @@ int main()
|
|||
Passed("ZERO_VAR is not defined.");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef STRING_VAR
|
||||
Failed("configureFile is broken, STRING_VAR is not defined.");
|
||||
#else
|
||||
|
@ -92,13 +103,32 @@ int main()
|
|||
Passed("STRING_VAR == ", STRING_VAR);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Attach a post-build custom-command to the lib.
|
||||
// It run ${CREATE_FILE_EXE} which will create the file
|
||||
// ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
// The 'complex' executable will then test if this file exists,
|
||||
// and remove it.
|
||||
|
||||
struct stat fs;
|
||||
if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0)
|
||||
{
|
||||
Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib).");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unlink(BINARY_DIR "/postbuild.txt") != 0)
|
||||
{
|
||||
Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed).");
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Passed:" << passed << "\n";
|
||||
if(failed)
|
||||
{
|
||||
std::cout << "Failed: " << failed << "\n";
|
||||
return failed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,23 @@ AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
|
|||
|
||||
SOURCE_FILES(LibrarySources file2)
|
||||
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
|
||||
|
||||
SOURCE_FILES(SharedLibrarySources sharedFile)
|
||||
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
|
||||
|
||||
UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx)
|
||||
ADD_EXECUTABLE(create_file create_file.cxx)
|
||||
|
||||
ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
|
||||
|
||||
# Attach a post-build custom-command to the lib.
|
||||
# It run ${CREATE_FILE_EXE} which will create the file
|
||||
# ${Complex_BINARY_DIR}/postbuild.txt.
|
||||
# The 'complex' executable will then test if this file exists,
|
||||
# and remove it.
|
||||
|
||||
ADD_CUSTOM_COMMAND(SOURCE CMakeTestLibraryShared
|
||||
COMMAND ${CREATE_FILE_EXE}
|
||||
ARGS "${Complex_BINARY_DIR}/postbuild.txt"
|
||||
TARGET CMakeTestLibraryShared)
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Missing name of file to create.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
FILE *stream = fopen(argv[1], "w");
|
||||
if(stream == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to open %s for writing!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(fclose(stream))
|
||||
{
|
||||
fprintf(stderr, "Unable to close %s!\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Creating %s!\n", argv[1]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#cmakedefine ZERO_VAR
|
||||
#define STRING_VAR "${STRING_VAR}"
|
||||
|
||||
#define BINARY_DIR "${Complex_BINARY_DIR}"
|
||||
|
||||
#cmakedefine CMAKE_NO_STD_NAMESPACE
|
||||
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
|
||||
|
|
Loading…
Reference in New Issue