slint/api/sixtyfps-cpp/cmake/CMakeLists.txt
Simon Hausmann 547a732e33 Fix rebuild issues, part 10523
By setting RUSTFLAGS in the Cargo config we run into the situation that
when doing a host build, all rust files are compiled with the flags,
including build.rs. When cross-compiling, build.rs is not build with the
RUSTFLAGS specified. That makes kind of sense, but it also means that
all the build scripts are always recompiled when switching between a
target and a host build - and that applies to *all* packages, including
dependencies.

So short of a better solution, this patch removes the need to set
RUSTFLAGS. It was used to extract the system library dependencies for
the static library we'd create. Instead we're now building two shared
libraries and are linking against them. They contain the rust library
twice, so that's not really a desirable final state either, but
productivity wins right now :-)

It might make sense to go back to creating *one* shared library through
a dedicated crate and -- since 'pub extern "C"' functions are not
transitively exported, it may require re-exporting them by hand or using
some clever build trick perhaps.
2020-06-09 13:08:59 +02:00

71 lines
No EOL
2.2 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(SixtyFPS LANGUAGES CXX)
add_library(SixtyFPS INTERFACE)
foreach(lib_path IN LISTS SIXTYFPS_INTERNAL_LIBS)
get_filename_component(lib_name "${lib_path}" NAME_WE)
add_library(${lib_name} SHARED IMPORTED)
set_property(TARGET ${lib_name} PROPERTY IMPORTED_LOCATION "${lib_path}")
target_link_libraries(SixtyFPS INTERFACE ${lib_name})
list(APPEND internal_libs ${lib_name})
install(FILES ${lib_path} TYPE LIB)
endforeach()
if (DEFINED SIXTYFPS_EXTERNAL_LIBS)
target_link_libraries(SixtyFPS INTERFACE ${SIXTYFPS_EXTERNAL_LIBS})
endif()
set(api_headers
sixtyfps.h
sixtyfps_properties.h
sixtyfps_signals.h
sixtyfps_string.h
vtable.h
)
foreach(header IN LISTS api_headers)
set_property(TARGET SixtyFPS APPEND PROPERTY PUBLIC_HEADER ../include/${header})
endforeach()
file(GLOB_RECURSE generated_headers RELATIVE_PATH "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/include/*.h")
foreach(header IN LISTS generated_headers)
set_property(TARGET SixtyFPS APPEND PROPERTY PUBLIC_HEADER ${header})
endforeach()
target_include_directories(SixtyFPS INTERFACE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include/sixtyfps>
)
export(TARGETS SixtyFPS NAMESPACE SixtyFPS:: FILE "${CMAKE_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSTargets.cmake")
install(EXPORT SixtyFPSTargets NAMESPACE SixtyFPS:: DESTINATION lib/cmake/SixtyFPS)
install(TARGETS SixtyFPS
EXPORT SixtyFPSTargets
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/sixtyfps
)
include(CMakePackageConfigHelpers)
configure_package_config_file("SixtyFPSConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSConfig.cmake" INSTALL_DESTINATION lib/cmake/SixtyFPS)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSConfigVersion.cmake
VERSION 1.0.0
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSConfigVersion.cmake"
DESTINATION lib/cmake/SixtyFPS
)