aboutsummaryrefslogtreecommitdiff
path: root/core/CMakeLists.txt
blob: f2077a35febe807b7594e21dbc4b6905c18bdd2b (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
project(CpltCore LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

function(add_source_group GROUP_NAME GROUP_SOURCES)
	set(${GROUP_NAME} ${GROUP_SOURCES})
	set_source_files_properties(${GROUP_SOURCES}
	PROPERTIES
		UNITY_GROUP "${GROUP_NAME}"
	)
endfunction()

set(ENTRYPOINT_MODULE_SOURCES
)

add_source_group(UI_MODULE_SOURCES
)

add_source_group(UTILS_MODULE_SOURCES
	src/Utils/Enum.hpp
	src/Utils/I18n.hpp
	src/Utils/I18n.cpp
	src/Utils/Sigslot.hpp
	src/Utils/Sigslot.cpp
	src/Utils/String.hpp
	src/Utils/String.cpp
)

# These files are compiled individually, hence no UNITY_GROUP property
# This is because the files here may contain non-c++ languages
set(UTILS_DIALOG_MODULE_SOURCES
	src/Utils/Dialog/Dialog.hpp
	src/Utils/Dialog/Dialog.cpp
)
if(APPLE)
    list(APPEND UTILS_DIALOG_MODULE_SOURCES
        src/Utils/Dialog/Dialog_macos.mm
    )
elseif(WIN32)
    list(APPEND UTILS_DIALOG_MODULE_SOURCES
        src/Utils/Dialog/Dialog_win32.cpp
    )
elseif(LINUX)
    list(APPEND UTILS_DIALOG_MODULE_SOURCES
        src/Utils/Dialog/Dialog_linux.cpp
    )
endif()

function(add_executable_variant TARGET_NAME)
	message("CpltCore: generating executable ${TARGET_NAME}")

	add_executable(${TARGET_NAME}
		${ENTRYPOINT_MODULE_SOURCES}
		${UI_MODULE_SOURCES}
		${UTILS_MODULE_SOURCES}
		${UTILS_DIALOG_MODULE_SOURCES}
	)
	target_include_directories(${TARGET_NAME} PRIVATE
		${CMAKE_CURRENT_LIST_DIR}/src
		${CMAKE_SOURCE_DIR}/3rdparty/imgui
		${CMAKE_SOURCE_DIR}/3rdparty/imnodes
	)
	target_link_libraries(${TARGET_NAME} PRIVATE ${CONAN_LIBS})
	target_compile_definitions(${TARGET_NAME}
	PRIVATE
		PLATFORM_WIN32=$<BOOL:${WIN32}>
		PLATFORM_MACOS=$<BOOL:${APPLE}>
		PLATFORM_LINUX=$<BOOL:${LINUX}>
	)

	# No console window when targetting windows
	if(WIN32)
		if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
			# Supposedly the flag -mwindows would automatically make the executable use GUI subsystem
			# But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like)
			# so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem
			target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem:windows)
			target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry:mainCRTStartup)
		elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
			target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup)
		endif()
	endif()

	if(${CMAKE_UNITY_BUILD})
		message("CpltCore: - using unity build")
		set_target_properties(${TARGET_NAME}
		PROPERTIES
			# UNITY_BUILD property is automatically set when CMAKE_UNITY_BUILD is set
			UNITY_BUILD_MODE GROUP
		)
	else()
		message("CpltCore: - using regular build")
	endif()
endfunction()

add_executable_variant(CpltCore_main)
target_compile_definitions(CpltCore_main PRIVATE DOCTEST_CONFIG_DISABLE=1)

add_executable_variant(CpltCore_test)