Skip to content

Commit

Permalink
シンプル化
Browse files Browse the repository at this point in the history
  • Loading branch information
steelpipe75 committed May 27, 2024
1 parent db618e9 commit 5858934
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 315 deletions.
315 changes: 1 addition & 314 deletions c_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,39 +113,6 @@ add_subdirectory(lib/bowling_game)

#################################################################################

include_directories(lib/bowling_game/src)

#################################################################################

add_executable(bowling_game_test_assert
lib/bowling_game/src/bowling_game.c
lib/bowling_game/test/assert/bowling_game_test_assert.c
)

if(WIN32)
add_test(
NAME bowling_game_test_assert
COMMAND ${TEST_LUNCHER} bowling_game_test_assert $<TARGET_FILE:bowling_game_test_assert>
)
elseif(UNIX)
add_test(
NAME bowling_game_test_assert
COMMAND sh ${TEST_LUNCHER} bowling_game_test_assert $<TARGET_FILE:bowling_game_test_assert>
)
endif()

target_include_directories(bowling_game_test_assert
PRIVATE lib/bowling_game/src
)
target_compile_options_helper(bowling_game_test_assert)

add_custom_command(
TARGET bowling_game_test_assert POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_test_assert> ${CMAKE_BINARY_DIR}
)

#################################################################################

add_executable(
bowling_game_test_pcunit
lib/bowling_game/src/bowling_game.c
Expand All @@ -172,291 +139,11 @@ target_include_directories(bowling_game_test_pcunit
)
target_compile_options_helper(bowling_game_test_pcunit)

add_custom_command(
TARGET bowling_game_test_pcunit POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_test_pcunit> ${CMAKE_BINARY_DIR}
)

#################################################################################

macro(find_test_data testfile variable)
find_file(${variable}
${testfile}
HINTS "${CMAKE_SOURCE_DIR}/../testdata/"
REQUIRED
)
endmacro()

find_test_data(all_ones.txt input_file_path_all_one_test )
find_test_data(all_zeros.txt input_file_path_all_zeros )
find_test_data(one_spare.txt input_file_path_one_spare )
find_test_data(one_strike.txt input_file_path_one_strike )
find_test_data(perfect_game.txt input_file_path_perfect_game )

#################################################################################

add_executable(
bowling_game_cli
lib/bowling_game/src/bowling_game.c
src/bowling_game_cli.c
)

macro(do_cli_test testname inputfile output)
if(WIN32)
add_test(
NAME bowling_game_cli_test_${testname}
COMMAND ${TEST_LUNCHER} bowling_game_cli_test_${testname} $<TARGET_FILE:bowling_game_cli> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
elseif(UNIX)
add_test(
NAME bowling_game_cli_test_${testname}
COMMAND sh ${TEST_LUNCHER} bowling_game_cli_test_${testname} $<TARGET_FILE:bowling_game_cli> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
set_tests_properties(
bowling_game_cli_test_${testname} PROPERTIES
PASS_REGULAR_EXPRESSION ${output}
)
endmacro()

target_include_directories(bowling_game_cli
PRIVATE lib/bowling_game/src
)
target_compile_options_helper(bowling_game_cli)

add_custom_command(
TARGET bowling_game_cli POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_cli> ${CMAKE_BINARY_DIR}
)

do_cli_test(
all_ones
${input_file_path_all_one_test}
20
)

do_cli_test(
all_zeros
${input_file_path_all_zeros}
0
)

do_cli_test(
one_spare
${input_file_path_one_spare}
16
)

do_cli_test(
one_strike
${input_file_path_one_strike}
24
)

do_cli_test(
perfect_game
${input_file_path_perfect_game}
300
)

do_cli_test(
no_inputfile
""
"usage: $<TARGET_FILE:bowling_game_cli> inputfilename"
)

do_cli_test(
cant_open_inputfile
cant_open_inputfile.txt
"can't open cant_open_inputfile.txt"
)

#################################################################################

add_executable(
bowling_game_cli_shared
src/bowling_game_cli.c
)

target_link_libraries(bowling_game_cli_shared bowling_game_share)

macro(do_cli_shared_test testname inputfile output)
if(WIN32)
add_test(
NAME bowling_game_cli_shared_test_${testname}
COMMAND ${TEST_LUNCHER} bowling_game_cli_shared_test_${testname} $<TARGET_FILE:bowling_game_cli_shared> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
elseif(UNIX)
add_test(
NAME bowling_game_cli_shared_test_${testname}
COMMAND sh ${TEST_LUNCHER} bowling_game_cli_shared_test_${testname} $<TARGET_FILE:bowling_game_cli_shared> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
set_tests_properties(
bowling_game_cli_shared_test_${testname} PROPERTIES
PASS_REGULAR_EXPRESSION ${output}
)
endmacro()

target_include_directories(bowling_game_cli_shared
PRIVATE lib/bowling_game/src
)
target_compile_options_helper(bowling_game_cli_shared)

add_custom_command(
TARGET bowling_game_cli_shared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_share> ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_cli_shared> ${CMAKE_BINARY_DIR}
)

do_cli_shared_test(
all_ones
${input_file_path_all_one_test}
20
)

do_cli_shared_test(
all_zeros
${input_file_path_all_zeros}
0
)

do_cli_shared_test(
one_spare
${input_file_path_one_spare}
16
)

do_cli_shared_test(
one_strike
${input_file_path_one_strike}
24
)

do_cli_shared_test(
perfect_game
${input_file_path_perfect_game}
300
)

do_cli_shared_test(
no_inputfile
""
"usage: $<TARGET_FILE:bowling_game_cli_shared> inputfilename"
)

do_cli_shared_test(
cant_open_inputfile
cant_open_inputfile.txt
"can't open cant_open_inputfile.txt"
)

#################################################################################

add_executable(
bowling_game_cli_static
src/bowling_game_cli.c
)

target_link_libraries(bowling_game_cli_static bowling_game_static)

macro(do_cli_static_test testname inputfile output)
if(WIN32)
add_test(
NAME bowling_game_cli_static_test_${testname}
COMMAND ${TEST_LUNCHER} bowling_game_cli_static_test_${testname} $<TARGET_FILE:bowling_game_cli_static> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
elseif(UNIX)
add_test(
NAME bowling_game_cli_static_test_${testname}
COMMAND sh ${TEST_LUNCHER} bowling_game_cli_static_test_${testname} $<TARGET_FILE:bowling_game_cli_static> ${inputfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
set_tests_properties(
bowling_game_cli_static_test_${testname} PROPERTIES
PASS_REGULAR_EXPRESSION ${output}
)
endmacro()

target_include_directories(bowling_game_cli_static
PRIVATE lib/bowling_game/src
)
target_compile_options_helper(bowling_game_cli_static)

add_custom_command(
TARGET bowling_game_cli_static POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:bowling_game_cli_static> ${CMAKE_BINARY_DIR}
)

do_cli_static_test(
all_ones
${input_file_path_all_one_test}
20
)

do_cli_static_test(
all_zeros
${input_file_path_all_zeros}
0
)

do_cli_static_test(
one_spare
${input_file_path_one_spare}
16
)

do_cli_static_test(
one_strike
${input_file_path_one_strike}
24
)

do_cli_static_test(
perfect_game
${input_file_path_perfect_game}
300
)

do_cli_static_test(
no_inputfile
""
"usage: $<TARGET_FILE:bowling_game_cli_static> inputfilename"
)

do_cli_static_test(
cant_open_inputfile
cant_open_inputfile.txt
"can't open cant_open_inputfile.txt"
)

#################################################################################

if(WIN32)

file(WRITE ${CMAKE_BINARY_DIR}/config.bat "@echo off
cd /D %~dp0
cmake . %*
cmd /K
")

file(WRITE ${CMAKE_BINARY_DIR}/config-gui.bat "cd /D %~dp0
start cmake-gui . %*
")

file(WRITE ${CMAKE_BINARY_DIR}/ninja_-t_deps.bat "cd /D %~dp0
ninja -t deps %*
")

# ビルドとテストを実行するバッチ
configure_file(../utility/build_and_test.bat.in build_and_test.bat)

elseif(UNIX)

endif()
target_link_libraries(bowling_game_cli bowling_game_static)
12 changes: 11 additions & 1 deletion c_cmake/lib/bowling_game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ add_library(
src/bowling_game.c
)

target_include_directories(
bowling_game_share
PUBLIC
src
)

#################################################################################

add_library(
Expand All @@ -45,4 +51,8 @@ add_library(
src/bowling_game.c
)

#################################################################################
target_include_directories(
bowling_game_static
PUBLIC
src
)

0 comments on commit 5858934

Please sign in to comment.