45 lines
1.7 KiB
CMake
45 lines
1.7 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 as requested
|
|
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()
|
|
|
|
# Convenience target: `cmake --build build --target run`
|
|
# This target will build `simulator_exec` (if present) and then execute it.
|
|
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}")
|