-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
83 lines (66 loc) · 3.19 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 3.24 is needed for LINK_LIBRARY:WHOLE_ARCHIVE support
cmake_minimum_required(VERSION 3.24)
project(vodozemac-cpp VERSION 1.0.0 LANGUAGES CXX)
set(ECM_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_DIR})
# Work around some weird CI problems; TODO: Figure out what's going on there
option(CI_BUILD FALSE)
if (${CI_BUILD})
set(BUILD_FOLDER_PREFIX "x64/Debug/")
endif()
include(ECMSetupVersion)
ecm_setup_version(PROJECT
VARIABLE_PREFIX VODOZEMAC
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/VodozemacCppConfigVersion.cmake"
SOVERSION 1
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/VodozemacCpp")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/VodozemacCppConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/VodozemacCppConfig.cmake"
INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
)
find_package(Corrosion REQUIRED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
corrosion_import_crate(
MANIFEST_PATH Cargo.toml
)
# We create our own shared library instead of having Cargo do it
# To work around https://github.com/dtolnay/cxx/issues/1331
add_library(vodozemac-cpp SHARED)
# We need a dummy file so CMake will have something to link with
target_sources(vodozemac-cpp PRIVATE src/dummy.cpp)
# We need to link to the whole archive, otherwise important symbols are thrown away
target_link_libraries(vodozemac-cpp PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,vodozemac-static>")
if(WIN32)
target_link_libraries(vodozemac-cpp PRIVATE Bcrypt.lib)
endif()
target_include_directories(vodozemac-cpp INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/VodozemacCpp>")
set_target_properties(vodozemac-cpp PROPERTIES
VERSION ${VODOZEMAC_VERSION}
SOVERSION ${VODOZEMAC_SOVERSION}
)
# We need to copy this file manually, as it's a symlink and CMake will erroneously try to install it as such
if(WIN32)
add_custom_target(copy_header ALL DEPENDS cargo-build_vodozemac BYPRODUCTS ${CMAKE_BINARY_DIR}/vodozemac.h VERBATIM COMMAND
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${BUILD_FOLDER_PREFIX}cargo/build/${Rust_CARGO_TARGET}/cxxbridge/vodozemac/src/lib.rs.h ${CMAKE_BINARY_DIR}/vodozemac.h)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT")
else()
add_custom_target(copy_header ALL DEPENDS cargo-build_vodozemac BYPRODUCTS ${CMAKE_BINARY_DIR}/vodozemac.h VERBATIM COMMAND
cp -L ${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET}/cxxbridge/vodozemac/src/lib.rs.h ${CMAKE_BINARY_DIR}/vodozemac.h)
endif()
install(TARGETS vodozemac-cpp EXPORT VodozemacTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES
"${CMAKE_BINARY_DIR}/vodozemac.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/VodozemacCpp COMPONENT Devel
)
install(FILES
"${PROJECT_BINARY_DIR}/VodozemacCppConfig.cmake"
"${PROJECT_BINARY_DIR}/VodozemacCppConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel
)
install(EXPORT VodozemacTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE VodozemacTargets.cmake NAMESPACE Vodozemac::)