Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Fix build with nightly Rust #5078

Merged
merged 1 commit into from Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions api/cpp/CMakeLists.txt
Expand Up @@ -113,11 +113,11 @@ if (SLINT_BUILD_RUNTIME)

if(BUILD_SHARED_LIBS)
set(rustc_lib_type "cdylib")
set(slint_cpp_impl "slint-cpp-shared")
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(slint_cpp_impl "slint_cpp-static")
set(cmake_lib_type "STATIC")
endif()

Expand All @@ -142,15 +142,15 @@ if (SLINT_BUILD_RUNTIME)
# 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)
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)
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_link_libraries(Slint INTERFACE slint_cpp)
target_compile_features(Slint INTERFACE cxx_std_20)
if (MSVC)
target_compile_options(Slint INTERFACE /bigobj)
Expand All @@ -167,25 +167,25 @@ if (SLINT_BUILD_RUNTIME)


set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
"SLINT_GENERATED_INCLUDE_DIR=${CMAKE_CURRENT_BINARY_DIR}/generated_include/"
)

set_property(
TARGET slint-cpp
TARGET slint_cpp
PROPERTY CORROSION_FEATURES
${features}
)
set_property(
TARGET slint-cpp
TARGET slint_cpp
PROPERTY CORROSION_NO_DEFAULT_FEATURES
ON
)

if(SLINT_LIBRARY_CARGO_FLAGS)
corrosion_set_cargo_flags(slint-cpp ${SLINT_LIBRARY_CARGO_FLAGS})
corrosion_set_cargo_flags(slint_cpp ${SLINT_LIBRARY_CARGO_FLAGS})
endif()

if(SLINT_FEATURE_BACKEND_QT)
Expand All @@ -200,14 +200,14 @@ if (SLINT_BUILD_RUNTIME)

if(SLINT_FEATURE_BACKEND_QT AND TARGET Qt::qmake)
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
QMAKE=$<TARGET_PROPERTY:Qt::qmake,LOCATION>
)
else()
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
SLINT_NO_QT=1
Expand Down Expand Up @@ -241,7 +241,7 @@ if (SLINT_BUILD_RUNTIME)
# to build time.
if(DEFINED ENV{PKG_CONFIG_SYSROOT_DIR})
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
"PKG_CONFIG_SYSROOT_DIR=$ENV{PKG_CONFIG_SYSROOT_DIR}"
Expand All @@ -253,15 +253,15 @@ if (SLINT_BUILD_RUNTIME)
find_program(CLANGCXX clang++)
if(CLANGCC AND NOT DEFINED ENV{CLANGCC})
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CLANGCC=${CLANGCC}
)
endif()
if(CLANGCXX AND NOT DEFINED ENV{CLANGCXX})
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CLANGCXX=${CLANGCXX}
Expand Down Expand Up @@ -289,13 +289,13 @@ if (SLINT_BUILD_RUNTIME)
if(host_cc)
string(REPLACE "-" "_" cargo_host_target_underscore "${Rust_CARGO_HOST_TARGET}")
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CC_${cargo_host_target_underscore}=${host_cc}
)
set_property(
TARGET slint-cpp
TARGET slint_cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CFLAGS_${cargo_host_target_underscore}=
Expand Down Expand Up @@ -354,10 +354,10 @@ if (SLINT_BUILD_RUNTIME)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/SlintMacro.cmake)
endif()

export(TARGETS Slint slint-cpp
export(TARGETS Slint slint_cpp
NAMESPACE Slint:: FILE "${CMAKE_BINARY_DIR}/lib/cmake/Slint/SlintTargets.cmake")
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)

install(FILES $<TARGET_FILE:${slint_cpp_impl}> TYPE LIB)
Expand Down
1 change: 1 addition & 0 deletions api/cpp/Cargo.toml
Expand Up @@ -20,6 +20,7 @@ links = "slint_cpp"
[lib]
path = "lib.rs"
crate-type = ["lib", "cdylib", "staticlib"]
name = "slint_cpp"

# Note, these features need to be kept in sync (along with their defaults) in
# the C++ crate's CMakeLists.txt
Expand Down