Add a 'core' library alongside 'common'.

The 'core' library contains almost all the same objects as 'common',
but leaves out hat.c. And the auxiliary program 'hatgen' now links
against that slightly reduced core library instead of 'common'.

This avoids a dependency loop: one of hatgen's jobs is to generate
hat-tables.h, but hat-tables.h is a dependency of it.

Of course, the generated hat-tables.h is already committed, so this
doesn't present a bootstrapping problem in a normal build. But if
someone modifies hatgen.c in order to regenerate hat-tables.h, and
does so in a way that makes it uncompilable, they can't rebuild hatgen
and try again! Of course you can always revert changes with git, but
it's annoying to have to. Better to keep the dependencies non-cyclic
in the first place.
This commit is contained in:
Simon Tatham
2023-06-15 07:40:14 +01:00
parent 43f4fde2f2
commit de13ca2874
3 changed files with 14 additions and 7 deletions

View File

@ -5,11 +5,12 @@ project(puzzles
include(cmake/setup.cmake) include(cmake/setup.cmake)
add_library(common add_library(core_obj OBJECT
combi.c divvy.c drawing.c dsf.c findloop.c grid.c latin.c combi.c divvy.c drawing.c dsf.c findloop.c grid.c latin.c
laydomino.c loopgen.c malloc.c matching.c midend.c misc.c penrose.c hat.c laydomino.c loopgen.c malloc.c matching.c midend.c misc.c penrose.c
ps.c random.c sort.c tdq.c tree234.c version.c ps.c random.c sort.c tdq.c tree234.c version.c ${platform_common_sources})
${platform_common_sources}) add_library(core $<TARGET_OBJECTS:core_obj>)
add_library(common $<TARGET_OBJECTS:core_obj> hat.c)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,6 +1,6 @@
cliprogram(combi-test combi-test.c) cliprogram(combi-test combi-test.c)
cliprogram(divvy-test divvy-test.c) cliprogram(divvy-test divvy-test.c)
cliprogram(hatgen hatgen.c COMPILE_DEFINITIONS TEST_HAT) cliprogram(hatgen hatgen.c CORE_LIB COMPILE_DEFINITIONS TEST_HAT)
cliprogram(hat-test hat-test.c) cliprogram(hat-test hat-test.c)
cliprogram(latin-test latin-test.c) cliprogram(latin-test latin-test.c)
cliprogram(matching matching.c) cliprogram(matching matching.c)

View File

@ -148,12 +148,18 @@ endfunction()
# a command-line helper tool. # a command-line helper tool.
function(cliprogram NAME) function(cliprogram NAME)
cmake_parse_arguments(OPT cmake_parse_arguments(OPT
"" "" "COMPILE_DEFINITIONS" ${ARGN}) "CORE_LIB" "" "COMPILE_DEFINITIONS" ${ARGN})
if(OPT_CORE_LIB)
set(lib core)
else()
set(lib common)
endif()
if(build_cli_programs) if(build_cli_programs)
add_executable(${NAME} ${CMAKE_SOURCE_DIR}/nullfe.c add_executable(${NAME} ${CMAKE_SOURCE_DIR}/nullfe.c
${OPT_UNPARSED_ARGUMENTS}) ${OPT_UNPARSED_ARGUMENTS})
target_link_libraries(${NAME} common ${platform_libs}) target_link_libraries(${NAME} ${lib} ${platform_libs})
if(OPT_COMPILE_DEFINITIONS) if(OPT_COMPILE_DEFINITIONS)
target_compile_definitions(${NAME} PRIVATE ${OPT_COMPILE_DEFINITIONS}) target_compile_definitions(${NAME} PRIVATE ${OPT_COMPILE_DEFINITIONS})
endif() endif()