mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-23 00:48:55 +08:00
Tests: Add cases for typical CheckIPOSupported usage
This commit is contained in:

committed by
Brad King

parent
f79b8fad09
commit
eeb58c5c34
@@ -477,6 +477,17 @@ if(BUILD_TESTING)
|
|||||||
|
|
||||||
ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
|
ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
|
||||||
|
|
||||||
|
set(Module.CheckIPOSupported-C_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_C=${CMake_TEST_IPO_WORKS_C})
|
||||||
|
ADD_TEST_MACRO(Module.CheckIPOSupported-C CheckIPOSupported-C)
|
||||||
|
|
||||||
|
set(Module.CheckIPOSupported-CXX_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_CXX=${CMake_TEST_IPO_WORKS_CXX})
|
||||||
|
ADD_TEST_MACRO(Module.CheckIPOSupported-CXX CheckIPOSupported-CXX)
|
||||||
|
|
||||||
|
if(CMAKE_Fortran_COMPILER)
|
||||||
|
set(Module.CheckIPOSupported-Fortran_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_Fortran=${CMake_TEST_IPO_WORKS_Fortran})
|
||||||
|
ADD_TEST_MACRO(Module.CheckIPOSupported-Fortran CheckIPOSupported-Fortran)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
|
add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
|
||||||
--build-and-test
|
--build-and-test
|
||||||
"${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
|
"${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
|
||||||
|
19
Tests/Module/CheckIPOSupported-C/CMakeLists.txt
Normal file
19
Tests/Module/CheckIPOSupported-C/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
project(CheckIPOSupported-C LANGUAGES C)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0069 NEW)
|
||||||
|
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT ipo_supported)
|
||||||
|
if(ipo_supported)
|
||||||
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
elseif(CMake_TEST_IPO_WORKS_C)
|
||||||
|
message(FATAL_ERROR "IPO expected to work")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(foo foo.c)
|
||||||
|
add_executable(CheckIPOSupported-C main.c)
|
||||||
|
target_link_libraries(CheckIPOSupported-C PUBLIC foo)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(NAME CheckIPOSupported-C COMMAND CheckIPOSupported-C)
|
4
Tests/Module/CheckIPOSupported-C/foo.c
Normal file
4
Tests/Module/CheckIPOSupported-C/foo.c
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
int foo()
|
||||||
|
{
|
||||||
|
return 0x42;
|
||||||
|
}
|
9
Tests/Module/CheckIPOSupported-C/main.c
Normal file
9
Tests/Module/CheckIPOSupported-C/main.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
int foo();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (foo() == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
19
Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
Normal file
19
Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
project(CheckIPOSupported-CXX LANGUAGES CXX)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0069 NEW)
|
||||||
|
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT ipo_supported)
|
||||||
|
if(ipo_supported)
|
||||||
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
elseif(CMake_TEST_IPO_WORKS_CXX)
|
||||||
|
message(FATAL_ERROR "IPO expected to work")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(foo foo.cpp)
|
||||||
|
add_executable(CheckIPOSupported-CXX main.cpp)
|
||||||
|
target_link_libraries(CheckIPOSupported-CXX PUBLIC foo)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(NAME CheckIPOSupported-CXX COMMAND CheckIPOSupported-CXX)
|
4
Tests/Module/CheckIPOSupported-CXX/foo.cpp
Normal file
4
Tests/Module/CheckIPOSupported-CXX/foo.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
int foo()
|
||||||
|
{
|
||||||
|
return 0x42;
|
||||||
|
}
|
9
Tests/Module/CheckIPOSupported-CXX/main.cpp
Normal file
9
Tests/Module/CheckIPOSupported-CXX/main.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
int foo();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (foo() == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
19
Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
Normal file
19
Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
project(CheckIPOSupported-Fortran LANGUAGES Fortran)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0069 NEW)
|
||||||
|
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT ipo_supported)
|
||||||
|
if(ipo_supported)
|
||||||
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
elseif(CMake_TEST_IPO_WORKS_Fortran)
|
||||||
|
message(FATAL_ERROR "IPO expected to work")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(foo foo.f)
|
||||||
|
add_executable(CheckIPOSupported-Fortran main.f)
|
||||||
|
target_link_libraries(CheckIPOSupported-Fortran PUBLIC foo)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(NAME CheckIPOSupported-Fortran COMMAND CheckIPOSupported-Fortran)
|
2
Tests/Module/CheckIPOSupported-Fortran/foo.f
Normal file
2
Tests/Module/CheckIPOSupported-Fortran/foo.f
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SUBROUTINE FOO
|
||||||
|
END
|
3
Tests/Module/CheckIPOSupported-Fortran/main.f
Normal file
3
Tests/Module/CheckIPOSupported-Fortran/main.f
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
PROGRAM BOO
|
||||||
|
CALL FOO()
|
||||||
|
END
|
Reference in New Issue
Block a user