forked from sakura-editor/sakura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
64 lines (54 loc) · 2.59 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.6)
include(${CMAKE_SOURCE_DIR}/runtime.cmake)
# define a variable of project name
set(project_name tests1)
# define a variable SRC with file GLOB
file(GLOB TEST_SRC ${CMAKE_CURRENT_LIST_DIR}/test*.cpp)
file(GLOB TARGET_SRC ${CMAKE_CURRENT_LIST_DIR}/code*.cpp)
# define sources files of an executable
add_executable(${project_name} ${TEST_SRC} ${TARGET_SRC})
# add definitions
target_compile_definitions(${project_name} PUBLIC _CONSOLE UNICODE _UNICODE)
# add include directories for sakura_core
target_include_directories(${project_name} PRIVATE ${CMAKE_SOURCE_DIR}/../sakura_core)
# use shared library version
# this is required when using parameterized test
if (BUILD_SHARED_LIBS)
# fix linker error "class testing::internal::Mutex testing::internal::g_linked_ptr_mutex"
target_compile_definitions(${project_name} PUBLIC -DGTEST_LINKED_AS_SHARED_LIBRARY=1)
# suppress warning
if (MSVC)
target_compile_options(${project_name} PUBLIC /wd4251 PUBLIC /wd4275)
endif(MSVC)
endif (BUILD_SHARED_LIBS)
# Hacks to reuse compiled editor objects.
target_compile_definitions(${project_name} PRIVATE WIN32 _WIN32_WINNT=_WIN32_WINNT_WIN7)
if (MSVC)
target_compile_options (${project_name} PRIVATE $<$<CONFIG:Release>:/GL> /MT$<$<CONFIG:Debug>:d> /GF /FD /EHsc /Zi /TP /source-charset:utf-8 /execution-charset:shift_jis)
target_link_libraries (${project_name} PRIVATE $<$<CONFIG:Release>:-LTCG> "${CMAKE_CURRENT_LIST_DIR}/../../sakura/${CMAKE_GENERATOR_PLATFORM}/$<CONFIG>/*.obj")
set_target_properties (${project_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_GENERATOR_PLATFORM}/$<CONFIG>"
)
elseif (MINGW)
target_compile_options (${project_name} PRIVATE -finput-charset=utf-8 -fexec-charset=cp932)
target_compile_definitions (${project_name} PUBLIC $<$<CONFIG:Debug>:_DEBUG>)
file (GLOB_RECURSE ALL_O
"${CMAKE_CURRENT_LIST_DIR}/../../sakura_core/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../../sakura_core/*.rc"
)
list (TRANSFORM ALL_O REPLACE "\\.(cpp|rc)$" ".o")
target_link_libraries (${project_name} PRIVATE ${ALL_O})
endif ()
# link with GoogleTest
if(BUILD_GTEST)
# Build GoogleTest from source code.
target_link_libraries(${project_name} PRIVATE gtest)
target_link_libraries(${project_name} PRIVATE gtest_main)
else()
# Build without GoogleTest(use system library).
find_package(GTest REQUIRED)
target_link_libraries(${project_name} PRIVATE GTest::GTest)
target_link_libraries(${project_name} PRIVATE GTest::Main)
endif()
# link libraries
target_link_libraries (${project_name} PRIVATE winspool ole32 oleaut32 uuid comctl32 imm32 mpr imagehlp shlwapi winmm windowscodecs msimg32)