|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | + |
| 3 | +# Project configuration |
| 4 | +project(VeraCryptSDK |
| 5 | + VERSION 1.26.24 |
| 6 | + DESCRIPTION "VeraCrypt SDK for creating encrypted volumes" |
| 7 | + LANGUAGES CXX |
| 8 | +) |
| 9 | + |
| 10 | +# Set C++ standard |
| 11 | +set(CMAKE_CXX_STANDARD 17) |
| 12 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 13 | + |
| 14 | +# Platform and architecture detection |
| 15 | +if(DEFINED CMAKE_GENERATOR_PLATFORM) |
| 16 | + string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" _platform) |
| 17 | + if(_platform STREQUAL "arm64") |
| 18 | + set(ARCH_DIR "arm64") |
| 19 | + elseif(_platform STREQUAL "x64" OR _platform STREQUAL "amd64") |
| 20 | + set(ARCH_DIR "x64") |
| 21 | + else() |
| 22 | + message(FATAL_ERROR "Unsupported generator platform: ${CMAKE_GENERATOR_PLATFORM}") |
| 23 | + endif() |
| 24 | +else() |
| 25 | + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _proc) |
| 26 | + if(_proc MATCHES "arm64" OR _proc MATCHES "aarch64") |
| 27 | + set(ARCH_DIR "arm64") |
| 28 | + elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 29 | + set(ARCH_DIR "x64") |
| 30 | + else() |
| 31 | + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") |
| 32 | + endif() |
| 33 | +endif() |
| 34 | + |
| 35 | +# Verify we're on Windows |
| 36 | +if(NOT WIN32) |
| 37 | + message(FATAL_ERROR "This SDK is currently only supported on Windows") |
| 38 | +endif() |
| 39 | + |
| 40 | +# Set output directories |
| 41 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 42 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 43 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 44 | + |
| 45 | +# For multi-config generators (Visual Studio) |
| 46 | +foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) |
| 47 | + string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG) |
| 48 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}) |
| 49 | + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}) |
| 50 | + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}) |
| 51 | +endforeach() |
| 52 | + |
| 53 | +# SDK paths |
| 54 | +set(SDK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include") |
| 55 | +set(SDK_LIB_DIR "${CMAKE_SOURCE_DIR}/lib/${ARCH_DIR}") |
| 56 | +set(SDK_BIN_DIR "${CMAKE_SOURCE_DIR}/bin/${ARCH_DIR}") |
| 57 | + |
| 58 | +# Verify SDK files exist |
| 59 | +if(NOT EXISTS "${SDK_INCLUDE_DIR}/VeraCryptFormatSDK.h") |
| 60 | + message(FATAL_ERROR "SDK header file not found: ${SDK_INCLUDE_DIR}/VeraCryptFormatSDK.h") |
| 61 | +endif() |
| 62 | + |
| 63 | +if(NOT EXISTS "${SDK_LIB_DIR}/VeraCryptFormat.lib") |
| 64 | + message(FATAL_ERROR "SDK library file not found: ${SDK_LIB_DIR}/VeraCryptFormat.lib") |
| 65 | +endif() |
| 66 | + |
| 67 | +if(NOT EXISTS "${SDK_BIN_DIR}/VeraCryptFormat.dll") |
| 68 | + message(FATAL_ERROR "SDK DLL file not found: ${SDK_BIN_DIR}/VeraCryptFormat.dll") |
| 69 | +endif() |
| 70 | + |
| 71 | +# Create imported target for VeraCrypt Format library |
| 72 | +add_library(VeraCryptFormat SHARED IMPORTED) |
| 73 | +set_target_properties(VeraCryptFormat PROPERTIES |
| 74 | + IMPORTED_LOCATION "${SDK_BIN_DIR}/VeraCryptFormat.dll" |
| 75 | + IMPORTED_IMPLIB "${SDK_LIB_DIR}/VeraCryptFormat.lib" |
| 76 | + INTERFACE_INCLUDE_DIRECTORIES "${SDK_INCLUDE_DIR}" |
| 77 | +) |
| 78 | + |
| 79 | +# Sample tool executable |
| 80 | +add_executable(VeraCryptFormatTool |
| 81 | + VeraCryptFormatTool.cpp |
| 82 | +) |
| 83 | + |
| 84 | +# Link the sample tool with the SDK and required system libraries |
| 85 | +target_link_libraries(VeraCryptFormatTool |
| 86 | + PRIVATE |
| 87 | + VeraCryptFormat |
| 88 | + shlwapi |
| 89 | +) |
| 90 | + |
| 91 | +# Set target properties |
| 92 | +set_target_properties(VeraCryptFormatTool PROPERTIES |
| 93 | + WIN32_EXECUTABLE TRUE |
| 94 | + OUTPUT_NAME "VeraCryptFormatTool" |
| 95 | +) |
| 96 | + |
| 97 | +# Compiler-specific settings |
| 98 | +if(MSVC) |
| 99 | + # Enable UTF-8 source code encoding |
| 100 | + target_compile_options(VeraCryptFormatTool PRIVATE /utf-8) |
| 101 | + |
| 102 | + # Set warning level |
| 103 | + target_compile_options(VeraCryptFormatTool PRIVATE /W3) |
| 104 | + |
| 105 | + # Define WIN32_LEAN_AND_MEAN to reduce Windows header bloat |
| 106 | + target_compile_definitions(VeraCryptFormatTool PRIVATE WIN32_LEAN_AND_MEAN) |
| 107 | + |
| 108 | + # Enable security features |
| 109 | + target_compile_options(VeraCryptFormatTool PRIVATE /GS) |
| 110 | + target_link_options(VeraCryptFormatTool PRIVATE /NXCOMPAT /DYNAMICBASE) |
| 111 | + |
| 112 | + # Set subsystem to console |
| 113 | + set_target_properties(VeraCryptFormatTool PROPERTIES |
| 114 | + LINK_FLAGS "/SUBSYSTEM:CONSOLE" |
| 115 | + ) |
| 116 | +endif() |
| 117 | + |
| 118 | +# Copy DLL to output directory after build |
| 119 | +add_custom_command(TARGET VeraCryptFormatTool POST_BUILD |
| 120 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 121 | + "${SDK_BIN_DIR}/VeraCryptFormat.dll" |
| 122 | + "$<TARGET_FILE_DIR:VeraCryptFormatTool>/VeraCryptFormat.dll" |
| 123 | + COMMENT "Copying VeraCryptFormat.dll to output directory" |
| 124 | +) |
| 125 | + |
| 126 | +# Install configuration |
| 127 | +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 128 | + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE) |
| 129 | +endif() |
| 130 | + |
| 131 | +# Install the sample tool |
| 132 | +install(TARGETS VeraCryptFormatTool |
| 133 | + RUNTIME DESTINATION bin |
| 134 | + COMPONENT Applications |
| 135 | +) |
| 136 | + |
| 137 | +# Install the DLL |
| 138 | +install(FILES "${SDK_BIN_DIR}/VeraCryptFormat.dll" |
| 139 | + DESTINATION bin |
| 140 | + COMPONENT Runtime |
| 141 | +) |
| 142 | + |
| 143 | +# Install SDK files for development |
| 144 | +install(FILES "${SDK_INCLUDE_DIR}/VeraCryptFormatSDK.h" |
| 145 | + DESTINATION include |
| 146 | + COMPONENT Development |
| 147 | +) |
| 148 | + |
| 149 | +install(FILES "${SDK_LIB_DIR}/VeraCryptFormat.lib" |
| 150 | + DESTINATION lib |
| 151 | + COMPONENT Development |
| 152 | +) |
| 153 | + |
| 154 | +# Install documentation |
| 155 | +install(FILES |
| 156 | + README.md |
| 157 | + LICENSE |
| 158 | + DESTINATION . |
| 159 | + COMPONENT Documentation |
| 160 | +) |
| 161 | + |
| 162 | +# Package configuration |
| 163 | +set(CPACK_PACKAGE_NAME "VeraCryptSDK") |
| 164 | +set(CPACK_PACKAGE_VENDOR "VeraCrypt") |
| 165 | +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "VeraCrypt SDK for creating encrypted volumes") |
| 166 | +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
| 167 | +set(CPACK_PACKAGE_INSTALL_DIRECTORY "VeraCryptSDK") |
| 168 | + |
| 169 | +# Package components |
| 170 | +set(CPACK_COMPONENTS_ALL Applications Runtime Development Documentation) |
| 171 | +set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "Sample Tool") |
| 172 | +set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "VeraCryptFormatTool sample application") |
| 173 | +set(CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "Runtime Libraries") |
| 174 | +set(CPACK_COMPONENT_RUNTIME_DESCRIPTION "Required DLL files") |
| 175 | +set(CPACK_COMPONENT_DEVELOPMENT_DISPLAY_NAME "Development Files") |
| 176 | +set(CPACK_COMPONENT_DEVELOPMENT_DESCRIPTION "Headers and import libraries for development") |
| 177 | +set(CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "Documentation") |
| 178 | +set(CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION "README and license files") |
| 179 | + |
| 180 | +# Set component dependencies |
| 181 | +set(CPACK_COMPONENT_APPLICATIONS_DEPENDS Runtime) |
| 182 | +set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS Runtime) |
| 183 | + |
| 184 | +# Generator specific settings |
| 185 | +if(WIN32) |
| 186 | + set(CPACK_GENERATOR "ZIP;NSIS") |
| 187 | + set(CPACK_NSIS_DISPLAY_NAME "VeraCrypt SDK") |
| 188 | + set(CPACK_NSIS_PACKAGE_NAME "VeraCrypt SDK") |
| 189 | + set(CPACK_NSIS_MODIFY_PATH ON) |
| 190 | +endif() |
| 191 | + |
| 192 | +# Set CPACK_SYSTEM_NAME to match target architecture for correct package naming |
| 193 | +if(DEFINED CMAKE_GENERATOR_PLATFORM) |
| 194 | + string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" _platform) |
| 195 | + if(_platform STREQUAL "arm64") |
| 196 | + set(CPACK_SYSTEM_NAME "Windows-ARM64") |
| 197 | + elseif(_platform STREQUAL "x64" OR _platform STREQUAL "amd64") |
| 198 | + set(CPACK_SYSTEM_NAME "Windows-x64") |
| 199 | + endif() |
| 200 | +else() |
| 201 | + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _proc) |
| 202 | + if(_proc MATCHES "arm64" OR _proc MATCHES "aarch64") |
| 203 | + set(CPACK_SYSTEM_NAME "Windows-ARM64") |
| 204 | + elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 205 | + set(CPACK_SYSTEM_NAME "Windows-x64") |
| 206 | + endif() |
| 207 | +endif() |
| 208 | + |
| 209 | +include(CPack) |
| 210 | + |
| 211 | +# Print configuration summary |
| 212 | +message(STATUS "VeraCrypt SDK Configuration Summary:") |
| 213 | +message(STATUS " Architecture: ${ARCH_DIR}") |
| 214 | +message(STATUS " SDK Include: ${SDK_INCLUDE_DIR}") |
| 215 | +message(STATUS " SDK Library: ${SDK_LIB_DIR}") |
| 216 | +message(STATUS " SDK DLL: ${SDK_BIN_DIR}") |
| 217 | +message(STATUS " Install Prefix: ${CMAKE_INSTALL_PREFIX}") |
| 218 | +message(STATUS " C++ Standard: ${CMAKE_CXX_STANDARD}") |
| 219 | + |
| 220 | +# Optional: Add testing support |
| 221 | +enable_testing() |
| 222 | + |
| 223 | +# Add a simple test to verify the tool can be executed |
| 224 | +add_test(NAME VeraCryptFormatTool_Help |
| 225 | + COMMAND VeraCryptFormatTool --help |
| 226 | +) |
| 227 | + |
| 228 | +# Set test properties |
| 229 | +set_tests_properties(VeraCryptFormatTool_Help PROPERTIES |
| 230 | + PASS_REGULAR_EXPRESSION "Usage: VeraCryptFormatTool" |
| 231 | +) |
| 232 | + |
| 233 | +# Print build instructions |
| 234 | +message(STATUS "") |
| 235 | +message(STATUS "Build Instructions:") |
| 236 | +message(STATUS " mkdir build && cd build") |
| 237 | +message(STATUS " cmake ..") |
| 238 | +message(STATUS " cmake --build . --config Release") |
| 239 | +message(STATUS "") |
| 240 | +message(STATUS "Install Instructions:") |
| 241 | +message(STATUS " cmake --install . --config Release") |
| 242 | +message(STATUS "") |
| 243 | +message(STATUS "Package Instructions:") |
| 244 | +message(STATUS " cpack -C Release") |
0 commit comments