blob: 79dae7145c5c8d72f7d0dfbbfff98934ea675d3a [file] [log] [blame]
Stella Laurenzo309dc5b2023-02-22 23:07:43 -08001# Copyright 2023 The IREE Authors
2#
3# Licensed under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -07006
Stanley Winatad413a7e2023-10-04 10:40:32 -07007# On Windows, DLLs go to the runtime directory and import
8# libraries go to the lib directory.
9# TODO: We should really be dumping binaries into bin/ not
10# tools/. This must line up with binaries built this way because
11# DLLs must be in the same directory as the binary.
Scott Todd3f51a552024-04-19 11:00:27 -070012# See: https://github.com/iree-org/iree/issues/11297
Stanley Winatad413a7e2023-10-04 10:40:32 -070013set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/tools")
14set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
15set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
16if(WIN32)
17 set(IREE_COMPILER_DYLIB_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
18 set(IREE_COMPILER_DYLIB_INSTALL_PREFIX "bin/")
19else()
20 set(IREE_COMPILER_DYLIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
21 set(IREE_COMPILER_DYLIB_INSTALL_PREFIX "lib/")
22endif()
23
Stella Laurenzo309dc5b2023-02-22 23:07:43 -080024# Always build the C bindings, since the API is available apart from
25# actually building the compiler.
26add_subdirectory(bindings/c)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070027
Stella Laurenzo309dc5b2023-02-22 23:07:43 -080028# The compiler implementation is gated on the global setting.
29if(IREE_BUILD_COMPILER)
Stella Laurenzo2eb68622023-11-10 17:04:46 -080030 # Force enable BUILD_SHARED_LIBS for the compiler if instructed.
31 set(_IREE_ORIG_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
32 if(IREE_COMPILER_BUILD_SHARED_LIBS)
33 set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
34 endif()
35
Stella Laurenzoc6092c42023-03-25 19:55:37 -070036 # Must configure plugins before processing the compiler sources so that
37 # the static link list can be set.
Stella Laurenzo2eb68622023-11-10 17:04:46 -080038 iree_include_cmake_plugin_dirs(
39 LOG_LABEL
40 compiler
41 BINARY_DIR
42 "${IREE_BINARY_DIR}/compiler/plugins"
43 PLUGIN_CMAKE_FILE
44 "iree_compiler_plugin.cmake"
45 )
Stella Laurenzo309dc5b2023-02-22 23:07:43 -080046 add_subdirectory(src)
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070047
Stella Laurenzo2eb68622023-11-10 17:04:46 -080048 # Reset BUILD_SHARED_LIBS.
49 set(BUILD_SHARED_LIBS ${_IREE_ORIG_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
50
Stella Laurenzo309dc5b2023-02-22 23:07:43 -080051 # Copy Python packaging files to the build dir so that we can install from
52 # there.
53 if(IREE_BUILD_PYTHON_BINDINGS)
54 configure_file(pyproject.toml pyproject.toml COPYONLY)
55 configure_file(setup.py setup.py @ONLY)
Stella Laurenzo6dd9de82023-03-07 19:02:25 -080056 add_subdirectory(bindings/python)
Stella Laurenzo309dc5b2023-02-22 23:07:43 -080057 endif()
Stanley Winatad413a7e2023-10-04 10:40:32 -070058
59 # Post processing.
Ben Vanikeb49f722024-04-24 13:16:13 -070060 get_property(_iree_compiler_depends GLOBAL PROPERTY IREE_COMPILER_DEPENDS)
61 if(_iree_compiler_depends)
62 add_dependencies(iree_compiler_API_SharedImpl ${_iree_compiler_depends})
63 add_dependencies(iree_compiler_API_StaticImpl ${_iree_compiler_depends})
Stanley Winatad413a7e2023-10-04 10:40:32 -070064 endif()
Stella Laurenzo41a2ceb2022-04-29 12:49:36 -070065endif()