-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
85 lines (73 loc) · 3.01 KB
/
CMakeLists.txt
File metadata and controls
85 lines (73 loc) · 3.01 KB
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
# Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# unless required by applicable law or agreed to in writing, software distributed under the
# license is distributed on an "as is" basis, without warranties or conditions of any kind,
# either express or implied. see the license for the specific language governing permissions
# and limitations under the license.
cmake_minimum_required(VERSION 3.13)
project(RttrAutoRegister)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
if (MSVC)
add_compile_options("/utf-8")
endif (MSVC)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-DDEBUG)
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-ffunction-sections -fdata-sections)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
endif()
endif ()
set(RTTR_INCLUDES vendor/libclang/include)
set(RTTR_LIBRARIES "")
if (NOT CMAKE_PREFIX_PATH)
# set your own llvm install path
set(CMAKE_PREFIX_PATH "")
endif()
set(RTTR_SOURCE_FILES
src/main.cpp
src/register.h
src/register.cpp
src/CLI11.hpp
src/clangraii/clangString.h
src/clangraii/translationUnit.h
src/clangraii/clangIndex.h
src/clangraii/clangDiagnostic.h
)
list(APPEND RTTR_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/include")
add_executable(RttrAutoRegister ${RTTR_SOURCE_FILES})
if(APPLE)
find_library(COREFOUNDATION CoreFoundation)
list(APPEND RTTR_LIBRARIES "${COREFOUNDATION}")
find_library(SECURITY Security)
list(APPEND RTTR_LIBRARIES "${SECURITY}")
find_library(ZLIB z)
list(APPEND RTTR_LIBRARIES "${ZLIB}")
execute_process(COMMAND bash -c "unzip ${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/mac/lib/libclang.a.zip -d ${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/mac/lib")
file(GLOB CLANG_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/mac/lib/libclang.a")
list(APPEND RTTR_LIBRARIES ${CLANG_LIBRARIES})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND strip "$<TARGET_FILE:${PROJECT_NAME}>"
COMMENT "Strip debug symbols done on final binary.")
elseif (WIN32)
file(GLOB CLANG_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/win/lib/libclang.lib")
list(APPEND RTTR_LIBRARIES ${CLANG_LIBRARIES})
add_custom_command(TARGET RttrAutoRegister POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/vendor/libclang/win/lib/libclang.dll
$<TARGET_FILE_DIR:RttrAutoRegister>/libclang.dll
COMMENT "正在复制文件..."
VERBATIM
)
endif()
target_include_directories(RttrAutoRegister PRIVATE ${RTTR_INCLUDES})
target_link_libraries(RttrAutoRegister PRIVATE ${RTTR_LIBRARIES})