-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakelists.txt
165 lines (129 loc) · 5.46 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# ------ Set Options for Projects --------------- #
MESSAGE( STATUS "Set Options for Project")
## CMake minimum version required
CMAKE_MINIMUM_REQUIRED( VERSION 3.20 )
## Make Project Name
SET( PROJECT_NAME "MemoryProject" )
## Project name
PROJECT( ${PROJECT_NAME} )
if( MSVC )
MESSAGE( STATUS "Compiler is ${CMAKE_CXX_COMPILER_ID}")
# Use multi-process debugging
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /MP")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi /MP")
# Use Windbg as the debugger
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DEBUG:FULL")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DEBUG:FULL")
SET(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} /DEBUG /INCREMENTAL:NO")
ENDIF()
## Set CXX Compiler Version
SET( CMAKE_CXX_STANDARD 17 )
MESSAGE( STATUS "Setting Done")
# ----------------------------------------------- #
# ------ Set Path ------------------------------ #
MESSAGE( STATUS "Set Path ")
## Set Directories
SET( MAIN_DIR ${CMAKE_SOURCE_DIR} )
SET( DEMOFILE_DIR ${MAIN_DIR}/externaldemofile )
SET( MEMORYMANAGER_DIR ${MAIN_DIR}/MemoryManager )
SET( MEMORYPOOL_DIR ${MAIN_DIR}/OnlyMemoryPool )
SET( MEMORYPTR_DIR ${MAIN_DIR}/MemoryPtr )
SET( SOURCE_DIR )
SET( FOLDER_DIR )
MESSAGE( STATUS "Setting Done ")
# ------------------------------------------------ #
# ------- Set Option ----------------------------- #
MESSAGE( STATUS "Set Option" )
## Set Option for the library is dynamics or static, the main install is memory manager or memory pool and the demo file is installed or not
OPTION( BUILD_STATIC_LIBRARY "Set option for the library which is static or dynamic" OFF )
OPTION( INSTALL_MEMORY_MANAGER "Install Memory Manager or Memory Pool" ON )
OPTION( INSTALL_DEMO_FILE "Install demofile for memorymanager" OFF )
## Set Option for install lib, header files' path
SET( PREFIX_DIR ${MAIN_DIR}/build/Prefix CACHE PATH "Prefix Path" )
SET( INCLUDE_DIR ${MAIN_DIR}/build/include CACHE PATH "Header files Path" )
SET( ARC_DIR ${MAIN_DIR}/build/arc CACHE PATH "Archieve files Path" )
SET( LIB_DIR ${MAIN_DIR}/build/lib CACHE PATH "Library files Path" )
SET( BIN_DIR ${MAIN_DIR}/build/bin CACHE PATH "Execute files Path" )
SET( CMAKE_BUILD_TYPE Debug CACHE STRING "Build Type" )
INCLUDE( Dependency.cmake )
IF ( INSTALL_MEMORY_MANAGER )
INCLUDE_DIRECTORIES( ${MEMORYMANAGER_DIR} ${MEMORYPTR_DIR} )
LIST( APPEND FOLDER_DIR ${MEMORYMANAGER_DIR} ${MEMORYPTR_DIR} )
LIST( APPEND SOURCE_DIR
${MEMORYPTR_DIR}/MemoryPtr.h
${MEMORYMANAGER_DIR}/IMemoryPool.h
${MEMORYMANAGER_DIR}/MemoryPool.h
${MEMORYMANAGER_DIR}/MemoryManager.h ${MEMORYMANAGER_DIR}/MemoryManager.cpp
)
MESSAGE( STATUS "Install Memory Manager" )
ELSE()
INCLUDE_DIRECTORIES( ${MEMORYPOOL_DIR} ${MEMORYPTR_DIR} )
LIST( APPEND FOLDER_DIR ${MEMORYMANAGER_DIR} ${MEMORYPTR_DIR} )
LIST( APPEND SOURCE_DIR
${MEMORYPTR_DIR}/MemoryPtr.h
${MEMORYPOOL_DIR}/MemoryPtr.h
${MEMORYPOOL_DIR}/MemoryPool.h ${MEMORYPOOL_DIR}/MemoryPool.cpp
)
MESSAGE( STATUS "Install only Memory Pool" )
ENDIF()
IF ( WIN32 )
MESSAGE( STATUS "Windows Platform for library")
SET( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1 )
ENDIF()
MESSAGE( STATUS "Setting Done ")
# ----------------------------------------------- #
# ------ Create library ---------------- #
MESSAGE(STATUS "Create Library ")
IF ( BUILD_STATIC_LIBRARY )
ADD_LIBRARY( ${PROJECT_NAME} STATIC ${SOURCE_DIR} )
MESSAGE( STATUS "Build library as a static" )
ELSE ()
ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SOURCE_DIR} )
MESSAGE( STATUS "Build library as a dynamic" )
ENDIF()
FOREACH( FOLDER ${FOLDER_DIR} )
FILE( COPY ${FOLDER}/ DESTINATION ${INCLUDE_DIR}/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h" )
ENDFOREACH()
IF ( CMAKE_BUILD_TYPE MATCHES Debug )
SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${ARC_DIR}
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${LIB_DIR}
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BIN_DIR}
)
MESSAGE( STATUS "Build library on Debug mode" )
ELSEIF ( CMAKE_BUILD_TYPE MATCHES Release )
SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${ARC_DIR}
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${LIB_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BIN_DIR}
)
MESSAGE( STATUS "Build library on Release mode" )
ELSE()
SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${ARC_DIR}
LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR}
RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR}
)
MESSAGE( STATUS "Build library on Other mode" )
ENDIF()
MESSAGE( STATUS "Creating Done ")
# ----------------------------------------------- #
# ------ Set Options for Target Files ----------- #
MESSAGE(STATUS "Set Options for Target Files")
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${FOLDER_DIR} ${DEP_INCLUDE})
TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC ${LIB_DIR})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${DEP_LIBS})
ADD_DEPENDENCIES(${PROJECT_NAME} ${DEP_LIST})
MESSAGE(STATUS "Setting Done ")
# ----------------------------------------------- #
# ------ Create Demofile ------------------------ #
MESSAGE( STATUS "Create Demofile")
IF ( INSTALL_DEMO_FILE )
ADD_SUBDIRECTORY( ${DEMOFILE_DIR} )
MESSAGE( STATUS "Install Demofile that use Log" )
ELSE()
MESSAGE( STATUS "Do not install MemoryProject's Demofile" )
ENDIF()
MESSAGE( STATUS "Create Done")
# ----------------------------------------------- #