diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 36 | ||||
-rw-r--r-- | Tests/CMakeOnly/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/CMakeOnly/CheckLanguage/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/CMakeOnly/CheckOBJCXXCompilerFlag/CMakeLists.txt | 17 | ||||
-rw-r--r-- | Tests/CMakeOnly/CompilerIdOBJCXX/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/Objective-C++/cxx-file-extension-test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/Objective-C++/cxx-file-extension-test/main.mm | 8 | ||||
-rw-r--r-- | Tests/Objective-C++/objcxx-file-extension-test/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/Objective-C++/objcxx-file-extension-test/main.mm | 14 | ||||
-rw-r--r-- | Tests/Objective-C++/simple-build-test/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/Objective-C++/simple-build-test/foo.h | 9 | ||||
-rw-r--r-- | Tests/Objective-C++/simple-build-test/foo.mm | 7 | ||||
-rw-r--r-- | Tests/Objective-C++/simple-build-test/main.mm | 14 | ||||
-rw-r--r-- | Tests/TryCompile/CMakeLists.txt | 66 |
14 files changed, 195 insertions, 22 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 2e17e59..789fc0e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2365,6 +2365,42 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH ) list(APPEND TEST_BUILD_DIRS "${CMAKE_BINARY_DIR}/Tests/Objective-C/objc-file-extension-test") + add_test(Objective-CXX.simple-build-test ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/Objective-C++/simple-build-test" + "${CMake_BINARY_DIR}/Tests/Objective-C++/simple-build-test" + --build-two-config + ${build_generator_args} + --build-project simple-build-test + --build-options ${build_options} + --test-command simple-build-test + ) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Objective-C++/simple-build-test") + + add_test(Objective-CXX.cxx-file-extension-test ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/Objective-C++/cxx-file-extension-test" + "${CMake_BINARY_DIR}/Tests/Objective-C++/cxx-file-extension-test" + --build-two-config + ${build_generator_args} + --build-project cxx-file-extension-test + --build-options ${build_options} + --test-command cxx-file-extension-test + ) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Objective-C++/cxx-file-extension-test") + + add_test(Objective-CXX.objcxx-file-extension-test ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/Objective-C++/objcxx-file-extension-test" + "${CMake_BINARY_DIR}/Tests/Objective-C++/objcxx-file-extension-test" + --build-two-config + ${build_generator_args} + --build-project objcxx-file-extension-test + --build-options ${build_options} + --test-command objcxx-file-extension-test + ) + list(APPEND TEST_BUILD_DIRS "${CMAKE_BINARY_DIR}/Tests/Objective-C++/objcxx-file-extension-test") + endif () endif () diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt index 1a25469..03babd2 100644 --- a/Tests/CMakeOnly/CMakeLists.txt +++ b/Tests/CMakeOnly/CMakeLists.txt @@ -36,6 +36,11 @@ if(CMAKE_OBJC_COMPILER) add_CMakeOnly_test(CheckOBJCCompilerFlag) endif() +if(CMAKE_OBJCXX_COMPILER) + add_CMakeOnly_test(CompilerIdOBJCXX) + add_CMakeOnly_test(CheckOBJCXXCompilerFlag) +endif() + if(CMAKE_Fortran_COMPILER) add_CMakeOnly_test(CompilerIdFortran) endif() diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt index e9bdf6a..90aa921 100644 --- a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt @@ -5,16 +5,17 @@ include(CheckLanguage) set(langs ) set(expect_C 1) set(expect_CXX 1) + if(APPLE) set(expect_OBJC 1) + set(expect_OBJCXX 1) endif() unset(expect_Fortran) set(expect_NoSuchLanguage 0) set(LANGUAGES C CXX Fortran CUDA NoSuchLanguage) - if(APPLE) - list(APPEND LANGUAGES OBJC) + list(APPEND LANGUAGES OBJC OBJCXX) endif() foreach(lang ${LANGUAGES}) diff --git a/Tests/CMakeOnly/CheckOBJCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckOBJCXXCompilerFlag/CMakeLists.txt new file mode 100644 index 0000000..f83b738 --- /dev/null +++ b/Tests/CMakeOnly/CheckOBJCXXCompilerFlag/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8.12) + +project(CheckOBJCXXCompilerFlag) + +include(CheckOBJCXXCompilerFlag) + +if(CMAKE_COMPILER_IS_GNUOBJCXX) + set(COMPILER_FLAG -fobjc-direct-dispatch) +else() + set(COMPILER_FLAG -fobjc-gc) +endif() + +CHECK_OBJCXX_COMPILER_FLAGS(${COMPILER_FLAG} HAS_COMPILER_FLAG) + +if(NOT HAS_COMPILER_FLAG) + message(SEND_ERROR "Test fail: HAS_COMPILER_FLAG: ${COMPILER_FLAG}") +endif() diff --git a/Tests/CMakeOnly/CompilerIdOBJCXX/CMakeLists.txt b/Tests/CMakeOnly/CompilerIdOBJCXX/CMakeLists.txt new file mode 100644 index 0000000..8f41db0 --- /dev/null +++ b/Tests/CMakeOnly/CompilerIdOBJCXX/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.12) +project(CompilerIdOBJCXX OBJCXX) + +foreach(v + CMAKE_OBJCXX_COMPILER + CMAKE_OBJCXX_COMPILER_ID + CMAKE_OBJCXX_COMPILER_VERSION + ) + if(${v}) + message(STATUS "${v}=[${${v}}]") + else() + message(SEND_ERROR "${v} not set!") + endif() +endforeach() diff --git a/Tests/Objective-C++/cxx-file-extension-test/CMakeLists.txt b/Tests/Objective-C++/cxx-file-extension-test/CMakeLists.txt new file mode 100644 index 0000000..0b33875 --- /dev/null +++ b/Tests/Objective-C++/cxx-file-extension-test/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.15) + +project(cxx-file-extension-test CXX) + +add_executable(cxx-file-extension-test main.mm) diff --git a/Tests/Objective-C++/cxx-file-extension-test/main.mm b/Tests/Objective-C++/cxx-file-extension-test/main.mm new file mode 100644 index 0000000..1c159a9 --- /dev/null +++ b/Tests/Objective-C++/cxx-file-extension-test/main.mm @@ -0,0 +1,8 @@ +#ifndef __OBJC__ +# error "Compiler cannot compile Objective-C" +#endif + +int main() +{ + return 0; +} diff --git a/Tests/Objective-C++/objcxx-file-extension-test/CMakeLists.txt b/Tests/Objective-C++/objcxx-file-extension-test/CMakeLists.txt new file mode 100644 index 0000000..eda7bba --- /dev/null +++ b/Tests/Objective-C++/objcxx-file-extension-test/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.15) + +project(objcxx-file-extension-test OBJCXX CXX) + +add_executable(objcxx-file-extension-test main.mm) +target_link_libraries(objcxx-file-extension-test "-framework Foundation") diff --git a/Tests/Objective-C++/objcxx-file-extension-test/main.mm b/Tests/Objective-C++/objcxx-file-extension-test/main.mm new file mode 100644 index 0000000..d4aa1bb --- /dev/null +++ b/Tests/Objective-C++/objcxx-file-extension-test/main.mm @@ -0,0 +1,14 @@ +#ifndef __OBJC__ +# error "Compiler is not an Objective-C compiler." +#endif + +#import <Foundation/Foundation.h> +#include <iostream> + +int main() +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + std::cout << "Hello World" << std::endl; + [pool release]; + return 0; +} diff --git a/Tests/Objective-C++/simple-build-test/CMakeLists.txt b/Tests/Objective-C++/simple-build-test/CMakeLists.txt new file mode 100644 index 0000000..cf27683 --- /dev/null +++ b/Tests/Objective-C++/simple-build-test/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +set(CMAKE_MACOSX_RPATH OFF) + +project(simple-build-test OBJCXX) + +add_library(foo SHARED foo.mm) +target_link_libraries(foo "-framework Foundation") + +add_executable(simple-build-test main.mm) +target_link_libraries(simple-build-test "-framework Foundation" foo) diff --git a/Tests/Objective-C++/simple-build-test/foo.h b/Tests/Objective-C++/simple-build-test/foo.h new file mode 100644 index 0000000..b3fb084 --- /dev/null +++ b/Tests/Objective-C++/simple-build-test/foo.h @@ -0,0 +1,9 @@ +#import <Foundation/Foundation.h> + +@interface Foo : NSObject { + NSNumber* age; +} + +@property (nonatomic, retain) NSNumber* age; + +@end diff --git a/Tests/Objective-C++/simple-build-test/foo.mm b/Tests/Objective-C++/simple-build-test/foo.mm new file mode 100644 index 0000000..2d452a8 --- /dev/null +++ b/Tests/Objective-C++/simple-build-test/foo.mm @@ -0,0 +1,7 @@ +#import "foo.h" + +@implementation Foo + +@synthesize age; + +@end diff --git a/Tests/Objective-C++/simple-build-test/main.mm b/Tests/Objective-C++/simple-build-test/main.mm new file mode 100644 index 0000000..7c85551 --- /dev/null +++ b/Tests/Objective-C++/simple-build-test/main.mm @@ -0,0 +1,14 @@ +#import <Foundation/Foundation.h> +#import "foo.h" +#include <iostream> + +int main(int argc, char **argv) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + Foo *theFoo = [[Foo alloc] init]; + theFoo.age = [NSNumber numberWithInt:argc]; + NSLog(@"%d\n",[theFoo.age intValue]); + std::cout << [theFoo.age intValue] << std::endl; + [pool release]; + return 0; +} diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 8fd8090..498e556 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 2.6) -project(TryCompile OBJC C CXX) +project(TryCompile) macro(TEST_ASSERT value msg) if (NOT ${value}) @@ -315,31 +315,57 @@ endif() ######################################################################### # -# Test that the CHECK_OBJCC_SOURCE_COMPILES, CHECK_OBJC_SOURCE_RUNS -# macros work. +# Test that the CHECK_OBJCC_SOURCE_COMPILES, CHECK_OBJCXX_SOURCE_COMPILES +# CHECK_OBJC_SOURCE_RUNS and CHECK_OBJCXX_SOURCE_RUNS macros work -include(CheckOBJCSourceCompiles) -include(CheckOBJCSourceRuns) +if (APPLE) + enable_language(OBJC) + enable_language(OBJCXX) -CHECK_OBJC_SOURCE_COMPILES("I don't build in Objective-C" OBJC_BUILD_SHOULD_FAIL) -CHECK_OBJC_SOURCE_COMPILES("int main() { return 0; }" SIMPLE_OBJC_BUILD_SHOULD_WORK) + include(CheckOBJCSourceCompiles) + include(CheckOBJCXXSourceCompiles) + include(CheckOBJCSourceRuns) + include(CheckOBJCXXSourceRuns) -TEST_FAIL(OBJC_BUILD_SHOULD_FAIL "CHECK_OBJC_SOURCE_COMPILES() succeeded, but should have failed") -TEST_ASSERT(SIMPLE_OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded") + CHECK_OBJC_SOURCE_COMPILES("I don't build in Objective-C" OBJC_BUILD_SHOULD_FAIL) + CHECK_OBJC_SOURCE_COMPILES("int main() { return 0; }" SIMPLE_OBJC_BUILD_SHOULD_WORK) -set(CMAKE_REQUIRED_LIBRARIES "-framework Foundation") + TEST_FAIL(OBJC_BUILD_SHOULD_FAIL "CHECK_OBJC_SOURCE_COMPILES() succeeded, but should have failed") + TEST_ASSERT(SIMPLE_OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded") -CHECK_OBJC_SOURCE_COMPILES("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_BUILD_SHOULD_WORK) -CHECK_OBJC_SOURCE_RUNS("int main() { return 2; }" SIMPLE_OBJC_RUN_SHOULD_FAIL) -CHECK_OBJC_SOURCE_RUNS("int main() { return 0; }" SIMPLE_OBJC_RUN_SHOULD_WORK) -CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 2;\n}\n" OBJC_RUN_SHOULD_FAIL) -CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_RUN_SHOULD_WORK) + set(CMAKE_REQUIRED_LIBRARIES "-framework Foundation") -TEST_ASSERT(OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded") -TEST_FAIL(SIMPLE_OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURC_RUNS() succeeds, but should have failed") -TEST_ASSERT(SIMPLE_OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded") -TEST_FAIL(OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURCE_RUNS() succeeds, but should have failed") -TEST_ASSERT(OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded") + CHECK_OBJC_SOURCE_COMPILES("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_BUILD_SHOULD_WORK) + CHECK_OBJC_SOURCE_RUNS("int main() { return 2; }" SIMPLE_OBJC_RUN_SHOULD_FAIL) + CHECK_OBJC_SOURCE_RUNS("int main() { return 0; }" SIMPLE_OBJC_RUN_SHOULD_WORK) + CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 2;\n}\n" OBJC_RUN_SHOULD_FAIL) + CHECK_OBJC_SOURCE_RUNS("#import <Foundation/Foundation.h>\nint main()\n{\nNSObject *foo;\nreturn 0;\n}\n" OBJC_RUN_SHOULD_WORK) + + TEST_ASSERT(OBJC_BUILD_SHOULD_WORK "CHECK_OBJC_SOURCE_COMPILES() failed, but should have succeeded") + TEST_FAIL(SIMPLE_OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURC_RUNS() succeeds, but should have failed") + TEST_ASSERT(SIMPLE_OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded") + TEST_FAIL(OBJC_RUN_SHOULD_FAIL "CHECK_OBJC_SOURCE_RUNS() succeeds, but should have failed") + TEST_ASSERT(OBJC_RUN_SHOULD_WORK "CHECK_OBJC_SOURCE_RUNS() failed, but should have succeeded") + + + CHECK_OBJCXX_SOURCE_COMPILES("I don't build in Objective-C++" OBJCXX_BUILD_SHOULD_FAIL) + CHECK_OBJCXX_SOURCE_COMPILES("int main() { return 0; }" SIMPLE_OBJCXX_BUILD_SHOULD_WORK) + + TEST_FAIL(OBJCXX_BUILD_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_COMPILES() succeeded, but should have failed") + TEST_ASSERT(SIMPLE_OBJCXX_BUILD_SHOULD_WORK "CHECK_OBJCXX_SOURCE_COMPILES() failed, but should have succeeded") + + CHECK_OBJCXX_SOURCE_COMPILES("#import <Foundation/Foundation.h>\n#include <iostream>\nint main()\n{\nNSObject *foo;\nstd::cout << \"Hello\" << std::endl;\nreturn 0;\n}\n" OBJCXX_BUILD_SHOULD_WORK) + CHECK_OBJCXX_SOURCE_RUNS("int main() { return 2; }" SIMPLE_OBJCXX_RUN_SHOULD_FAIL) + CHECK_OBJCXX_SOURCE_RUNS("int main() { return 0; }" SIMPLE_OBJCXX_RUN_SHOULD_WORK) + CHECK_OBJCXX_SOURCE_RUNS("#import <Foundation/Foundation.h>\n#include <vector>\nint main()\n{\nNSObject *foo;\nstd::vector<int> bar;\nreturn 2;\n}\n" OBJCXX_RUN_SHOULD_FAIL) + CHECK_OBJCXX_SOURCE_RUNS("#import <Foundation/Foundation.h>\n#include <vector>\nint main()\n{\nNSObject *foo;\nstd::vector<int> bar;\nreturn 0;\n}\n" OBJCXX_RUN_SHOULD_WORK) + + TEST_ASSERT(OBJCXX_BUILD_SHOULD_WORK "CHECK_OBJCXX_SOURCE_COMPILES() failed, but should have succeeded") + TEST_FAIL(SIMPLE_OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURC_RUNS() succeeds, but should have failed") + TEST_ASSERT(SIMPLE_OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded") + TEST_FAIL(OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_RUNS() succeeds, but should have failed") + TEST_ASSERT(OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded") +endif() ####################################################################### # |