Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 1 | # 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 | |
| 23 | cmake_minimum_required(VERSION 3.14 FATAL_ERROR) |
| 24 | |
| 25 | #--------------------------------------------------------------------- |
| 26 | # Compute Kernel Writer Project |
| 27 | |
| 28 | project(ComputeKernelWriter |
| 29 | VERSION 1.0.0 |
| 30 | LANGUAGES CXX |
| 31 | ) |
| 32 | |
| 33 | set(CMAKE_CXX_STANDARD 14) |
| 34 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 35 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 36 | |
| 37 | include(GNUInstallDirs) |
| 38 | |
| 39 | message(STATUS "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}") |
Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 40 | |
| 41 | #--------------------------------------------------------------------- |
| 42 | # Options |
| 43 | |
| 44 | set(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 Sujak | bec9b03 | 2023-06-09 14:13:30 +0100 | [diff] [blame] | 48 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os") |
Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 49 | |
| 50 | option(CKW_ENABLE_OPENCL "Enable OpenCL code generation" OFF) |
| 51 | option(CKW_ENABLE_ASSERTS "Enable assertions. Always enabled in Debug builds" OFF) |
| 52 | option(CKW_BUILD_TESTING "Build the Compute Kernel Writer validation test suite" OFF) |
| 53 | option(CKW_CCACHE "Enable compiler cache builds" OFF) |
| 54 | |
| 55 | #--------------------------------------------------------------------- |
| 56 | # Build configuration |
| 57 | |
| 58 | get_property(CKW_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 59 | |
Jakub Sujak | bec9b03 | 2023-06-09 14:13:30 +0100 | [diff] [blame] | 60 | # Allow only Release or Debug builds |
| 61 | if(NOT CKW_IS_MULTI_CONFIG) # Single-config generators |
Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 62 | if(NOT CMAKE_BUILD_TYPE) |
Jakub Sujak | bec9b03 | 2023-06-09 14:13:30 +0100 | [diff] [blame] | 63 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Options: Release (default) or Debug" FORCE) |
Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 64 | endif() |
Jakub Sujak | bec9b03 | 2023-06-09 14:13:30 +0100 | [diff] [blame] | 65 | else() # Multi-config generators |
| 66 | list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES RelWithDebInfo MinSizeRel) |
Jakub Sujak | df5d987 | 2023-05-22 17:38:56 +0100 | [diff] [blame] | 67 | endif() |
| 68 | |
| 69 | # Simplistic CCache setup |
| 70 | if(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() |
| 76 | endif() |
| 77 | |
| 78 | #--------------------------------------------------------------------- |
| 79 | # Library targets |
| 80 | |
| 81 | set(CKW_ASSERTS_OPTS "-fstack-protector-strong") |
| 82 | |
| 83 | # Define common properties across all targets |
| 84 | add_library(ckw_common INTERFACE) |
| 85 | |
| 86 | target_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 | |
| 93 | target_compile_options(ckw_common INTERFACE |
| 94 | -pedantic |
| 95 | "$<$<BOOL:${CKW_ASSERTS}>:${CKW_ASSERTS_OPTS}>" |
| 96 | ) |
| 97 | |
| 98 | # Compute Kernel Writer library |
| 99 | add_library(ckw) |
| 100 | |
| 101 | target_sources(ckw PRIVATE |
| 102 | src/Error.cpp |
| 103 | src/Helpers.cpp |
| 104 | src/TensorInfo.cpp |
| 105 | src/TensorUtils.cpp |
| 106 | src/TileInfo.cpp |
| 107 | ) |
| 108 | if(CKW_ENABLE_OPENCL) |
| 109 | target_sources(ckw PRIVATE |
| 110 | src/cl/CLHelpers.cpp |
| 111 | src/cl/CLTile.cpp |
| 112 | ) |
| 113 | endif() |
| 114 | |
| 115 | target_link_libraries(ckw PUBLIC ckw_common) |
| 116 | target_include_directories(ckw |
| 117 | PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include |
| 118 | PRIVATE ${CMAKE_CURRENT_LIST_DIR} |
| 119 | ) |
| 120 | |
| 121 | set_target_properties(ckw |
| 122 | PROPERTIES |
| 123 | SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} |
| 124 | VERSION ${CMAKE_PROJECT_VERSION} |
| 125 | ) |
| 126 | |
| 127 | #--------------------------------------------------------------------- |
| 128 | # Validation tests |
| 129 | |
| 130 | if(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 | ) |
| 145 | endif() |
| 146 | |
| 147 | #--------------------------------------------------------------------- |
| 148 | # Installing |
| 149 | |
| 150 | install(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 | |
| 157 | install(DIRECTORY include/ckw |
| 158 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 159 | ) |