-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
139 lines (116 loc) · 4.06 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
cmake_minimum_required(VERSION 3.14)
project(dmf2mod VERSION "0.2.0")
set(PROJECT_VERSION_STAGE "alpha")
if(PROJECT_VERSION_STAGE)
set(PROJECT_VERSION "${PROJECT_VERSION}-${PROJECT_VERSION_STAGE}")
endif()
enable_language(CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(DMF2MOD_ROOT ${PROJECT_SOURCE_DIR})
set(SRC ${DMF2MOD_ROOT}/src)
set(INC ${DMF2MOD_ROOT}/include)
# Configure version
configure_file(${INC}/version.h.in ${INC}/version.h)
# Source files
set(CORE_SOURCES
${SRC}/dmf2mod.cpp
${SRC}/core/conversion_options.cpp
${SRC}/core/factory.cpp
${SRC}/core/global_options.cpp
${SRC}/core/module.cpp
${SRC}/core/options.cpp
${SRC}/core/status.cpp
)
set(MODULE_SOURCES
${SRC}/modules/dmf.cpp
${SRC}/modules/mod.cpp
${SRC}/modules/debug.cpp
)
set(UTILS_SOURCES
${SRC}/utils/utils.cpp
)
set(DMF2MOD_SOURCES ${CORE_SOURCES} ${MODULE_SOURCES} ${UTILS_SOURCES})
set(INC_DIRS
${DMF2MOD_ROOT}/extern
${DMF2MOD_ROOT}/extern/zstr
${DMF2MOD_ROOT}/extern/zlib
${DMF2MOD_ROOT}/extern/gcem/include
${DMF2MOD_ROOT}/include
${PROJECT_BINARY_DIR}
)
option(BUILD_CONSOLE "Build dmf2mod command-line application" TRUE)
option(ENABLE_CPPCHECK "Enable testing with cppcheck" FALSE)
# Set default build type if none was specified
set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Asan" "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Set up address sanitizer
if(CMAKE_BUILD_TYPE STREQUAL "Asan")
message(STATUS "Using address sanitizer")
add_compile_options(${CMAKE_CXX_FLAGS_DEBUG})
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/fsanitize=address)
add_link_options(/fsanitize=address)
else()
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
endif()
# Display default configuration-specific flags (debugging and optimization flags)
message(STATUS "Debug flags: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "Release flags: ${CMAKE_CXX_FLAGS_RELEASE}")
# Set up Cppcheck static code analysis
if(ENABLE_CPPCHECK)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK
${CPPCHECK}
--suppress=syntaxError
--enable=all
--inconclusive)
else()
message(SEND_ERROR "cppcheck requested but executable not found")
endif()
endif()
if(EMSCRIPTEN)
# Web app build
add_subdirectory(webapp)
else()
# DMF2MOD library build
# Compiler-specific warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNING_FLAGS "-Wall -Wno-unknown-pragmas -Werror -Wno-error=cpp -Wno-error=unused-variable")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WARNING_FLAGS "-Wall -Wno-unknown-pragmas -Wno-\#warnings -Werror -Wno-error=unused-variable")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(WARNING_FLAGS "/W3") #/WX
else()
set(WARNING_FLAGS "")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
add_library(${PROJECT_NAME} STATIC ${DMF2MOD_SOURCES})
#set_target_properties(${PROJECT_NAME} PROPERTIES
# ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
# Build and link to the bundled zlib
set(ZLIB_ROOT ${DMF2MOD_ROOT}/extern/zlib)
add_subdirectory(${ZLIB_ROOT} EXCLUDE_FROM_ALL)
target_link_libraries(${PROJECT_NAME} PRIVATE zlibstatic)
# Includes
target_include_directories(${PROJECT_NAME} PRIVATE
${INC_DIRS}
${PROJECT_BINARY_DIR}/extern
${PROJECT_BINARY_DIR}/extern/zlib
)
target_include_directories(${PROJECT_NAME} PUBLIC
${INC}
${PROJECT_BINARY_DIR}
)
if(BUILD_CONSOLE)
add_subdirectory(console)
endif()
endif()