#Variables #----------------------------------------------------------------------------------------- set(PROJ_NAME DragonV2) set(MAJOR_VER 0) set(MINOR_VER 1) #----------------------------------------------------------------------------------------- #Setup #----------------------------------------------------------------------------------------- set(CMAKE_CXX_COMPILER "clang++") set(CMAKE_C_COMPILER "clang") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) cmake_minimum_required(VERSION 3.18) project(${PROJ_NAME} LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 23) file(STRINGS "./other/build.nr" BUILD_NUMBER) #----------------------------------------------------------------------------------------- message("** Building ${PROJ_NAME} ${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") if(CMAKE_BUILD_TYPE STREQUAL "Debug") message(STATUS "Debug Configuration") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") message(STATUS "Release Configuration") endif() #Sources #----------------------------------------------------------------------------------------- list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/src ) list(APPEND RUNTIME_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/runtime/runtime_main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/CPU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/RAM.cpp ) list(APPEND DEBUGGER_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/debugger/debugger_main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/CPU.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/RAM.cpp ) list(APPEND ASSEMBLER_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/assembler/assembler_main.cpp ) list(APPEND TOOLS_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/tools/tools_main.cpp ) list(APPEND TEST_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/RAM_test.cpp ${CMAKE_CURRENT_LIST_DIR}/src/hardware/RAM.cpp ) #----------------------------------------------------------------------------------------- #Targets #----------------------------------------------------------------------------------------- set(RUNTIME_TARGET dvm) add_executable(${RUNTIME_TARGET} ${RUNTIME_SOURCE_FILES}) if(WIN32) target_sources(${RUNTIME_TARGET} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/other/dvm_appIcon.rc") endif() target_include_directories(${RUNTIME_TARGET} PUBLIC ${INCLUDE_DIRS}) set(DEBUGGER_TARGET ddb) add_executable(${DEBUGGER_TARGET} ${DEBUGGER_SOURCE_FILES}) if(WIN32) target_sources(${DEBUGGER_TARGET} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/other/ddb_appIcon.rc") endif() target_include_directories(${DEBUGGER_TARGET} PUBLIC ${INCLUDE_DIRS}) set(ASSEMBLER_TARGET dasm) add_executable(${ASSEMBLER_TARGET} ${ASSEMBLER_SOURCE_FILES}) if(WIN32) target_sources(${ASSEMBLER_TARGET} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/other/dasm_appIcon.rc") endif() target_include_directories(${ASSEMBLER_TARGET} PUBLIC ${INCLUDE_DIRS}) set(TOOLS_TARGET dtools) add_executable(${TOOLS_TARGET} ${TOOLS_SOURCE_FILES}) if(WIN32) target_sources(${TOOLS_TARGET} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/other/dtools_appIcon.rc") endif() target_include_directories(${TOOLS_TARGET} PUBLIC ${INCLUDE_DIRS}) set(TEST_TARGET test_exec) add_executable(${TEST_TARGET} ${TEST_SOURCE_FILES}) if(WIN32) target_sources(${TEST_TARGET} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/other/dtools_appIcon.rc") endif() target_include_directories(${TEST_TARGET} PUBLIC ${INCLUDE_DIRS}) target_compile_definitions(${RUNTIME_TARGET} PUBLIC BUILD_NR=${BUILD_NUMBER} MAJ_V=${MAJOR_VER} MIN_V=${MINOR_VER} VERSION_STR="${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") target_compile_definitions(${DEBUGGER_TARGET} PUBLIC BUILD_NR=${BUILD_NUMBER} MAJ_V=${MAJOR_VER} MIN_V=${MINOR_VER} VERSION_STR="${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") target_compile_definitions(${ASSEMBLER_TARGET} PUBLIC BUILD_NR=${BUILD_NUMBER} MAJ_V=${MAJOR_VER} MIN_V=${MINOR_VER} VERSION_STR="${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") target_compile_definitions(${TOOLS_TARGET} PUBLIC BUILD_NR=${BUILD_NUMBER} MAJ_V=${MAJOR_VER} MIN_V=${MINOR_VER} VERSION_STR="${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") target_compile_definitions(${TEST_TARGET} PUBLIC BUILD_NR=${BUILD_NUMBER} MAJ_V=${MAJOR_VER} MIN_V=${MINOR_VER} VERSION_STR="${MAJOR_VER}.${MINOR_VER}.${BUILD_NUMBER}") if (WIN32) set(MSYS2_UCRT64 "C:/msys64/ucrt64") target_include_directories(${RUNTIME_TARGET} PRIVATE "${MSYS2_UCRT64}/include" "${MSYS2_UCRT64}/include/c++/13.2.0" "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) target_include_directories(${DEBUGGER_TARGET} PRIVATE "${MSYS2_UCRT64}/include" "${MSYS2_UCRT64}/include/c++/13.2.0" "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) target_include_directories(${ASSEMBLER_TARGET} PRIVATE "${MSYS2_UCRT64}/include" "${MSYS2_UCRT64}/include/c++/13.2.0" "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) target_include_directories(${TOOLS_TARGET} PRIVATE "${MSYS2_UCRT64}/include" "${MSYS2_UCRT64}/include/c++/13.2.0" "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) target_include_directories(${TEST_TARGET} PRIVATE "${MSYS2_UCRT64}/include" "${MSYS2_UCRT64}/include/c++/13.2.0" "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(${RUNTIME_TARGET} PUBLIC BUILD_CONFIG_DEBUG OX_DEBUG_BUILD) target_compile_definitions(${DEBUGGER_TARGET} PUBLIC BUILD_CONFIG_DEBUG OX_DEBUG_BUILD) target_compile_definitions(${ASSEMBLER_TARGET} PUBLIC BUILD_CONFIG_DEBUG OX_DEBUG_BUILD) target_compile_definitions(${TOOLS_TARGET} PUBLIC BUILD_CONFIG_DEBUG OX_DEBUG_BUILD) target_compile_definitions(${TEST_TARGET} PUBLIC BUILD_CONFIG_DEBUG OX_DEBUG_BUILD) add_compile_options(-O3 -MMD -MP -Wall -ggdb) elseif(CMAKE_BUILD_TYPE STREQUAL "Release") target_compile_definitions(${RUNTIME_TARGET} PUBLIC BUILD_CONFIG_RELEASE OX_RELEASE_BUILD) target_compile_definitions(${DEBUGGER_TARGET} PUBLIC BUILD_CONFIG_RELEASE OX_RELEASE_BUILD) target_compile_definitions(${ASSEMBLER_TARGET} PUBLIC BUILD_CONFIG_RELEASE OX_RELEASE_BUILD) target_compile_definitions(${TOOLS_TARGET} PUBLIC BUILD_CONFIG_RELEASE OX_RELEASE_BUILD) target_compile_definitions(${TEST_TARGET} PUBLIC BUILD_CONFIG_RELEASE OX_RELEASE_BUILD) add_compile_options(-MMD -MP -Wall) endif() if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Release") set_target_properties(${RUNTIME_TARGET} PROPERTIES WIN32_EXECUTABLE TRUE ) set_target_properties(${DEBUGGER_TARGET} PROPERTIES WIN32_EXECUTABLE TRUE ) set_target_properties(${ASSEMBLER_TARGET} PROPERTIES WIN32_EXECUTABLE TRUE ) set_target_properties(${TOOLS_TARGET} PROPERTIES WIN32_EXECUTABLE TRUE ) endif() #----------------------------------------------------------------------------------------- #Linking #----------------------------------------------------------------------------------------- if (WIN32) target_link_libraries(${RUNTIME_TARGET} mingw32 SDL3 SDL3_ttf SDL3_image) target_link_libraries(${ASSEMBLER_TARGET} mingw32) target_link_libraries(${TOOLS_TARGET} mingw32) target_link_libraries(${DEBUGGER_TARGET} mingw32 SDL3 SDL3_ttf SDL3_image) target_link_libraries(${TEST_TARGET} mingw32) endif (WIN32) if (APPLE) cmake_policy(SET CMP0167 OLD) find_package(Boost REQUIRED COMPONENTS regex) target_link_libraries(${RUNTIME_TARGET} Boost::regex) target_link_libraries(${ASSEMBLER_TARGET} Boost::regex) target_link_libraries(${TOOLS_TARGET} Boost::regex) target_link_libraries(${DEBUGGER_TARGET} Boost::regex) target_link_libraries(${TEST_TARGET} Boost::regex) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL3 REQUIRED sdl3) pkg_check_modules(SDL3_IMAGE REQUIRED sdl3-image) pkg_check_modules(SDL3_TTF REQUIRED sdl3-ttf) target_include_directories(${RUNTIME_TARGET} PUBLIC ${SDL3_INCLUDE_DIRS} ${SDL3_IMAGE_INCLUDE_DIRS} ${SDL3_TTF_INCLUDE_DIRS} ) target_link_directories(${RUNTIME_TARGET} PUBLIC ${SDL3_LIBRARY_DIRS} ${SDL3_IMAGE_LIBRARY_DIRS} ${SDL3_TTF_LIBRARY_DIRS} ) target_link_libraries(${RUNTIME_TARGET} ${SDL3_LIBRARIES} ${SDL3_IMAGE_LIBRARIES} ${SDL3_TTF_LIBRARIES} ) target_include_directories(${DEBUGGER_TARGET} PUBLIC ${SDL3_INCLUDE_DIRS} ${SDL3_IMAGE_INCLUDE_DIRS} ${SDL3_TTF_INCLUDE_DIRS} ) target_link_directories(${DEBUGGER_TARGET} PUBLIC ${SDL3_LIBRARY_DIRS} ${SDL3_IMAGE_LIBRARY_DIRS} ${SDL3_TTF_LIBRARY_DIRS} ) target_link_libraries(${DEBUGGER_TARGET} ${SDL3_LIBRARIES} ${SDL3_IMAGE_LIBRARIES} ${SDL3_TTF_LIBRARIES} ) elseif (UNIX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN',-rpath,/usr/lib,-rpath,/usr/local/lib") target_link_libraries(${RUNTIME_TARGET} xcb xcb-randr boost_regex SDL3 SDL3_image) target_link_libraries(${ASSEMBLER_TARGET} xcb xcb-randr boost_regex) target_link_libraries(${TOOLS_TARGET} xcb xcb-randr boost_regex) target_link_libraries(${DEBUGGER_TARGET} xcb xcb-randr boost_regex SDL3 SDL3_image) target_link_libraries(${TEST_TARGET} xcb xcb-randr boost_regex) endif () target_link_libraries(${RUNTIME_TARGET} ostd ogfx) target_link_libraries(${DEBUGGER_TARGET} ostd ogfx) target_link_libraries(${ASSEMBLER_TARGET} ostd) target_link_libraries(${TOOLS_TARGET} ostd) target_link_libraries(${TEST_TARGET} ostd) #-----------------------------------------------------------------------------------------