blob: 4338f7bbb493469bf2234bb889185d01d82b2104 [file] [log] [blame]
Jakub Sujakdf5d9872023-05-22 17:38:56 +01001# Copyright (c) 2023 Arm Limited.
2#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22
23cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
24
25#---------------------------------------------------------------------
26# Compute Kernel Writer Project
27
28project(ComputeKernelWriter
29 VERSION 1.0.0
30 LANGUAGES CXX
31 )
32
33set(CMAKE_CXX_STANDARD 14)
34set(CMAKE_CXX_STANDARD_REQUIRED ON)
35set(CMAKE_CXX_EXTENSIONS OFF)
36
37include(GNUInstallDirs)
38
39message(STATUS "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}")
Jakub Sujakdf5d9872023-05-22 17:38:56 +010040
41#---------------------------------------------------------------------
42# Options
43
44set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wdisabled-optimization -Wformat=2 \
45 -Winit-self -Wstrict-overflow=2 -Wswitch-default -Woverloaded-virtual \
46 -Wformat-security -Wctor-dtor-privacy -Wsign-promo -Weffc++ \
47 -Wlogical-op -Wstrict-null-sentinel")
Jakub Sujakbec9b032023-06-09 14:13:30 +010048set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os")
Jakub Sujakdf5d9872023-05-22 17:38:56 +010049
50option(CKW_ENABLE_OPENCL "Enable OpenCL code generation" OFF)
51option(CKW_ENABLE_ASSERTS "Enable assertions. Always enabled in Debug builds" OFF)
52option(CKW_BUILD_TESTING "Build the Compute Kernel Writer validation test suite" OFF)
53option(CKW_CCACHE "Enable compiler cache builds" OFF)
54
55#---------------------------------------------------------------------
56# Build configuration
57
58get_property(CKW_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
59
Jakub Sujakbec9b032023-06-09 14:13:30 +010060# Allow only Release or Debug builds
61if(NOT CKW_IS_MULTI_CONFIG) # Single-config generators
Jakub Sujakdf5d9872023-05-22 17:38:56 +010062 if(NOT CMAKE_BUILD_TYPE)
Jakub Sujakbec9b032023-06-09 14:13:30 +010063 set(CMAKE_BUILD_TYPE Release CACHE STRING "Options: Release (default) or Debug" FORCE)
Jakub Sujakdf5d9872023-05-22 17:38:56 +010064 endif()
Jakub Sujakbec9b032023-06-09 14:13:30 +010065else() # Multi-config generators
66 list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES RelWithDebInfo MinSizeRel)
Jakub Sujakdf5d9872023-05-22 17:38:56 +010067endif()
68
69# Simplistic CCache setup
70if(CKW_CCACHE)
71 find_program(CCACHE_FOUND ccache)
72 if(CCACHE_FOUND)
73 set(CMAKE_C_COMPILER_LAUNCHER ${CACHE_FOUND})
74 set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_FOUND})
75 endif()
76endif()
77
78#---------------------------------------------------------------------
79# Library targets
80
81set(CKW_ASSERTS_OPTS "-fstack-protector-strong")
82
83# Define common properties across all targets
84add_library(ckw_common INTERFACE)
85
86target_compile_definitions(ckw_common INTERFACE
87 $<$<CONFIG:Debug>:COMPUTE_KERNEL_WRITER_DEBUG_ENABLED>
88 $<$<CONFIG:Debug>:COMPUTE_KERNEL_WRITER_ASSERTS_ENABLED>
89 $<$<BOOL:${CKW_ASSERTS}>:COMPUTE_KERNEL_WRITER_ASSERTS_ENABLED>
90 $<$<BOOL:${CKW_ENABLE_OPENCL}>:COMPUTE_KERNEL_WRITER_OPENCL_ENABLED>
91 )
92
93target_compile_options(ckw_common INTERFACE
94 -pedantic
95 "$<$<BOOL:${CKW_ASSERTS}>:${CKW_ASSERTS_OPTS}>"
96 )
97
98# Compute Kernel Writer library
99add_library(ckw)
100
101target_sources(ckw PRIVATE
102 src/Error.cpp
103 src/Helpers.cpp
104 src/TensorInfo.cpp
105 src/TensorUtils.cpp
106 src/TileInfo.cpp
107 )
108if(CKW_ENABLE_OPENCL)
109 target_sources(ckw PRIVATE
110 src/cl/CLHelpers.cpp
111 src/cl/CLTile.cpp
112 )
113endif()
114
115target_link_libraries(ckw PUBLIC ckw_common)
116target_include_directories(ckw
117 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include
118 PRIVATE ${CMAKE_CURRENT_LIST_DIR}
119 )
120
121set_target_properties(ckw
122 PROPERTIES
123 SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
124 VERSION ${CMAKE_PROJECT_VERSION}
125 )
126
127#---------------------------------------------------------------------
128# Validation tests
129
130if(CKW_BUILD_TESTING)
131 add_executable(ckw_validation
132 validation/tests/common/Common.h
133 validation/tests/TensorBitMaskTest.hpp
134 validation/tests/UtilsTest.hpp
135 validation/Validation.cpp
136 )
137 if(CKW_ENABLE_OPENCL)
138 target_sources(ckw_validation PRIVATE validation/tests/CLTileTest.hpp)
139 endif()
140
141 target_link_libraries(ckw_validation PRIVATE ckw)
142 target_include_directories(ckw_validation
143 PRIVATE ${CMAKE_CURRENT_LIST_DIR}
144 )
145endif()
146
147#---------------------------------------------------------------------
148# Installing
149
150install(TARGETS ckw
151 CONFIGURATIONS Release
152 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
153 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
154 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
155 )
156
157install(DIRECTORY include/ckw
158 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
159 )