diff options
Diffstat (limited to 'Tests/LoadCommandOneConfig')
-rw-r--r-- | Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt | 17 | ||||
-rw-r--r-- | Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c | 219 | ||||
-rw-r--r-- | Tests/LoadCommandOneConfig/CMakeLists.txt | 69 | ||||
-rw-r--r-- | Tests/LoadCommandOneConfig/LoadedCommand.cxx.in | 41 | ||||
-rw-r--r-- | Tests/LoadCommandOneConfig/LoadedCommand.h.in | 13 |
5 files changed, 359 insertions, 0 deletions
diff --git a/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt b/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt new file mode 100644 index 0000000..953d05c --- /dev/null +++ b/Tests/LoadCommandOneConfig/CMakeCommands/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 2.6) +PROJECT(CMAKE_LOADED_COMMANDS) + +IF (MUDSLIDE_TYPE MATCHES MUCHO) + ADD_DEFINITIONS(-DMUCHO_MUDSLIDE) +ENDIF (MUDSLIDE_TYPE MATCHES MUCHO) + +IF(WATCOM) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +ENDIF(WATCOM) +INCLUDE_DIRECTORIES(${CMAKE_ROOT}/include ${CMAKE_ROOT}/Source) + +ADD_LIBRARY(cmCMAKE_TEST_COMMAND MODULE cmTestCommand.c) + +IF(WATCOM) + TARGET_LINK_LIBRARIES(cmCMAKE_TEST_COMMAND clbsdll.lib) +ENDIF(WATCOM) diff --git a/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c b/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c new file mode 100644 index 0000000..6b4f48f --- /dev/null +++ b/Tests/LoadCommandOneConfig/CMakeCommands/cmTestCommand.c @@ -0,0 +1,219 @@ +#include "cmCPluginAPI.h" +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +typedef struct +{ + char *LibraryName; + int Argc; + char** Argv; +} cmVTKWrapTclData; + +/* do almost everything in the initial pass */ +static int CCONV InitialPass(void *inf, void *mf, int argc, char *argv[]) +{ + char* file; + char* str; + char *srcs; + const char* cstr; + char buffer[1024]; + void *source_file; + char *args[2]; + char *ccArgs[4]; + char *ccDep[1]; + char *ccOut[1]; + cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf; + + cmVTKWrapTclData *cdata = + (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData)); + cdata->LibraryName = "BOO"; + cdata->Argc = argc; + cdata->Argv = argv; + info->CAPI->SetClientData(info,cdata); + + /* Now check and see if the value has been stored in the cache */ + /* already, if so use that value and don't look for the program */ + if(!info->CAPI->IsOn(mf,"TEST_COMMAND_TEST1")) + { + info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO"); + return 1; + } + + info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO"); + cdata->LibraryName = "HOO"; + + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON", + "Test cache variable", + CM_CACHE_BOOL); + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "", + "Test cache variable 1", + CM_CACHE_PATH); + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "", + "Test cache variable 2", + CM_CACHE_FILEPATH); + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "", + "Test cache variable 3", + CM_CACHE_STRING); + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "", + "Test cache variable 4", + CM_CACHE_INTERNAL); + info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "", + "Test cache variable 5", + CM_CACHE_STATIC); + + + file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0); + + str = info->CAPI->GetFilenameWithoutExtension(file); + info->CAPI->DisplaySatus(mf, str); + info->CAPI->Free(str); + str = info->CAPI->GetFilenamePath(file); + info->CAPI->DisplaySatus(mf, str); + info->CAPI->Free(str); + str = info->CAPI->Capitalized("cmake"); + info->CAPI->DisplaySatus(mf, str); + info->CAPI->Free(str); + + info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf)); + info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf)); + sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d", + info->CAPI->GetCacheMajorVersion(mf), + info->CAPI->GetCacheMinorVersion(mf), + info->CAPI->GetMajorVersion(mf), + info->CAPI->GetMinorVersion(mf)); + info->CAPI->DisplaySatus(mf, buffer); + if ( info->CAPI->CommandExists(mf, "SET") ) + { + info->CAPI->DisplaySatus(mf, "Command SET exists"); + } + if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") ) + { + info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists"); + return 0; + } + info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION"); + + source_file = info->CAPI->CreateNewSourceFile(mf); + cstr = info->CAPI->SourceFileGetSourceName(source_file); + sprintf(buffer, "Shold be empty (source file name): [%s]", cstr); + info->CAPI->DisplaySatus(mf, buffer); + cstr = info->CAPI->SourceFileGetFullPath(source_file); + sprintf(buffer, "Should be empty (source file full path): [%s]", cstr); + info->CAPI->DisplaySatus(mf, buffer); + info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY","unused old prop", + "This property is no longer used", + 0); + if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") ) + { + info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined"); + return 0; + } + info->CAPI->DefineSourceFileProperty(mf,"SOME_PROPERTY2","nice prop", + "This property is for testing.", + 0); + info->CAPI->SourceFileSetProperty(source_file, "SOME_PROPERTY2", "HERE"); + cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT"); + sprintf(buffer, "Should be 0 (source file abstract property): [%p]", cstr); + info->CAPI->DisplaySatus(mf, buffer); + + info->CAPI->DestroySourceFile(source_file); + + srcs = argv[2]; + info->CAPI->AddExecutable(mf,"LoadedCommand",1, &srcs, 0); + + /* add customs commands to generate the source file */ + ccArgs[0] = "-E"; + ccArgs[1] = "copy"; + ccArgs[2] = argv[0]; + ccArgs[3] = argv[1]; + ccDep[0] = ccArgs[2]; + ccOut[0] = ccArgs[3]; + info->CAPI->AddCustomCommand(mf, "LoadedCommand.cxx.in", + file, + 4, ccArgs, + 1, ccDep, + 1, ccOut, + "LoadedCommand"); + + + ccArgs[2] = argv[1]; + ccArgs[3] = argv[2]; + ccDep[0] = ccArgs[2]; + ccOut[0] = ccArgs[3]; + info->CAPI->AddCustomCommandToOutput(mf, ccOut[0], + file, + 4, ccArgs, + ccDep[0], + 0, 0); + + + ccArgs[1] = "echo"; + ccArgs[2] = "Build has finished"; + info->CAPI->AddCustomCommandToTarget(mf, "LoadedCommand", + file, + 3, ccArgs, + CM_POST_BUILD); + + info->CAPI->Free(file); + + args[0] = "TEST_EXEC"; + args[1] = "TRUE"; + + /* code coverage */ + if (info->CAPI->GetTotalArgumentSize(2,args) != 13) + { + return 0; + } + info->CAPI->ExecuteCommand(mf,"SET",2,args); + + /* make sure we can find the source file */ + if (!info->CAPI->GetSource(mf,argv[1])) + { + info->CAPI->SetError(mf, "Source file could not be found!"); + return 0; + } + + return 1; +} + +static void CCONV FinalPass(void *inf, void *mf) +{ + cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf; + /* get our client data from initial pass */ + cmVTKWrapTclData *cdata = + (cmVTKWrapTclData *)info->CAPI->GetClientData(info); + if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") || + strcmp(cdata->LibraryName,"HOO")) + { + fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n"); + } +} +static void CCONV Destructor(void *inf) +{ + cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf; + /* get our client data from initial pass */ + cmVTKWrapTclData *cdata = + (cmVTKWrapTclData *)info->CAPI->GetClientData(info); + free(cdata); +} + +#ifdef MUCHO_MUDSLIDE +void CM_PLUGIN_EXPORT CCONV CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info) +{ + info->InitialPass = InitialPass; + info->FinalPass = FinalPass; + info->Destructor = Destructor; + info->m_Inherited = 0; + info->Name = "CMAKE_TEST_COMMAND"; +} +#endif + + + + diff --git a/Tests/LoadCommandOneConfig/CMakeLists.txt b/Tests/LoadCommandOneConfig/CMakeLists.txt new file mode 100644 index 0000000..e99105a --- /dev/null +++ b/Tests/LoadCommandOneConfig/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required (VERSION 2.6) +PROJECT(LoadCommand) + +# set a definition +SET (TEST_COMMAND_TEST1 1) + +INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake) +CHECK_TYPE_SIZE(char SIZEOF_CHAR) +CHECK_TYPE_SIZE(short SIZEOF_SHORT) + +INCLUDE (CheckFunctionExists) +CHECK_FUNCTION_EXISTS(printf HAVE_PRINTF) +CHECK_FUNCTION_EXISTS(vsblabla HAVE_VSBLABLA) + +INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) +CHECK_INCLUDE_FILE("sys/prctl.h" HAVE_SYS_PRCTL_H) + +INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake) +CHECK_LIBRARY_EXISTS(m ceil "" HAVE_LIBM) + +CONFIGURE_FILE(${LoadCommand_SOURCE_DIR}/LoadedCommand.h.in + ${LoadCommand_BINARY_DIR}/LoadedCommand.h) + +INCLUDE_DIRECTORIES(${LoadCommand_BINARY_DIR}) + +# try to compile the command +# make sure it is not already loaded +IF(COMMAND CMAKE_TEST_COMMAND) +ELSE(COMMAND CMAKE_TEST_COMMAND) + TRY_COMPILE(COMPILE_OK + ${LoadCommand_BINARY_DIR}/CMakeCommands + ${LoadCommand_SOURCE_DIR}/CMakeCommands + CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO + OUTPUT_VARIABLE OUTPUT ) +# do another TRY_COMPILE to get around make +# problem on hp + TRY_COMPILE(COMPILE_OK + ${LoadCommand_BINARY_DIR}/CMakeCommands + ${LoadCommand_SOURCE_DIR}/CMakeCommands + CMAKE_LOADED_COMMANDS CMAKE_FLAGS -DMUDSLIDE_TYPE:STRING=MUCHO + OUTPUT_VARIABLE OUTPUT ) +ENDIF(COMMAND CMAKE_TEST_COMMAND) + +MESSAGE("Output from try compile: ${OUTPUT}") + +# if the compile was OK, try loading the command +IF (COMPILE_OK) + LOAD_COMMAND(CMAKE_TEST_COMMAND + ${LoadCommand_BINARY_DIR}/CMakeCommands + ${LoadCommand_BINARY_DIR}/CMakeCommands/Debug + ${LoadCommand_BINARY_DIR}/CMakeCommands/Development + ) + # if the command loaded, execute the command + IF (COMMAND CMAKE_TEST_COMMAND) + CMAKE_TEST_COMMAND( + "${LoadCommand_SOURCE_DIR}/LoadedCommand.cxx.in" + "${LoadCommand_BINARY_DIR}/LoadedCommand2.cxx.in" + "${LoadCommand_BINARY_DIR}/LoadedCommand3.cxx" + ) + ENDIF (COMMAND CMAKE_TEST_COMMAND) +ELSE (COMPILE_OK) + MESSAGE("failed to compile CMAKE_LOADED_COMMANDS") +ENDIF (COMPILE_OK) + +# TEST_DEF is set by the loaded command cmTestCommand.c +IF (TEST_DEF AND SOME_CACHE_VARIABLE AND TEST_EXEC) + ADD_DEFINITIONS(-DCMAKE_IS_FUN) +ENDIF (TEST_DEF AND SOME_CACHE_VARIABLE AND TEST_EXEC) + diff --git a/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in b/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in new file mode 100644 index 0000000..c58bcf1 --- /dev/null +++ b/Tests/LoadCommandOneConfig/LoadedCommand.cxx.in @@ -0,0 +1,41 @@ +#include "LoadedCommand.h" +#include <stdio.h> + +int testSizeOf(int s1, int s2) +{ + return s1 - s2; +} + +int main () +{ + int ret = 0; +#ifdef HAVE_VSBLABLA + printf("Should not be able to find vsblabla\n"); + ret = 1; +#endif + +#if !defined( HAVE_PRINTF ) + printf("Should be able to find printf\n"); + ret= 1; +#endif + +#if !defined( ADDED_DEFINITION ) + printf("Should have ADDED_DEFINITION defined\n"); + ret= 1; +#endif +#if !defined(CMAKE_IS_FUN) + printf("Loaded Command was not built with CMAKE_IS_FUN: failed.\n"); + ret = 1; +#endif + if(testSizeOf(SIZEOF_CHAR, sizeof(char))) + { + printf("Size of char is broken.\n"); + ret = 1; + } + if(testSizeOf(SIZEOF_SHORT, sizeof(short))) + { + printf("Size of short is broken.\n"); + ret = 1; + } + return ret; +} diff --git a/Tests/LoadCommandOneConfig/LoadedCommand.h.in b/Tests/LoadCommandOneConfig/LoadedCommand.h.in new file mode 100644 index 0000000..7a0a15d --- /dev/null +++ b/Tests/LoadCommandOneConfig/LoadedCommand.h.in @@ -0,0 +1,13 @@ +/* Check for size of types */ +#cmakedefine SIZEOF_CHAR ${SIZEOF_CHAR} +#cmakedefine SIZEOF_SHORT ${SIZEOF_SHORT} + +/* Check for functions */ +#cmakedefine HAVE_PRINTF +#cmakedefine HAVE_VSBLABLA + +/* Check for headers */ +#cmakedefine HAVE_SYS_PRCTL_H + +/* Check for libraries */ +#cmakedefine HAVE_LIBM |