Skip to content

Commit 50b1568

Browse files
committed
Added Cmake examples
1 parent 27ff684 commit 50b1568

28 files changed

+1120
-0
lines changed

Templates/cmake/C/IPO/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#==============================================================
2+
# Copyright © Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#=============================================================
6+
7+
if (CMAKE_HOST_WIN32)
8+
# need CMake 3.25.0+ for IntelLLVM support of target link properties on Windows
9+
cmake_minimum_required(VERSION 3.25)
10+
if( NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER icx)
12+
endif()
13+
if( NOT DEFINED CMAKE_CXX_COMPILER)
14+
set(CMAKE_CXX_COMPILER icx)
15+
endif()
16+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
17+
set(CMAKE_Fortran_COMPILER ifx)
18+
endif()
19+
else()
20+
# CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux
21+
cmake_minimum_required(VERSION 3.20.5)
22+
if( NOT DEFINED CMAKE_C_COMPILER)
23+
set(CMAKE_C_COMPILER icx)
24+
endif()
25+
if( NOT DEFINED CMAKE_CXX_COMPILER)
26+
set(CMAKE_CXX_COMPILER icpx)
27+
endif()
28+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
29+
set(CMAKE_Fortran_COMPILER ifx)
30+
endif()
31+
endif()
32+
33+
project("ipo_c" LANGUAGES C)
34+
35+
include(CheckIPOSupported)
36+
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_check_output LANGUAGES C)
37+
38+
if(ipo_supported)
39+
message(STATUS "Toolchain has C IPO support")
40+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
41+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
42+
else()
43+
message(WARNING "Toolchain WITHOUT IPO support: ${ipo_check_output}")
44+
endif()
45+
46+
add_library(ipo_c_lib ipo_c_lib1.c ipo_c_lib.h)
47+
add_executable(ipo_c main.c)
48+
target_link_libraries(ipo_c PUBLIC ipo_c_lib)

Templates/cmake/C/IPO/ipo_c_lib.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#ifndef IPO_C_LIB1_H
8+
#define IPO_C_LIB1_H
9+
10+
int plus3(int x);
11+
12+
#endif

Templates/cmake/C/IPO/ipo_c_lib1.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include "ipo_c_lib.h"
8+
#include <stdio.h>
9+
10+
int plus3(int x) { return x + 3; }

Templates/cmake/C/IPO/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include "ipo_c_lib.h"
8+
9+
#include <stdio.h>
10+
11+
int main(int argc, char *argv[]) {
12+
int ans = plus3(argc);
13+
printf("%d + 3 = %d\n", argc, ans);
14+
return 0;
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#==============================================================
2+
# Copyright © Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#=============================================================
6+
7+
if (CMAKE_HOST_WIN32)
8+
# need CMake 3.25.0+ for IntelLLVM support of target link properties on Windows
9+
cmake_minimum_required(VERSION 3.25)
10+
if( NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER icx)
12+
endif()
13+
if( NOT DEFINED CMAKE_CXX_COMPILER)
14+
set(CMAKE_CXX_COMPILER icx)
15+
endif()
16+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
17+
set(CMAKE_Fortran_COMPILER ifx)
18+
endif()
19+
else()
20+
# CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux
21+
cmake_minimum_required(VERSION 3.20.5)
22+
if( NOT DEFINED CMAKE_C_COMPILER)
23+
set(CMAKE_C_COMPILER icx)
24+
endif()
25+
if( NOT DEFINED CMAKE_CXX_COMPILER)
26+
set(CMAKE_CXX_COMPILER icpx)
27+
endif()
28+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
29+
set(CMAKE_Fortran_COMPILER ifx)
30+
endif()
31+
endif()
32+
33+
project(find_omp_c VERSION 1.0 LANGUAGES C)
34+
35+
find_package(OpenMP REQUIRED)
36+
37+
add_executable(hello-omp-c hello_omp.c)
38+
target_link_libraries(hello-omp-c PUBLIC OpenMP::OpenMP_C)

Templates/cmake/C/OpenMP/hello_omp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include <omp.h>
8+
#include <stdio.h>
9+
10+
int main(int argc, char *argv[]) {
11+
printf("Hello, OpenMP C World!\n");
12+
#pragma omp parallel
13+
{ printf(" I am thread %d\n", omp_get_thread_num()); }
14+
printf("All done, bye.\n");
15+
return 0;
16+
}

Templates/cmake/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#==============================================================
2+
# Copyright © Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#=============================================================
6+
7+
if (CMAKE_HOST_WIN32)
8+
# need CMake 3.25.0+ for IntelLLVM support of target link properties on Windows
9+
cmake_minimum_required(VERSION 3.25)
10+
if( NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER icx)
12+
endif()
13+
if( NOT DEFINED CMAKE_CXX_COMPILER)
14+
set(CMAKE_CXX_COMPILER icx)
15+
endif()
16+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
17+
set(CMAKE_Fortran_COMPILER ifx)
18+
endif()
19+
else()
20+
# CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux
21+
cmake_minimum_required(VERSION 3.20.5)
22+
if( NOT DEFINED CMAKE_C_COMPILER)
23+
set(CMAKE_C_COMPILER icx)
24+
endif()
25+
if( NOT DEFINED CMAKE_CXX_COMPILER)
26+
set(CMAKE_CXX_COMPILER icpx)
27+
endif()
28+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
29+
set(CMAKE_Fortran_COMPILER ifx)
30+
endif()
31+
endif()
32+
33+
project(cmake-intel-examples)
34+
35+
set(projects
36+
OpenMP
37+
IPO
38+
)
39+
40+
foreach(lang C CXX)
41+
foreach(project ${projects})
42+
add_subdirectory(${lang}/${project})
43+
endforeach()
44+
endforeach()
45+
46+
add_subdirectory(Fortran/do_concurrent)
47+
add_subdirectory(Fortran/OpenMP)
48+
add_subdirectory(SYCL/add_sycl_to_target)
49+
add_subdirectory(SYCL/target_link_library)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#==============================================================
2+
# Copyright © Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#=============================================================
6+
7+
if (CMAKE_HOST_WIN32)
8+
# need CMake 3.25.0+ for IntelLLVM support of target link properties on Windows
9+
cmake_minimum_required(VERSION 3.25)
10+
if( NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER icx)
12+
endif()
13+
if( NOT DEFINED CMAKE_CXX_COMPILER)
14+
set(CMAKE_CXX_COMPILER icx)
15+
endif()
16+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
17+
set(CMAKE_Fortran_COMPILER ifx)
18+
endif()
19+
else()
20+
# CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux
21+
cmake_minimum_required(VERSION 3.20.5)
22+
if( NOT DEFINED CMAKE_C_COMPILER)
23+
set(CMAKE_C_COMPILER icx)
24+
endif()
25+
if( NOT DEFINED CMAKE_CXX_COMPILER)
26+
set(CMAKE_CXX_COMPILER icpx)
27+
endif()
28+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
29+
set(CMAKE_Fortran_COMPILER ifx)
30+
endif()
31+
endif()
32+
33+
project("ipo_cxx" LANGUAGES CXX)
34+
35+
include(CheckIPOSupported)
36+
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_check_output LANGUAGES CXX)
37+
38+
if(ipo_supported)
39+
message(STATUS "Toolchain has CXX IPO support")
40+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
41+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
42+
else()
43+
message(STATUS "Toolchain WITHOUT IPO support: ${ipo_check_output}")
44+
endif()
45+
46+
add_library(ipo_cxx_lib ipo_cxx_lib1.cpp ipo_cxx_lib.h)
47+
add_executable(ipo_cxx main.cpp)
48+
target_link_libraries(ipo_cxx PUBLIC ipo_cxx_lib)

Templates/cmake/CXX/IPO/ipo_cxx_lib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#pragma once
8+
9+
int plus3(int x);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include "ipo_cxx_lib.h"
8+
9+
int plus3(int x) { return x + 3; }

Templates/cmake/CXX/IPO/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include "ipo_cxx_lib.h"
8+
#include <iostream>
9+
10+
int main(int argc, char *argv[]) {
11+
int ans = plus3(argc);
12+
std::cout << argc << " + 3 = " << ans << std::endl;
13+
14+
return 0;
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#==============================================================
2+
# Copyright © Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#=============================================================
6+
7+
if (CMAKE_HOST_WIN32)
8+
# need CMake 3.25.0+ for IntelLLVM support of target link properties on Windows
9+
cmake_minimum_required(VERSION 3.25)
10+
if( NOT DEFINED CMAKE_C_COMPILER)
11+
set(CMAKE_C_COMPILER icx)
12+
endif()
13+
if( NOT DEFINED CMAKE_CXX_COMPILER)
14+
set(CMAKE_CXX_COMPILER icx)
15+
endif()
16+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
17+
set(CMAKE_Fortran_COMPILER ifx)
18+
endif()
19+
else()
20+
# CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux
21+
cmake_minimum_required(VERSION 3.20.5)
22+
if( NOT DEFINED CMAKE_C_COMPILER)
23+
set(CMAKE_C_COMPILER icx)
24+
endif()
25+
if( NOT DEFINED CMAKE_CXX_COMPILER)
26+
set(CMAKE_CXX_COMPILER icpx)
27+
endif()
28+
if( NOT DEFINED CMAKE_Fortran_COMPILER)
29+
set(CMAKE_Fortran_COMPILER ifx)
30+
endif()
31+
endif()
32+
33+
project(find_omp_cxx VERSION 1.0 LANGUAGES CXX)
34+
35+
find_package(OpenMP REQUIRED)
36+
37+
add_executable(hello-omp-cxx hello_omp.cpp)
38+
target_link_libraries(hello-omp-cxx PUBLIC OpenMP::OpenMP_CXX)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include <iostream>
8+
#include <omp.h>
9+
#include <sstream>
10+
11+
int main(int argc, char *argv[]) {
12+
std::cout << "Hello, OpenMP C World!" << std::endl;
13+
#pragma omp parallel
14+
{
15+
std::ostringstream msg;
16+
msg << " I am thread " << omp_get_thread_num() << std::endl;
17+
std::cout << msg.str();
18+
}
19+
std::cout << "All done, bye." << std::endl;
20+
return 0;
21+
}

0 commit comments

Comments
 (0)