Refactor the source file listing

Make the common files into an object library, which lets them
be compiled only once (saving 41 build steps)
This also lends itself well to removing the per-program loop,
which simplifies the code somewhat.
This commit is contained in:
ISSOtm
2026-03-09 23:37:20 -04:00
committed by Rangi
parent 06e5386d93
commit a139cbc744

View File

@@ -2,7 +2,7 @@
configure_file(version.cpp _version.cpp ESCAPE_QUOTES) configure_file(version.cpp _version.cpp ESCAPE_QUOTES)
set(common_src add_library(common OBJECT
"extern/getopt.cpp" "extern/getopt.cpp"
"cli.cpp" "cli.cpp"
"diagnostics.cpp" "diagnostics.cpp"
@@ -10,7 +10,7 @@ set(common_src
"usage.cpp" "usage.cpp"
"util.cpp" "util.cpp"
"_version.cpp" "_version.cpp"
) )
find_package(BISON 3.0.0 REQUIRED) find_package(BISON 3.0.0 REQUIRED)
set(BISON_FLAGS "-Wall -Dlr.type=ielr") set(BISON_FLAGS "-Wall -Dlr.type=ielr")
@@ -31,15 +31,8 @@ BISON_TARGET(ASM_PARSER "asm/parser.y"
"${PROJECT_SOURCE_DIR}/src/asm/parser.cpp" "${PROJECT_SOURCE_DIR}/src/asm/parser.cpp"
COMPILE_FLAGS "${BISON_FLAGS}" COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/parser.hpp" DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/parser.hpp"
) )
add_executable(rgbasm $<TARGET_OBJECTS:common>
BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y"
"${PROJECT_SOURCE_DIR}/src/link/script.cpp"
COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp"
)
set(rgbasm_src
"${BISON_ASM_PARSER_OUTPUT_SOURCE}" "${BISON_ASM_PARSER_OUTPUT_SOURCE}"
"asm/actions.cpp" "asm/actions.cpp"
"asm/charmap.cpp" "asm/charmap.cpp"
@@ -60,9 +53,14 @@ set(rgbasm_src
"linkdefs.cpp" "linkdefs.cpp"
"opmath.cpp" "opmath.cpp"
"verbosity.cpp" "verbosity.cpp"
) )
set(rgblink_src BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y"
"${PROJECT_SOURCE_DIR}/src/link/script.cpp"
COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp"
)
add_executable(rgblink $<TARGET_OBJECTS:common>
"${BISON_LINKER_SCRIPT_PARSER_OUTPUT_SOURCE}" "${BISON_LINKER_SCRIPT_PARSER_OUTPUT_SOURCE}"
"link/assign.cpp" "link/assign.cpp"
"link/fstack.cpp" "link/fstack.cpp"
@@ -81,16 +79,16 @@ set(rgblink_src
"linkdefs.cpp" "linkdefs.cpp"
"opmath.cpp" "opmath.cpp"
"verbosity.cpp" "verbosity.cpp"
) )
set(rgbfix_src add_executable(rgbfix $<TARGET_OBJECTS:common>
"fix/fix.cpp" "fix/fix.cpp"
"fix/main.cpp" "fix/main.cpp"
"fix/mbc.cpp" "fix/mbc.cpp"
"fix/warning.cpp" "fix/warning.cpp"
) )
set(rgbgfx_src add_executable(rgbgfx $<TARGET_OBJECTS:common>
"gfx/color_set.cpp" "gfx/color_set.cpp"
"gfx/main.cpp" "gfx/main.cpp"
"gfx/pal_packing.cpp" "gfx/pal_packing.cpp"
@@ -103,19 +101,13 @@ set(rgbgfx_src
"gfx/rgba.cpp" "gfx/rgba.cpp"
"gfx/warning.cpp" "gfx/warning.cpp"
"verbosity.cpp" "verbosity.cpp"
) )
foreach(PROG "asm" "fix" "gfx" "link") install(TARGETS rgbasm rgblink rgbfix rgbgfx RUNTIME DESTINATION bin)
add_executable(rgb${PROG} # Required to run tests
${rgb${PROG}_src} set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES
${common_src} # hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
) RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
# Required to run tests
set_target_properties(rgb${PROG} PROPERTIES
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
endforeach()
if(LIBPNG_FOUND) # pkg-config if(LIBPNG_FOUND) # pkg-config
target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS}) target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS})