-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
74 lines (53 loc) · 1.98 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
cmake_minimum_required(VERSION 3.22)
set(PROJ_TYPE EXECUTABLE) # EXECUTABLE or LIBRARY
set(PROJ_LIB_TYPE STATIC) # If LIBRARY (STATIC, SHARED or MODULE)
set(PROJ_NAME "ProjName")
set(SRC_DIR "src")
set(INC_DIR "include")
set(
SRC_FILES
"main.c"
)
project(
${PROJ_NAME}
VERSION 0.1
DESCRIPTION "A project"
LANGUAGES C CXX
)
###################
list(TRANSFORM SRC_FILES PREPEND "${SRC_DIR}/")
###################
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
if(UNIX)
message(STATUS "STATUS - ${PROJ_NAME}: Building for UNIX.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++2a")
# Override to newer compiler usually needed on ubuntu cause shits old
set(CMAKE_C_COMPILER gcc-13)
set(CMAKE_CXX_COMPILER g++-13)
add_compile_definitions(__unix__)
elseif(WIN32)
message(STATUS "STATUS - ${PROJ_NAME}: Building for Windows.")
add_compile_definitions(__win32__)
elseif(APPLE)
message(STATUS "STATUS - ${PROJ_NAME}: Building for Apple.")
add_compile_definitions(__apple__)
endif()
if(${PROJ_TYPE} MATCHES "EXECUTABLE")
message(STATUS "STATUS - ${PROJ_NAME}: Is built as EXECUTABLE.")
add_executable(${PROJ_NAME} ${SRC_FILES})
set(${PROJ_NAME}_BIN ${PROJ_NAME} PARENT_SCOPE) # Expose binary executable
elseif(${PROJ_TYPE} MATCHES "LIBRARY")
message(STATUS "STATUS - ${PROJ_NAME}: Is built as LIBRARY.")
add_library(${PROJ_NAME} ${PROJ_LIB_TYPE} ${SRC_FILES})
set(${PROJ_NAME}_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR} PARENT_SCOPE) # TODO: Add "current dir"
set(${PROJ_NAME}_LIB ${PROJ_NAME} PARENT_SCOPE) # Expose library
else()
message(FATAL_ERROR "ERROR - ${PROJ_NAME}: PROJ_TYPE in CMakeLists.txt wrongly set. Supported types are EXECUTABLE or LIBRARY.")
endif()
target_include_directories(${PROJ_NAME} PUBLIC ${INC_DIR})
if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
target_compile_definitions(${PROJ_NAME} PRIVATE _DEBUG)
else()
target_compile_definitions(${PROJ_NAME} PRIVATE _RELEASE)
endif()