Modularize build system.

This way object files can be shared accross multiple executables.
This commit is contained in:
Maxim Poliakovski 2020-02-03 14:36:30 +01:00
parent eb476adf87
commit 4e4d0370be
3 changed files with 26 additions and 10 deletions

View File

@ -6,20 +6,26 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
"${PROJECT_SOURCE_DIR}/debugger"
"${PROJECT_SOURCE_DIR}/cpu/ppc")
"${PROJECT_SOURCE_DIR}/cpu/ppc"
"${PROJECT_SOURCE_DIR}/debugger")
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp" "${PROJECT_SOURCE_DIR}/devices/*.cpp"
"${PROJECT_SOURCE_DIR}/debugger/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp")
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/debugger/*.cpp")
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/devices/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
add_executable(dingusppc ${SOURCES})
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:cpu_ppc> $<TARGET_OBJECTS:devices>)
add_executable(testppc ${TEST_SOURCES})
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:cpu_ppc> $<TARGET_OBJECTS:devices>)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})

5
cpu/ppc/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
include_directories("${PROJECT_SOURCE_DIR}")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(cpu_ppc OBJECT ${SOURCES})

5
devices/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
include_directories("${PROJECT_SOURCE_DIR}")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(devices OBJECT ${SOURCES})