-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
143 lines (111 loc) · 3.92 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
cmake_minimum_required(VERSION 3.22)
# Project setup
set(CMAKE_OSX_ARCHITECTURES arm64;x86_64)
project(phosg)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if (MSVC)
# Disabled warnings:
# 4458 = declaration of '%s' hides class member (I use this->x for members)
add_compile_options(/W4 /WX /wd4458)
else()
add_compile_options(-Wall -Wextra -Werror -Wno-strict-aliasing -Wno-unused-result -Wno-overflow)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_TYPE Debug)
set(CTEST_OUTPUT_ON_FAILURE ON)
# Library and executable definitions
add_library(
phosg
src/Arguments.cc
src/Encoding.cc
src/Filesystem.cc
src/Hash.cc
src/Image.cc
src/JSON.cc
src/Network.cc
src/Process.cc
src/Random.cc
src/Strings.cc
src/Time.cc
src/Tools.cc
src/UnitTest.cc
)
target_link_libraries(phosg pthread z)
target_include_directories(
phosg PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
# It seems that on some Linux variants (e.g. Raspbian) we also need -latomic,
# but this library does not exist on others (e.g. Ubuntu) nor on macOS
message(STATUS "Target architecture is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
string(FIND ${CMAKE_HOST_SYSTEM_PROCESSOR} "armv" IS_LINUX_ARMV)
if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${IS_LINUX_ARMV} GREATER_EQUAL 0)
target_link_libraries(phosg atomic)
endif()
add_executable(bindiff src/BinDiff.cc)
target_link_libraries(bindiff phosg)
add_executable(jsonformat src/JSONFormat.cc)
target_link_libraries(jsonformat phosg)
add_executable(parse-data src/ParseData.cc)
target_link_libraries(parse-data phosg)
add_executable(phosg-png-conv src/PhosgPNGConv.cc)
target_link_libraries(phosg-png-conv phosg)
# Test definitions
enable_testing()
# TODO: Figure out why ToolsTest doesn't work in GitHub Actions and add it back.
# (It works locally on macOS and Ubuntu.)
add_executable(ToolsTest src/ToolsTest.cc)
target_link_libraries(ToolsTest phosg)
foreach(TestName IN ITEMS ArgumentsTest EncodingTest FilesystemTest HashTest ImageTest JSONTest KDTreeTest LRUMapTest LRUSetTest ProcessTest StringsTest TimeTest UnitTestTest)
add_executable(${TestName} src/${TestName}.cc)
target_link_libraries(${TestName} phosg)
add_test(NAME ${TestName} COMMAND ${TestName})
endforeach()
# Installation configuration
# Package setup
install(
TARGETS phosg
EXPORT phosg
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Header files
file(GLOB Headers ${CMAKE_SOURCE_DIR}/src/*.hh)
install(FILES ${Headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/phosg)
# Export definition
install(
EXPORT phosg
FILE phosg.cmake
NAMESPACE phosg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg
)
# CMake config files
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/phosgConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/phosgConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg
)
set(version 0.1)
set_property(TARGET phosg PROPERTY VERSION ${version})
set_property(TARGET phosg PROPERTY SOVERSION 0)
set_property(TARGET phosg PROPERTY INTERFACE_phosg_MAJOR_VERSION 0)
set_property(TARGET phosg APPEND PROPERTY COMPATIBLE_INTERFACE_STRING phosg_MAJOR_VERSION)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/phosgConfigVersion.cmake"
VERSION "${version}"
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/phosgConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/phosgConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg
)
# Executables (separate from package definition)
install(TARGETS bindiff DESTINATION bin)
install(TARGETS jsonformat DESTINATION bin)
install(TARGETS parse-data DESTINATION bin)
install(TARGETS phosg-png-conv DESTINATION bin)