Collect all of the various spread out 3rd party licenses to a single file.
[SquirrelJME.git] / nanocoat / tests / CMakeLists.txt
bloba0f28fc530841265ab61681fea5f7788a5f0925b
1 # ---------------------------------------------------------------------------
2 # SquirrelJME
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: Testing framework for the main library
10 # Decode all of the blobs to binary
11 squirreljme_decode_dir("${CMAKE_CURRENT_SOURCE_DIR}/blobs"
12         "${CMAKE_CURRENT_BINARY_DIR}/blobs/binary")
14 # Then encode them all to source files, for use within tests
15 squirreljme_sourceize_dir("${CMAKE_CURRENT_BINARY_DIR}/blobs/binary"
16         "${CMAKE_CURRENT_BINARY_DIR}/blobs")
18 # Setup main test execution wrapper which runs within TAC
19 add_library(TACTestExecutorCore STATIC
20         $<TARGET_OBJECTS:Base>
21         $<TARGET_OBJECTS:Core>
22         src/tac.c)
24 # Make sure we have our headers included accordingly
25 target_include_directories(TACTestExecutorCore PUBLIC
26         "${CMAKE_SOURCE_DIR}/include"
27         "${CMAKE_SOURCE_DIR}/tests/include")
29 # Depend on the core
30 target_link_libraries(TACTestExecutorCore PUBLIC
31         ${SQUIRRELJME_EXEC_LINK_LIBRARIES})
33 # Get a list of tests that are not TAC tests, but more general tests
34 file(GLOB basicTestSources
35         "test*.c"
36         "test*.cxx")
37 squirreljme_list_file_sort(SORT basicTestSources)
39 # Get a list of all the supporting blobs
40 file(GLOB basicTestBlobs
41         "${CMAKE_CURRENT_BINARY_DIR}/blobs/*.c")
43 # Setup base files for auto-generated test launching and method linking
44 set(outTestProtosH "${CMAKE_CURRENT_BINARY_DIR}/proto.h")
45 set(outTestStructH "${CMAKE_CURRENT_BINARY_DIR}/struct.h")
46 configure_file("${CMAKE_SOURCE_DIR}/cmake/blank.in.h"
47         "${outTestProtosH}")
48 configure_file("${CMAKE_SOURCE_DIR}/cmake/blank.in.h"
49         "${outTestStructH}")
51 # Include test header in the prototypes file
52 file(APPEND "${outTestProtosH}"
53         "#include \"test.h\"\n")
55 # Basic test library
56 add_library(BasicTestLib OBJECT
57         src/basic.c
58         src/classBuilder.c
59         src/blobs.c
60         src/mock.c
61         src/unit.c
62         ${basicTestSources}
63         ${basicTestBlobs})
65 # Basic test library
66 add_library(BasicTestLibPIC OBJECT
67         src/basic.c
68         src/classBuilder.c
69         src/blobs.c
70         src/mock.c
71         src/unit.c
72         ${basicTestSources}
73         ${basicTestBlobs})
75 # Initialize executable for basic tests, which contains everything
76 add_executable(BasicTest
77         src/basicMain.c
78         $<TARGET_OBJECTS:Base>
79         $<TARGET_OBJECTS:Core>
80         $<TARGET_OBJECTS:BasicTestLib>)
82 # Make it static
83 squirreljme_static_executable(BasicTest)
85 # Make sure we have our headers included accordingly
86 target_include_directories(BasicTestLib PUBLIC
87         "${CMAKE_SOURCE_DIR}/include"
88         "${CMAKE_CURRENT_SOURCE_DIR}/include"
89         "${CMAKE_CURRENT_BINARY_DIR}"
90         "${CMAKE_CURRENT_BINARY_DIR}/blobs")
91 target_include_directories(BasicTestLibPIC PUBLIC
92         "${CMAKE_SOURCE_DIR}/include"
93         "${CMAKE_CURRENT_SOURCE_DIR}/include"
94         "${CMAKE_CURRENT_BINARY_DIR}"
95         "${CMAKE_CURRENT_BINARY_DIR}/blobs")
97 # Make sure the PIC libraries are position independent!
98 set_target_properties(BasicTestLibPIC PROPERTIES
99         POSITION_INDEPENDENT_CODE ON)
101 # Make sure we have our headers included accordingly
102 target_include_directories(BasicTest PUBLIC
103         "${CMAKE_SOURCE_DIR}/include"
104         "${CMAKE_CURRENT_SOURCE_DIR}/include"
105         "${CMAKE_CURRENT_BINARY_DIR}"
106         "${CMAKE_CURRENT_BINARY_DIR}/blobs")
108 # Depend on the core
109 target_link_libraries(BasicTest PUBLIC
110         Core)
112 # Include debugging info for tests
113 if(CMAKE_BUILD_TYPE STREQUAL "Release")
114         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
115                 target_compile_options(BasicTestLib PRIVATE
116                         "-g")
117                 target_compile_options(BasicTestLibPIC PRIVATE
118                         "-g")
119         elseif(MSVC)
120                 target_compile_options(BasicTestLib PRIVATE
121                         "/DEBUG")
122                 target_compile_options(BasicTestLibPIC PRIVATE
123                         "/DEBUG")
124         endif()
125 endif()
127 # Process each individual test accordingly
128 message(DEBUG "Looking for tests...")
129 foreach(basicTestSource ${basicTestSources})
130         # We need to do this because on Windows, CLion+CMake just gives the full
131         # path which we really do not want as it will mess up with tests
132         set(initialBasicTestSource "${basicTestSource}")
133         get_filename_component(basicTestSource
134                 "${basicTestSource}" NAME)
136         # Remove the C/C++ to just get the base test
137         string(REPLACE ".cxx" ""
138                 basicTestName "${basicTestSource}")
139         string(REPLACE ".c" ""
140                 basicTestName "${basicTestSource}")
142         # Long name of the test
143         set(basicTestLongName "basic:${basicTestName}")
145         # Full path, for message output
146         get_filename_component(basicTestFullPath
147                 "${initialBasicTestSource}" ABSOLUTE)
149         # Add test for this
150         message(STATUS "Registering test ${basicTestLongName}...")
151         add_test(NAME "${basicTestLongName}"
152                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
153                 COMMAND "$<TARGET_FILE:BasicTest>" "${basicTestName}"
154                         "${basicTestFullPath}")
156         # Code for skipped tests
157         set_property(TEST "${basicTestLongName}"
158                 PROPERTY SKIP_RETURN_CODE 2)
159         set_tests_properties("${basicTestLongName}"
160                 PROPERTIES SKIP_RETURN_CODE 2)
162         # Test timeout (to prevent infinite loops)
163         set_property(TEST "${basicTestLongName}"
164                 PROPERTY TIMEOUT 180)
165         set_tests_properties("${basicTestLongName}"
166                 PROPERTIES TIMEOUT 180)
168         # Label, name of test, used for filtering
169         set_property(TEST "${basicTestLongName}"
170                 PROPERTY LABEL "${basicTestSource}")
171         set_tests_properties("${basicTestLongName}"
172                 PROPERTIES LABEL "${basicTestSource}")
174         # Add prototype and structures for test
175         file(APPEND "${outTestProtosH}"
176                 "SJME_TEST_DECLARE(${basicTestName});\n")
177         file(APPEND "${outTestStructH}"
178                 "{\"${basicTestName}\", ${basicTestName}},\n")
179 endforeach()