Skip to content

Commit 6ddf038

Browse files
authoredJun 27, 2024··
Remove fortran binary files and add logic to build them from source (#152)
* Add building of the fortran binaries when -ft build option is selected * delete fortran binary files * add --cmake_gen build option to specify cmake build generator * code cleanup
1 parent 3346299 commit 6ddf038

21 files changed

+116
-61
lines changed
 

‎.github/workflows/main.yml

+16-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ubuntu-latest, macos-latest, windows-latest]
22+
include:
23+
- os: ubuntu-latest
24+
optional_args: -pt
25+
- os: windows-latest
26+
optional_args: -pt --cmake_gen ninja
27+
- os: macos-latest
2328
steps:
24-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
29+
- name: Checkout sources
30+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
31+
- name: Setup Fortran compiler
32+
uses: fortran-lang/setup-fortran@8821f57b53846d35d62632eb51c60ac6c4bff4ce # v1.6.1
2533
with:
26-
submodules: recursive
34+
compiler: intel
2735
- name: Build C library
28-
# TODO: Ubuntu is phasing out support for 32-bit packages (e.g., `apt install gcc-multilib`
29-
# fails on GitHub's runner); only build the 64-bit version for now.
30-
run: python buildall.py --force_bits 64
36+
# 1. Force to only build the 64-bit version since ITT API 32-bit support will be discontinued soon
37+
# 2. Disable PT support for MacOS since we have x86 specific assembly instructions
38+
# 3. Switch to use Ninja CMake Generator for Windows since setup-fortran action
39+
# doesn't work in case of CMake + VS (https://github.com/fortran-lang/setup-fortran/issues/45)
40+
run: python buildall.py --force_bits 64 -ft ${{ matrix.optional_args }}
3141

3242
rust_format:
3343
name: Check Rust formatting

‎.github/workflows/release.yml

+26-15
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,33 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
os: [ubuntu-latest, macos-latest, windows-latest]
18+
include:
19+
- os: ubuntu-latest
20+
optional_args: -pt
21+
- os: windows-latest
22+
optional_args: -pt --cmake_gen ninja
23+
- os: macos-latest
1924
steps:
20-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
21-
with:
22-
submodules: recursive
25+
- name: Checkout sources
26+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2327
- name: Config environment
2428
if: runner.os == 'Linux'
25-
run: sudo apt-get install gcc-multilib
29+
run: sudo apt-get update && sudo apt-get install gcc-multilib
30+
- name: Setup Fortran compiler
31+
uses: fortran-lang/setup-fortran@8821f57b53846d35d62632eb51c60ac6c4bff4ce # v1.6.1
32+
with:
33+
compiler: intel
2634
- name: Build C library
27-
run: python buildall.py ${{ runner.os != 'macOS' && '-pt -v' || '-v' }}
35+
run: python buildall.py -ft ${{ matrix.optional_args }}
2836
- name: Display structure of files
2937
run: ls -R
30-
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
38+
- name: Upload artifact
39+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
3140
with:
3241
name: build-artifacts-${{ matrix.os }}
33-
path: build*/**/bin
42+
path: |
43+
build*/**/bin
44+
build*/**/fortran
3445
3546
create_release:
3647
permissions:
@@ -39,9 +50,9 @@ jobs:
3950
runs-on: ubuntu-latest
4051
needs: build
4152
steps:
42-
- name: Chechout sources
53+
- name: Checkout sources
4354
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
44-
- name: Create Release
55+
- name: Create release
4556
id: create_release
4657
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4
4758
env:
@@ -51,7 +62,7 @@ jobs:
5162
release_name: release ${{ github.ref_name }}
5263
draft: false
5364
prerelease: false
54-
- name: Download Artifacts
65+
- name: Download artifacts
5566
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
5667
with:
5768
path: build-artifacts
@@ -61,11 +72,11 @@ jobs:
6172
run: ls -R
6273
- name: Zip files
6374
run: |
64-
zip -r ittapi_build_${{ github.ref_name }}.zip include &&
65-
cd build-artifacts &&
66-
zip -rg ../ittapi_build_${{ github.ref_name }}.zip build*/**/bin &&
75+
zip -r ittapi_build_${{ github.ref_name }}.zip include &&
76+
cd build-artifacts &&
77+
zip -rg ../ittapi_build_${{ github.ref_name }}.zip build*/**/bin build*/**/fortran &&
6778
cd -
68-
- name: Upload Release Asset
79+
- name: Upload release asset
6980
id: upload-release-asset
7081
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1.0.2
7182
env:

‎CMakeLists.txt

+61-34
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
55
#
66

7-
cmake_minimum_required(VERSION 2.8.12)
7+
cmake_minimum_required(VERSION 3.5)
88

9-
if (POLICY CMP0048)
9+
if(POLICY CMP0048)
1010
# The `project()` command manages `VERSION` variables
1111
cmake_policy(SET CMP0048 NEW)
1212
endif()
@@ -23,19 +23,25 @@ endif()
2323

2424
project(ittapi)
2525

26-
OPTION(FORCE_32 "Force a 32bit compile on 64bit" OFF)
27-
OPTION(ITT_API_IPT_SUPPORT "ptmarks support" OFF)
28-
OPTION(ITT_API_FORTRAN_SUPPORT "fortran support" OFF)
26+
option(FORCE_32 "Force a 32-bit compile on 64-bit" OFF)
27+
option(ITT_API_IPT_SUPPORT "ptmarks support" OFF)
28+
option(ITT_API_FORTRAN_SUPPORT "fortran support" OFF)
2929

30-
IF(FORCE_32 AND UNIX)
30+
if(FORCE_32 AND UNIX)
3131
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
3232
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
33-
ENDIF()
33+
endif()
3434

3535
if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT(FORCE_32))
3636
set(ARCH_64 ON)
3737
endif()
3838

39+
if(FORCE_32 AND ITT_API_FORTRAN_SUPPORT)
40+
# ifx dropped 32-bit support
41+
message(WARNING "Fortran support for 32-bit has been discontinued")
42+
set(ITT_API_FORTRAN_SUPPORT OFF)
43+
endif()
44+
3945
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
4046
# override default -O3
4147
string(REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
@@ -48,10 +54,10 @@ endif()
4854

4955
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
5056

51-
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
52-
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
53-
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH} )
54-
endforeach( )
57+
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
58+
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
59+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH})
60+
endforeach()
5561

5662
set(ITT_PUBLIC_HDRS
5763
include/ittnotify.h
@@ -61,45 +67,66 @@ set(ITT_PUBLIC_HDRS
6167

6268
file(GLOB ITT_SRCS "src/ittnotify/*.c" "src/ittnotify/*.h")
6369

64-
if (ITT_API_IPT_SUPPORT)
70+
if(ITT_API_IPT_SUPPORT)
6571
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DITT_API_IPT_SUPPORT")
6672
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DITT_API_IPT_SUPPORT")
67-
if (NOT WIN32)
73+
if(NOT WIN32)
6874
enable_language(ASM)
69-
if (ARCH_64)
75+
if(ARCH_64)
7076
set(ITT_PT src/ittnotify/ittptmark64.S)
7177
else()
7278
set(ASM_OPTIONS "-m32")
7379
set(ITT_PT src/ittnotify/ittptmark32.S)
7480
endif()
75-
set(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}" )
81+
set(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}")
7682
else()
7783
enable_language(ASM_MASM)
78-
if (ARCH_64)
84+
if(ARCH_64)
7985
set(ITT_PT src/ittnotify/ittptmark64.asm)
8086
else()
8187
set(ITT_PT src/ittnotify/ittptmark32.asm)
8288
endif()
8389
endif()
8490
endif()
8591

86-
if (NOT WIN32)
92+
if(NOT WIN32)
8793
set(PLATFORM_PATH "posix")
8894
set(PLATFORM_EXT "o")
8995
else()
9096
set(PLATFORM_PATH "win32")
9197
set(PLATFORM_EXT "obj")
9298
endif()
9399

94-
if (ARCH_64)
95-
set(ARCH_PATH "x86_64")
96-
else()
97-
set(ARCH_PATH "x86")
98-
endif()
99-
100100
if(ITT_API_FORTRAN_SUPPORT)
101-
set(ITT_FORTRAN include/fortran/${PLATFORM_PATH}/${ARCH_PATH}/ittfortran.${PLATFORM_EXT})
102-
set(ADVISOR_ANNOTATION include/fortran/${PLATFORM_PATH}/${ARCH_PATH}/advisor_annotate.${PLATFORM_EXT})
101+
enable_language(Fortran)
102+
103+
set(FORTRAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
104+
file(MAKE_DIRECTORY ${FORTRAN_BINARY_DIR})
105+
106+
set(ITT_FORTRAN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/fortran/${PLATFORM_PATH}/ittnotify.f90)
107+
set(ADVISOR_ANNOTATION_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/fortran/advisor_annotate.f90)
108+
set(ITT_FORTRAN ${FORTRAN_BINARY_DIR}/ittfortran.${PLATFORM_EXT})
109+
set(ADVISOR_ANNOTATION ${FORTRAN_BINARY_DIR}/advisor_annotate.${PLATFORM_EXT})
110+
111+
if(WIN32)
112+
set(FORTRAN_BUILD_CMD ${CMAKE_Fortran_COMPILER} /Z7 /nologo /libdir:noauto /c /O2 /module:${FORTRAN_BINARY_DIR})
113+
set(ITT_FORTRAN_BUILD_CMD ${FORTRAN_BUILD_CMD} /object:${ITT_FORTRAN} ${ITT_FORTRAN_SRC})
114+
set(ADVISOR_ANNOTATION_BUILD_CMD ${FORTRAN_BUILD_CMD} /object:${ADVISOR_ANNOTATION} ${ADVISOR_ANNOTATION_SRC})
115+
else()
116+
set(FORTRAN_BUILD_CMD ${CMAKE_Fortran_COMPILER} -g -c -fPIC -O2 -module ${FORTRAN_BINARY_DIR})
117+
set(ITT_FORTRAN_BUILD_CMD ${FORTRAN_BUILD_CMD} -o ${ITT_FORTRAN} ${ITT_FORTRAN_SRC})
118+
set(ADVISOR_ANNOTATION_BUILD_CMD ${FORTRAN_BUILD_CMD} -o ${ADVISOR_ANNOTATION} ${ADVISOR_ANNOTATION_SRC})
119+
endif()
120+
121+
add_custom_command(OUTPUT ${ITT_FORTRAN}
122+
COMMAND ${ITT_FORTRAN_BUILD_CMD}
123+
DEPENDS ${ITT_FORTRAN_SRC}
124+
COMMENT "Building ITT Fortran")
125+
126+
add_custom_command(OUTPUT ${ADVISOR_ANNOTATION}
127+
COMMAND ${ADVISOR_ANNOTATION_BUILD_CMD}
128+
DEPENDS ${ADVISOR_ANNOTATION_SRC}
129+
COMMENT "Building Advisor Annotation")
103130

104131
add_library(ittnotify STATIC ${ITT_SRCS} ${ITT_PUBLIC_HDRS} ${ITT_PT} ${ITT_FORTRAN})
105132
add_library(advisor STATIC ${ADVISOR_ANNOTATION})
@@ -111,24 +138,24 @@ set(JITPROFILING_SRC "src/ittnotify/jitprofiling.c")
111138
add_library(jitprofiling STATIC ${JITPROFILING_SRC})
112139

113140
if(WIN32)
114-
SET_TARGET_PROPERTIES(ittnotify PROPERTIES OUTPUT_NAME libittnotify)
115-
SET_TARGET_PROPERTIES(jitprofiling PROPERTIES OUTPUT_NAME libjitprofiling)
141+
set_target_properties(ittnotify PROPERTIES OUTPUT_NAME libittnotify)
142+
set_target_properties(jitprofiling PROPERTIES OUTPUT_NAME libjitprofiling)
116143
if(ITT_API_FORTRAN_SUPPORT)
117-
SET_TARGET_PROPERTIES(advisor PROPERTIES OUTPUT_NAME libadvisor)
144+
set_target_properties(advisor PROPERTIES OUTPUT_NAME libadvisor)
118145
endif()
119146
else()
120-
SET_TARGET_PROPERTIES(ittnotify PROPERTIES OUTPUT_NAME ittnotify)
121-
SET_TARGET_PROPERTIES(jitprofiling PROPERTIES OUTPUT_NAME jitprofiling)
147+
set_target_properties(ittnotify PROPERTIES OUTPUT_NAME ittnotify)
148+
set_target_properties(jitprofiling PROPERTIES OUTPUT_NAME jitprofiling)
122149
if(ITT_API_FORTRAN_SUPPORT)
123-
SET_TARGET_PROPERTIES(advisor PROPERTIES OUTPUT_NAME advisor)
150+
set_target_properties(advisor PROPERTIES OUTPUT_NAME advisor)
124151
endif()
125152
endif()
126153

127-
TARGET_LINK_LIBRARIES(ittnotify PRIVATE ${CMAKE_DL_LIBS})
154+
target_link_libraries(ittnotify PRIVATE ${CMAKE_DL_LIBS})
128155

129-
SET_TARGET_PROPERTIES(ittnotify PROPERTIES LINKER_LANGUAGE C)
156+
set_target_properties(ittnotify PROPERTIES LINKER_LANGUAGE C)
130157
if(ITT_API_FORTRAN_SUPPORT)
131-
SET_TARGET_PROPERTIES(advisor PROPERTIES LINKER_LANGUAGE C)
158+
set_target_properties(advisor PROPERTIES LINKER_LANGUAGE C)
132159
endif()
133160

134161
target_include_directories(ittnotify

‎README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ a BSD/GPLv2 dual license with every tool supporting ITT API.
2121
To build the library:
2222
- On Windows, Linux, FreeBSD and OSX: requires [cmake](https://cmake.org) to be set in `PATH`
2323
- Windows: requires Visual Studio installed or requires [Ninja](https://github.com/ninja-build/ninja/releases) to be set in `PATH`
24+
- To enable fortran support requires [Intel Fortran Compiler](https://www.intel.com/content/www/us/en/docs/fortran-compiler/get-started-guide/current/overview.html) installed
2425
- To list available build options execute: `python buildall.py -h`
2526
```
26-
usage: buildall.py [-h] [-d] [-c] [-v] [-pt] [--force_bits] [-ft]
27+
usage: buildall.py [-h] [-d] [-c] [-v] [-pt] [-ft] [--force_bits]
2728
2829
optional arguments:
2930
-h, --help show this help message and exit
3031
-d, --debug specify debug build configuration (release by default)
3132
-c, --clean delete any intermediate and output files
3233
-v, --verbose enable verbose output from build process
3334
-pt, --ptmark enable anomaly detection support
34-
--force_bits specify bit version for the target
3535
-ft, --fortran enable fortran support
36+
--force_bits specify bit version for the target
37+
--vs specify visual studio version (Windows only)
38+
--cmake_gen specify cmake build generator (Windows only)
3639
```
3740
### License
3841

‎buildall.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ def main():
115115
"-v", "--verbose", help="enable verbose output from build process", action="store_true")
116116
parser.add_argument(
117117
"-pt", "--ptmark", help="enable anomaly detection support", action="store_true")
118+
parser.add_argument(
119+
"-ft", "--fortran", help="enable fortran support", action="store_true")
118120
parser.add_argument(
119121
"--force_bits", choices=["32", "64"], help="specify bit version for the target")
120-
parser.add_argument("-ft", "--fortran",
121-
help="enable fortran support", action="store_true")
122122
if sys.platform == 'win32' and vs_versions:
123123
parser.add_argument(
124124
"--vs", help="specify visual studio version {default}", choices=vs_versions, default=vs_versions[0])
125+
parser.add_argument(
126+
"--cmake_gen", choices=["vs", "ninja"], help="specify cmake build generator")
125127
args = parser.parse_args()
126128

127129
if args.force_bits:
@@ -157,7 +159,9 @@ def main():
157159
return
158160

159161
if sys.platform == 'win32':
160-
if vs_versions:
162+
# ninja does not support platform bit specification
163+
use_ninja = args.cmake_gen == 'ninja' and bits =='64'
164+
if vs_versions and not use_ninja:
161165
generator = 'Visual Studio {}'.format(args.vs)
162166
generator_args = '-A {}'.format('x64' if bits ==
163167
'64' else 'Win32')
@@ -177,7 +181,7 @@ def main():
177181
])))
178182

179183
if sys.platform == 'win32':
180-
target_project = 'ALL_BUILD'
184+
target_project = 'ALL_BUILD' if not use_ninja else 'all'
181185
run_shell('%s --build . --config %s --target %s' %
182186
(cmake, ('Debug' if args.debug else 'Release'), target_project))
183187
else:
-12.3 KB
Binary file not shown.
-25.2 KB
Binary file not shown.
-22.5 KB
Binary file not shown.
-9.66 KB
Binary file not shown.
-13.8 KB
Binary file not shown.
-36.8 KB
Binary file not shown.
-32.1 KB
Binary file not shown.
-11 KB
Binary file not shown.
-12.4 KB
Binary file not shown.
-10.7 KB
Binary file not shown.
-7.95 KB
Binary file not shown.
-9.75 KB
Binary file not shown.
-13.9 KB
Binary file not shown.
-13.4 KB
Binary file not shown.
-9.48 KB
Binary file not shown.
-11.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.