spo/simulator_SIC_XE/CMakeLists.txt
2025-11-17 15:21:25 +01:00

60 lines
2.1 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(simulator_SIC_XE VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Put all build outputs under target/bin
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/target/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR})
# Collect all .cpp sources under src/
file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")
if(NOT SOURCES)
message(WARNING "No source files found in ${PROJECT_SOURCE_DIR}/src — the build will create an empty library")
endif()
# Build a static library from all sources
add_library(simulator_lib STATIC ${SOURCES})
target_include_directories(simulator_lib PUBLIC ${PROJECT_SOURCE_DIR}/include)
set_target_properties(simulator_lib PROPERTIES OUTPUT_NAME "simulator")
# If a main.cpp exists, create an executable that links the library.
if(EXISTS "${PROJECT_SOURCE_DIR}/src/main.cpp")
add_executable(simulator_exec "${PROJECT_SOURCE_DIR}/src/main.cpp")
target_link_libraries(simulator_exec PRIVATE simulator_lib)
endif()
if(TARGET simulator_exec)
add_custom_target(run
DEPENDS simulator_exec
COMMAND ${CMAKE_COMMAND} -E echo "Running simulator_exec..."
COMMAND $<TARGET_FILE:simulator_exec>
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Builds and runs simulator_exec"
)
endif()
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Sources found: ${SOURCES}")
message(STATUS "Output directory: ${OUTPUT_DIR}")
if(EXISTS "${CMAKE_SOURCE_DIR}/gui/qt/CMakeLists.txt")
add_subdirectory(gui/qt)
endif()
# Copy resources directory (if present) to target/res so build output includes them
if(EXISTS "${CMAKE_SOURCE_DIR}/res")
add_custom_target(copy_resources
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/target/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res ${CMAKE_SOURCE_DIR}/target/res
COMMENT "Copying resources from res/ to target/res/"
)
if(TARGET simulator_exec)
add_dependencies(simulator_exec copy_resources)
endif()
endif()