aboutsummaryrefslogtreecommitdiffstats
path: root/deps/sol2/tests/compile_tests/CMakeLists.txt
blob: a973cd9abdf309ad6f4406516b89ff7801917604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# # # # sol3
# The MIT License (MIT)
# 
# Copyright (c) 2013-2019 Rapptz, ThePhD, and contributors
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# # # # sol3 tests - compilation tests

file(GLOB_RECURSE SOL2_COMPILE_TEST_SOURCES source/*.cpp)
source_group(compile_test_sources FILES "${SOL2_COMPILE_TEST_SOURCES}")

function(CREATE_TEST test_target_name test_name target_sol)
	if (test_name MATCHES ".single")
		add_executable(${test_target_name} "source/main.cpp" "source/forward.cpp" "source/sol.cpp")
	else()
		add_executable(${test_target_name} "${SOL2_COMPILE_TEST_SOURCES}")
	endif()
	set_target_properties(${test_target_name}
		PROPERTIES
		OUTPUT_NAME ${test_name}
		EXPORT_NAME sol2::${test_name})
	target_link_libraries(${test_target_name} 
		PUBLIC Threads::Threads ${LUA_LIBRARIES} ${CATCH_LIBRARIES} ${target_sol})
	
	if (MSVC)
		target_compile_options(${test_target_name}
			PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
			"$<$<CONFIG:Release>:/MD>"
			"$<$<CONFIG:RelWithDebInfo>:/MD>"
			"$<$<CONFIG:MinSizeRel>:/MD>")
		target_compile_definitions(${test_target_name}
			PRIVATE UNICODE _UNICODE 
			_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE)
	else()
		target_compile_options(${test_target_name}
			PRIVATE -std=c++1z
			-Wno-unknown-warning -Wno-unknown-warning-option
			-Wall -Wextra -Wpedantic -pedantic -pedantic-errors
			-Wno-noexcept-type)

		if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
			# For another day, when C++ is not so crap
			# and we have time to audit the entire lib
			# for all uses of `detail::swallow`...
			#target_compile_options(${test_target_name}
			#	PRIVATE -Wcomma)		
		endif()
	endif()
	
	if (MSVC)
		if (NOT CMAKE_COMPILER_ID MATCHES "Clang")
			target_compile_options(${test_target_name} 
				PRIVATE /bigobj /W4)
		endif()
	else()
		if (IS_X86)
			if(MINGW)
				set_target_properties(${test_target_name}
					PROPERTIES
					LINK_FLAGS -static-libstdc++)
			endif()
		endif()	
	endif()
	if (SOL2_CI)
		target_compile_definitions(${test_target_name} 
			PRIVATE SOL2_CI)
	endif()
	if (CMAKE_DL_LIBS)
		target_link_libraries(${test_target_name} PUBLIC
			${CMAKE_DL_LIBS})
	endif()
	
	add_test(NAME ${test_name} COMMAND ${test_target_name})
	install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
endfunction(CREATE_TEST)

if (SOL2_TESTS)
	CREATE_TEST(compile_tests "compile_tests" sol2::sol2)
endif()
if (SOL2_TESTS_SINGLE)
	CREATE_TEST(compile_tests_single "compile_tests.single" sol2::sol2_single)
endif()
if (SOL2_TESTS_SINGLE_GENERATED)
	CREATE_TEST(compile_tests_generated_single "compile_tests.single.generated" sol2::sol2_single_generated)
endif()