1 # ---------------------------------------------------------------------------
3 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
4 # ---------------------------------------------------------------------------
5 # SquirrelJME is under the Mozilla Public License Version 2.0.
6 # See license.mkd for licensing and copyright information.
7 # ---------------------------------------------------------------------------
8 # DESCRIPTION: Functions and macros for ROM source code, allows all the
9 # ROM source information to be duplicated accordingly and to change all of
10 # at once instead of auto-generating new code.
12 # Initializes the structure and otherwise for ROMs themselves which
14 function(squirreljme_rom sourceSet clutterLevel)
16 set(romTask "ROM_${sourceSet}_${clutterLevel}")
18 # Add base object library
19 add_library("${romTask}" STATIC
20 ${squirreljme_dynamic_objLibs})
22 # If this is a test ROM, we need to actually link it in with the
23 # TAC test execution core
24 if ("${sourceSet}" STREQUAL "test")
25 # Name of the TAC executable task to run the test in
26 set(romTacTask "TACTestExecutor_${clutterLevel}")
28 # Define executable which uses this ROM and the others
29 add_executable("${romTacTask}"
30 "${CMAKE_SOURCE_DIR}/tests/tacPayload.c")
32 # Need to include our headers and such
33 target_include_directories("${romTacTask}"
34 PUBLIC "${CMAKE_SOURCE_DIR}/include"
35 PUBLIC "${CMAKE_SOURCE_DIR}/rom/main_${clutterLevel}"
36 PUBLIC "${CMAKE_SOURCE_DIR}/rom/testFixtures_${clutterLevel}"
37 PUBLIC "${CMAKE_SOURCE_DIR}/rom/${sourceSet}_${clutterLevel}")
39 # Include the libraries needed to run the ROM
40 target_link_libraries("${romTacTask}" PUBLIC
42 "ROM_main_${clutterLevel}"
43 "ROM_testFixtures_${clutterLevel}"
44 "ROM_${sourceSet}_${clutterLevel}")
46 # Define ROMs available for use
47 target_compile_definitions("${romTacTask}"
48 PUBLIC SJME_CONFIG_ROM0=rom_main_${clutterLevel}
49 PUBLIC SJME_CONFIG_ROM0_HEADER="rom_main_${clutterLevel}.h"
50 PUBLIC SJME_CONFIG_ROM1=rom_testFixtures_${clutterLevel}
51 PUBLIC SJME_CONFIG_ROM1_HEADER="rom_testFixtures_${clutterLevel}.h"
52 PUBLIC SJME_CONFIG_ROM2=rom_${sourceSet}_${clutterLevel}
53 PUBLIC SJME_CONFIG_ROM2_HEADER="rom_${sourceSet}_${clutterLevel}.h")
57 # Include a previous instance of squirreljme_romLibrary
58 macro(squirreljme_romLibrary_include sourceSet
59 clutterLevel libName libIdentifier)
60 # Include directory where the module exists
61 add_subdirectory("modules/${libIdentifier}")
63 # Used for later inclusion
64 list(APPEND squirreljme_dynamic_objLibs
65 "$<$<TARGET_OBJECTS:${sourceSet}_${clutterLevel}_${libIdentifier}>>")
68 # Declares a class for a library
69 macro(squirreljme_romLibrary_class sourceSet clutterLevel
70 libName libIdentifier className
71 classIdentifier classHeader classSource)
72 list(APPEND squirreljme_dynamic_classesFiles
76 # Initializes the structure and otherwise needed for ROM libraries
77 # Remaining argv are sources
78 function(squirreljme_romLibrary sourceSet clutterLevel
79 libName libIdentifier libHeader libSource
81 # Library task for simplicity
83 "ROMLib_${sourceSet}_${clutterLevel}_${libName}_Object")
85 # Add object library which includes all the output object files
86 add_library("${libTask}" OBJECT
89 # Include main headers
90 target_include_directories("${libTask}" PUBLIC
91 "${CMAKE_SOURCE_DIR}/include")
93 # Disable warnings, since it gets extremely noisy when compiling libraries
94 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
95 target_compile_options("${libTask}" PRIVATE
97 elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
98 CMAKE_C_COMPILER_ID STREQUAL "Clang")
99 target_compile_options("${libTask}" PRIVATE
104 # Defines a test for a ROM library entry using the TAC framework
105 function(squirreljme_romLibraryTest libNameStr sourceSet
106 clutterLevel testName testClassPath)
107 # Determine name for the actual test
108 set(longName "${clutterLevel}:${libNameStr}:${testName}")
112 "Adding test ${testName} in ${libNameStr}...")
113 set(romTacTask "TACTestExecutor_${clutterLevel}")
114 add_test(NAME "${longName}"
115 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
116 COMMAND "${romTacTask}"
117 "-classpath" "${testClassPath}"
118 "net.multiphasicapps.tac.MainSingleRunner"
121 # Code for skipped tests
122 set_property(TEST "${longName}"
123 PROPERTY SKIP_RETURN_CODE 2)
124 set_tests_properties("${longName}"
125 PROPERTIES SKIP_RETURN_CODE 2)
127 # Test timeout (to prevent infinite loops)
128 set_property(TEST "${longName}"
129 PROPERTY TIMEOUT 180)
130 set_tests_properties("${longName}"
131 PROPERTIES TIMEOUT 180)