|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | +project(BasicSpanner CXX) |
| 3 | + |
| 4 | +# Set C++ standard |
| 5 | +set(CMAKE_CXX_STANDARD 17) |
| 6 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 | + |
| 8 | +# Find required packages |
| 9 | +find_package(Qt6 REQUIRED COMPONENTS Core Widgets Charts) |
| 10 | + |
| 11 | +# Automatically handle Qt MOC, UIC, and RCC |
| 12 | +set(CMAKE_AUTOMOC ON) |
| 13 | +set(CMAKE_AUTOUIC ON) |
| 14 | +set(CMAKE_AUTORCC ON) |
| 15 | + |
| 16 | +# Define source files |
| 17 | +file(GLOB_RECURSE SOURCES "src/**/*.cpp") |
| 18 | +file(GLOB_RECURSE HEADERS "src/**/*.h") |
| 19 | + |
| 20 | +# Create executable |
| 21 | +add_executable(BasicSpanner |
| 22 | + src/main.cpp |
| 23 | + ${SOURCES} |
| 24 | + ${HEADERS} |
| 25 | +) |
| 26 | + |
| 27 | +# Create test executable |
| 28 | +file(GLOB CORE_SOURCES "src/core/*.cpp") |
| 29 | + |
| 30 | +# Create verification executable only if the source file exists |
| 31 | +if (EXISTS "${CMAKE_SOURCE_DIR}/verify_basic_network.cpp") |
| 32 | + add_executable(verify_basic_network |
| 33 | + verify_basic_network.cpp |
| 34 | + ${CORE_SOURCES} |
| 35 | + ) |
| 36 | +endif() |
| 37 | + |
| 38 | +# Link libraries |
| 39 | +target_link_libraries(BasicSpanner |
| 40 | + Qt6::Core |
| 41 | + Qt6::Widgets |
| 42 | + Qt6::Charts |
| 43 | +) |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +if (TARGET verify_basic_network) |
| 48 | + target_link_libraries(verify_basic_network |
| 49 | + Qt6::Core |
| 50 | + Qt6::Widgets |
| 51 | + Qt6::Charts |
| 52 | + ) |
| 53 | +endif() |
| 54 | + |
| 55 | +# Include directories |
| 56 | +target_include_directories(BasicSpanner PRIVATE |
| 57 | + src/core |
| 58 | + src/gui |
| 59 | + src/gui/panels |
| 60 | +) |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +if (TARGET verify_basic_network) |
| 65 | + target_include_directories(verify_basic_network PRIVATE |
| 66 | + src/core |
| 67 | + src/gui |
| 68 | + src/gui/panels |
| 69 | + ) |
| 70 | +endif() |
| 71 | + |
| 72 | +# Set properties for different build types |
| 73 | +if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 74 | + target_compile_definitions(BasicSpanner PRIVATE DEBUG_BUILD) |
| 75 | +endif() |
| 76 | + |
| 77 | +# Platform-specific settings |
| 78 | +if(WIN32) |
| 79 | + # Windows-specific settings |
| 80 | + if(MSVC) |
| 81 | + # MSVC compiler options |
| 82 | + target_compile_options(BasicSpanner PRIVATE |
| 83 | + /W3 # Warning level 3 |
| 84 | + /permissive- # Disable non-conforming code |
| 85 | + /Zc:__cplusplus # Enable correct __cplusplus macro |
| 86 | + /EHsc # Exception handling |
| 87 | + ) |
| 88 | + |
| 89 | + # Set subsystem to console for proper output |
| 90 | + set_target_properties(BasicSpanner PROPERTIES |
| 91 | + WIN32_EXECUTABLE FALSE |
| 92 | + ) |
| 93 | + endif() |
| 94 | + |
| 95 | + # Copy Qt DLLs to output directory |
| 96 | + add_custom_command(TARGET BasicSpanner POST_BUILD |
| 97 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 98 | + $<TARGET_FILE:Qt6::Core> |
| 99 | + $<TARGET_FILE:Qt6::Widgets> |
| 100 | + $<TARGET_FILE_DIR:BasicSpanner> |
| 101 | + ) |
| 102 | + |
| 103 | + # Windows deployment |
| 104 | + find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt HINTS ${Qt6_DIR}/../../../bin) |
| 105 | + if(QT_WINDEPLOYQT_EXECUTABLE) |
| 106 | + add_custom_command(TARGET BasicSpanner POST_BUILD |
| 107 | + COMMAND ${QT_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:BasicSpanner> |
| 108 | + COMMENT "Deploying Qt libraries") |
| 109 | + endif() |
| 110 | +endif() |
| 111 | + |
| 112 | +# Install rules |
| 113 | +install(TARGETS BasicSpanner |
| 114 | + RUNTIME DESTINATION bin |
| 115 | +) |
0 commit comments