mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-14 17:58:40 +00:00
cmake: add flags to only build the compiler
... and to use an external compiler For example, this is how one only build the compiler: ``` cmake .. -DSLINT_BUILD_RUNTIME=OFF -DCMAKE_INSTALL_PREFIX=/tmp/slint_compiler make install ``` And this only build the runtime ``` cmake .. -DSLINT_FEATURE_COMPILER=OFF -DCMAKE_INSTALL_PREFIX=/tmp/install_runtime make install ``` And then this can be used in a project like so: ``` cmake .. -DCMAKE_PREFIX_PATH=/tmp/install_runtime/ -DSLINT_COMPILER=/tmp/install_compiler/bin/slint-compiler ```
This commit is contained in:
parent
d299f0bf3e
commit
14f7fe4ba2
5 changed files with 265 additions and 243 deletions
|
|
@ -23,6 +23,7 @@ All notable changes to this project are documented in this file.
|
||||||
### C++
|
### C++
|
||||||
|
|
||||||
- Removed the need for C++ exceptions in generated code.
|
- Removed the need for C++ exceptions in generated code.
|
||||||
|
- Added ability to only build the Slint compiler or use an external compiler.
|
||||||
|
|
||||||
### LSP
|
### LSP
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ add_feature_info(SLINT_BUILD_EXAMPLES SLINT_BUILD_EXAMPLES "configure whether to
|
||||||
if(SLINT_BUILD_EXAMPLES)
|
if(SLINT_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif()
|
endif()
|
||||||
if(SLINT_BUILD_TESTING)
|
if(SLINT_BUILD_TESTING AND (SLINT_FEATURE_COMPILER OR SLINT_COMPILER))
|
||||||
add_subdirectory(docs/tutorial/cpp/src/)
|
add_subdirectory(docs/tutorial/cpp/src/)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,63 +20,13 @@ find_package(Rust 1.70 REQUIRED MODULE)
|
||||||
|
|
||||||
option(BUILD_SHARED_LIBS "Build Slint as shared library" ON)
|
option(BUILD_SHARED_LIBS "Build Slint as shared library" ON)
|
||||||
option(SLINT_FEATURE_COMPILER "Enable support for compiling .slint files to C++ ahead of time" ON)
|
option(SLINT_FEATURE_COMPILER "Enable support for compiling .slint files to C++ ahead of time" ON)
|
||||||
|
add_feature_info(SLINT_FEATURE_COMPILER SLINT_FEATURE_COMPILER "Enable support for compiling .slint files to C++ ahead of time")
|
||||||
|
option(SLINT_BUILD_RUNTIME "Actually build the Slint runtime libraries (Disable that to only build the compiler)" ON)
|
||||||
|
add_feature_info(SLINT_BUILD_RUNTIME SLINT_BUILD_RUNTIME "Actually build the Slint runtime libraries (Disable that to only build the compiler)")
|
||||||
|
|
||||||
if(SLINT_FEATURE_COMPILER)
|
set(SLINT_COMPILER "" CACHE STRING "Path to the slint-compiler executable. When unset, it the compiler will be build as part of the build process")
|
||||||
set(slint_compiler_crate "slint-compiler")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(BUILD_SHARED_LIBS)
|
|
||||||
set(rustc_lib_type "cdylib")
|
|
||||||
set(slint_cpp_impl "slint-cpp-shared")
|
|
||||||
set(cmake_lib_type "SHARED")
|
|
||||||
else()
|
|
||||||
set(rustc_lib_type "staticlib")
|
|
||||||
set(slint_cpp_impl "slint-cpp-static")
|
|
||||||
set(cmake_lib_type "STATIC")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml"
|
|
||||||
CRATES slint-cpp ${slint_compiler_crate} CRATE_TYPES bin ${rustc_lib_type})
|
|
||||||
|
|
||||||
set(SLINT_LIBRARY_CARGO_FLAGS "" CACHE STRING
|
set(SLINT_LIBRARY_CARGO_FLAGS "" CACHE STRING
|
||||||
"Flags to pass to cargo when building the Slint runtime library")
|
"Flags to pass to cargo when building the Slint runtime library")
|
||||||
if(SLINT_LIBRARY_CARGO_FLAGS)
|
|
||||||
corrosion_set_cargo_flags(slint-cpp ${SLINT_LIBRARY_CARGO_FLAGS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# When doing "make install" package builds, set install_name to rpath, so that the installed
|
|
||||||
# binaries don't have a load-command pointing back to their build directory.
|
|
||||||
# Don't do this when Slint is used via FetchContent. While we could set CMAKE_BUILD_RPATH to
|
|
||||||
# include the binary dir and thus our examples would have the correct rpath set, binaries
|
|
||||||
# outside (i.e. applications using Slint via FetchContent) would not and the BUILD_RPATH
|
|
||||||
# target property doesn't propagate :(
|
|
||||||
if (APPLE AND SLINT_IS_TOPLEVEL_BUILD AND BUILD_SHARED_LIBS)
|
|
||||||
# corrosion could provide the Cargo.toml package version as a CMake target property.
|
|
||||||
corrosion_add_target_local_rustflags(slint-cpp -Clink-arg=-Wl,-install_name,@rpath/libslint_cpp.dylib,-current_version,${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR},-compatibility_version,${PROJECT_VERSION_MAJOR}.0)
|
|
||||||
# Set this one to false again explicitely because Corrosion will starting setting this property to true by default.
|
|
||||||
set_target_properties(slint-cpp-shared PROPERTIES IMPORTED_NO_SONAME 0)
|
|
||||||
set_target_properties(slint-cpp-shared PROPERTIES IMPORTED_SONAME libslint_cpp.dylib)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set_property(
|
|
||||||
TARGET slint-cpp
|
|
||||||
APPEND
|
|
||||||
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
|
|
||||||
"SLINT_GENERATED_INCLUDE_DIR=${CMAKE_CURRENT_BINARY_DIR}/generated_include/"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(SLINT_FEATURE_COMPILER)
|
|
||||||
corrosion_set_hostbuild(slint-compiler)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(Slint INTERFACE)
|
|
||||||
add_library(Slint::Slint ALIAS Slint)
|
|
||||||
target_link_libraries(Slint INTERFACE slint-cpp)
|
|
||||||
target_compile_features(Slint INTERFACE cxx_std_20)
|
|
||||||
if (MSVC)
|
|
||||||
target_compile_options(Slint INTERFACE /bigobj)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
function(define_cargo_feature cargo-feature description default)
|
function(define_cargo_feature cargo-feature description default)
|
||||||
# turn foo-bar into SLINT_FEATURE_FOO_BAR
|
# turn foo-bar into SLINT_FEATURE_FOO_BAR
|
||||||
|
|
@ -148,8 +98,57 @@ define_cargo_dependent_feature(backend-linuxkms "Enable support for the backend
|
||||||
define_cargo_dependent_feature(gettext "Enable support of translations using gettext" OFF "NOT SLINT_FEATURE_FREESTANDING")
|
define_cargo_dependent_feature(gettext "Enable support of translations using gettext" OFF "NOT SLINT_FEATURE_FREESTANDING")
|
||||||
define_cargo_dependent_feature(accessibility "Enable integration with operating system provided accessibility APIs" ON "NOT SLINT_FEATURE_FREESTANDING")
|
define_cargo_dependent_feature(accessibility "Enable integration with operating system provided accessibility APIs" ON "NOT SLINT_FEATURE_FREESTANDING")
|
||||||
|
|
||||||
if (SLINT_FEATURE_FREESTANDING)
|
if (SLINT_BUILD_RUNTIME)
|
||||||
|
if(SLINT_FEATURE_COMPILER AND NOT SLINT_COMPILER)
|
||||||
|
set(slint_compiler_crate "slint-compiler")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_SHARED_LIBS)
|
||||||
|
set(rustc_lib_type "cdylib")
|
||||||
|
set(slint_cpp_impl "slint-cpp-shared")
|
||||||
|
set(cmake_lib_type "SHARED")
|
||||||
|
else()
|
||||||
|
set(rustc_lib_type "staticlib")
|
||||||
|
set(slint_cpp_impl "slint-cpp-static")
|
||||||
|
set(cmake_lib_type "STATIC")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml"
|
||||||
|
CRATES slint-cpp ${slint_compiler_crate} CRATE_TYPES bin ${rustc_lib_type})
|
||||||
|
elseif(SLINT_FEATURE_COMPILER AND NOT SLINT_COMPILER)
|
||||||
|
corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml"
|
||||||
|
CRATES slint-compiler CRATE_TYPES bin)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SLINT_FEATURE_COMPILER AND NOT SLINT_COMPILER)
|
||||||
|
corrosion_set_hostbuild(slint-compiler)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (SLINT_BUILD_RUNTIME)
|
||||||
|
|
||||||
|
# When doing "make install" package builds, set install_name to rpath, so that the installed
|
||||||
|
# binaries don't have a load-command pointing back to their build directory.
|
||||||
|
# Don't do this when Slint is used via FetchContent. While we could set CMAKE_BUILD_RPATH to
|
||||||
|
# include the binary dir and thus our examples would have the correct rpath set, binaries
|
||||||
|
# outside (i.e. applications using Slint via FetchContent) would not and the BUILD_RPATH
|
||||||
|
# target property doesn't propagate :(
|
||||||
|
if (APPLE AND SLINT_IS_TOPLEVEL_BUILD AND BUILD_SHARED_LIBS)
|
||||||
|
# corrosion could provide the Cargo.toml package version as a CMake target property.
|
||||||
|
corrosion_add_target_local_rustflags(slint-cpp -Clink-arg=-Wl,-install_name,@rpath/libslint_cpp.dylib,-current_version,${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR},-compatibility_version,${PROJECT_VERSION_MAJOR}.0)
|
||||||
|
# Set this one to false again explicitely because Corrosion will starting setting this property to true by default.
|
||||||
|
set_target_properties(slint-cpp-shared PROPERTIES IMPORTED_NO_SONAME 0)
|
||||||
|
set_target_properties(slint-cpp-shared PROPERTIES IMPORTED_SONAME libslint_cpp.dylib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(Slint INTERFACE)
|
||||||
|
add_library(Slint::Slint ALIAS Slint)
|
||||||
|
target_link_libraries(Slint INTERFACE slint-cpp)
|
||||||
|
target_compile_features(Slint INTERFACE cxx_std_20)
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_options(Slint INTERFACE /bigobj)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (SLINT_FEATURE_FREESTANDING)
|
||||||
if (ESP_PLATFORM)
|
if (ESP_PLATFORM)
|
||||||
list(APPEND features "esp-backtrace/${IDF_TARGET}")
|
list(APPEND features "esp-backtrace/${IDF_TARGET}")
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -157,6 +156,14 @@ else (SLINT_FEATURE_FREESTANDING)
|
||||||
list(APPEND features std)
|
list(APPEND features std)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TARGET slint-cpp
|
||||||
|
APPEND
|
||||||
|
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
|
||||||
|
"SLINT_GENERATED_INCLUDE_DIR=${CMAKE_CURRENT_BINARY_DIR}/generated_include/"
|
||||||
|
)
|
||||||
|
|
||||||
set_property(
|
set_property(
|
||||||
TARGET slint-cpp
|
TARGET slint-cpp
|
||||||
PROPERTY CORROSION_FEATURES
|
PROPERTY CORROSION_FEATURES
|
||||||
|
|
@ -168,6 +175,10 @@ set_property(
|
||||||
ON
|
ON
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(SLINT_LIBRARY_CARGO_FLAGS)
|
||||||
|
corrosion_set_cargo_flags(slint-cpp ${SLINT_LIBRARY_CARGO_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SLINT_FEATURE_BACKEND_QT)
|
if(SLINT_FEATURE_BACKEND_QT)
|
||||||
# For the CMake build don't rely on qmake being in PATH but use CMake to locate Qt. This
|
# For the CMake build don't rely on qmake being in PATH but use CMake to locate Qt. This
|
||||||
# means usually CMAKE_PREFIX_PATH is set.
|
# means usually CMAKE_PREFIX_PATH is set.
|
||||||
|
|
@ -301,7 +312,8 @@ target_include_directories(Slint INTERFACE
|
||||||
$<INSTALL_INTERFACE:include/slint>
|
$<INSTALL_INTERFACE:include/slint>
|
||||||
)
|
)
|
||||||
|
|
||||||
if(SLINT_FEATURE_COMPILER)
|
|
||||||
|
if(SLINT_FEATURE_COMPILER AND NOT SLINT_COMPILER)
|
||||||
add_executable(Slint::slint-compiler ALIAS slint-compiler)
|
add_executable(Slint::slint-compiler ALIAS slint-compiler)
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/SlintMacro.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/SlintMacro.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -312,19 +324,24 @@ install(EXPORT SlintTargets NAMESPACE Slint:: DESTINATION lib/cmake/Slint)
|
||||||
install(TARGETS Slint slint-cpp
|
install(TARGETS Slint slint-cpp
|
||||||
EXPORT SlintTargets LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/slint)
|
EXPORT SlintTargets LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/slint)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
include(GNUInstallDirs)
|
|
||||||
|
|
||||||
install(FILES $<TARGET_FILE:${slint_cpp_impl}> TYPE LIB)
|
install(FILES $<TARGET_FILE:${slint_cpp_impl}> TYPE LIB)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
install(FILES $<TARGET_LINKER_FILE:${slint_cpp_impl}> TYPE LIB)
|
install(FILES $<TARGET_LINKER_FILE:${slint_cpp_impl}> TYPE LIB)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SLINT_FEATURE_COMPILER)
|
endif(SLINT_BUILD_RUNTIME)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
|
||||||
|
if(SLINT_FEATURE_COMPILER AND NOT SLINT_COMPILER)
|
||||||
install(PROGRAMS $<TARGET_FILE:slint-compiler> TYPE BIN)
|
install(PROGRAMS $<TARGET_FILE:slint-compiler> TYPE BIN)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(SLINT_BUILD_RUNTIME)
|
||||||
|
|
||||||
# Corrosion sets the `IMPORTED` locations late to allow us to set OUTPUT_DIRECTORY
|
# Corrosion sets the `IMPORTED` locations late to allow us to set OUTPUT_DIRECTORY
|
||||||
# target properties. This function must be deferred until after Corrosion set the
|
# target properties. This function must be deferred until after Corrosion set the
|
||||||
# locations. Since we are writing to a config file Generator expressions are not
|
# locations. Since we are writing to a config file Generator expressions are not
|
||||||
|
|
@ -358,15 +375,9 @@ write_basic_package_version_file(
|
||||||
install(FILES
|
install(FILES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/Slint/SlintConfig.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/Slint/SlintConfig.cmake"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/Slint/SlintConfigVersion.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/Slint/SlintConfigVersion.cmake"
|
||||||
DESTINATION lib/cmake/Slint
|
|
||||||
)
|
|
||||||
|
|
||||||
if(SLINT_FEATURE_COMPILER)
|
|
||||||
install(FILES
|
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/cmake/SlintMacro.cmake"
|
"${CMAKE_CURRENT_LIST_DIR}/cmake/SlintMacro.cmake"
|
||||||
DESTINATION lib/cmake/Slint
|
DESTINATION lib/cmake/Slint
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
option(SLINT_PACKAGE_BUNDLE_QT "Internal setting to install Qt binary in the packages" OFF)
|
option(SLINT_PACKAGE_BUNDLE_QT "Internal setting to install Qt binary in the packages" OFF)
|
||||||
|
|
||||||
|
|
@ -399,6 +410,8 @@ if(SLINT_PACKAGE_BUNDLE_QT)
|
||||||
endif()
|
endif()
|
||||||
endif(SLINT_PACKAGE_BUNDLE_QT)
|
endif(SLINT_PACKAGE_BUNDLE_QT)
|
||||||
|
|
||||||
|
endif(SLINT_BUILD_RUNTIME)
|
||||||
|
|
||||||
set(CPACK_PACKAGE_NAME "Slint-cpp")
|
set(CPACK_PACKAGE_NAME "Slint-cpp")
|
||||||
set(CPACK_PACKAGE_VENDOR "Slint")
|
set(CPACK_PACKAGE_VENDOR "Slint")
|
||||||
set(CPACK_VERBATIM_VARIABLES true)
|
set(CPACK_VERBATIM_VARIABLES true)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,13 @@ endif()
|
||||||
add_library(@slint_cpp_impl@ @cmake_lib_type@ IMPORTED)
|
add_library(@slint_cpp_impl@ @cmake_lib_type@ IMPORTED)
|
||||||
set_target_properties(@slint_cpp_impl@ PROPERTIES @SLINT_LIB_PROPERTIES@)
|
set_target_properties(@slint_cpp_impl@ PROPERTIES @SLINT_LIB_PROPERTIES@)
|
||||||
|
|
||||||
if (@SLINT_FEATURE_COMPILER@)
|
set(SLINT_COMPILER @SLINT_COMPILER@ CACHE STRING "Path to the slint-compiler executable")
|
||||||
|
if (SLINT_COMPILER)
|
||||||
|
set(SLINT_STYLE @_SLINT_STYLE@ CACHE STRING "The Slint widget style")
|
||||||
|
add_executable(Slint::slint-compiler IMPORTED GLOBAL)
|
||||||
|
set_target_properties(Slint::slint-compiler PROPERTIES IMPORTED_LOCATION ${SLINT_COMPILER})
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/SlintMacro.cmake")
|
||||||
|
elseif (@SLINT_FEATURE_COMPILER@)
|
||||||
add_executable(Slint::slint-compiler IMPORTED GLOBAL)
|
add_executable(Slint::slint-compiler IMPORTED GLOBAL)
|
||||||
set_target_properties(Slint::slint-compiler PROPERTIES IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_BINDIR@/slint-compiler${CMAKE_EXECUTABLE_SUFFIX}")
|
set_target_properties(Slint::slint-compiler PROPERTIES IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_BINDIR@/slint-compiler${CMAKE_EXECUTABLE_SUFFIX}")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/SlintMacro.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/SlintMacro.cmake")
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,9 @@ if(NOT SLINT_FEATURE_FREESTANDING)
|
||||||
endif()
|
endif()
|
||||||
slint_test(models)
|
slint_test(models)
|
||||||
|
|
||||||
|
if(SLINT_FEATURE_COMPILER OR SLINT_COMPILER)
|
||||||
add_subdirectory(multiple-includes)
|
add_subdirectory(multiple-includes)
|
||||||
|
endif()
|
||||||
|
|
||||||
slint_test(platform_eventloop)
|
slint_test(platform_eventloop)
|
||||||
target_link_libraries(test_platform_eventloop PRIVATE Threads::Threads)
|
target_link_libraries(test_platform_eventloop PRIVATE Threads::Threads)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue