-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
101 lines (82 loc) · 3.03 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
#-------------------------------------------------------------------------------
# CMAKE SETTINGS
#-------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.12)
#-------------------------------------------------------------------------------
# COMMAND SOURCE CODE
#-------------------------------------------------------------------------------
# .cpp files
list(APPEND COMMAND_SOURCE_FILES
src/commands/command
src/commands/echo.cpp
src/commands/wait.cpp
)
#-------------------------------------------------------------------------------
# SOURCE CODE
#-------------------------------------------------------------------------------
# .h files
list(APPEND HEADER_FILES
src/command.h
src/commandCallback.h
src/parser.h
src/script.h
)
# .cpp files
list(APPEND SOURCE_FILES
src/command.cpp
src/main.cpp
src/parser.cpp
src/script.cpp
)
# on windows, append headers to source so they show up in visual studio
if(WIN32)
LIST(APPEND SOURCE_FILES ${HEADER_FILES})
endif()
# Set the project name
PROJECT(script)
#-------------------------------------------------------------------------------
# COMPILE FLAGS
#-------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
add_compile_options(/MP)
elseif(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-std=c++17)
endif(MSVC)
#-------------------------------------------------------------------------------
# HELPERS
#-------------------------------------------------------------------------------
# Helper function to add preprocesor definition of FILE_BASENAME
# to pass the filename without directory path for debugging use.
#
# Example:
#
# define_file_basename_for_sources(my_target)
#
# Will add -DFILE_BASENAME="filename" for each source file depended on
# by my_target, where filename is the name of the file.
#
function(define_file_basename_for_sources targetname)
get_target_property(source_files "${targetname}" SOURCES)
foreach(sourcefile ${source_files})
# Get source file's current list of compile definitions.
get_property(defs SOURCE "${sourcefile}"
PROPERTY COMPILE_DEFINITIONS)
# Add the FILE_BASENAME=filename compile definition to the list.
get_filename_component(basename "${sourcefile}" NAME_WE)
list(APPEND defs "FILE_BASENAME=${basename}")
# Set the updated compile definitions on the source file.
set_property(
SOURCE "${sourcefile}"
PROPERTY COMPILE_DEFINITIONS ${defs})
endforeach()
endfunction()
#-------------------------------------------------------------------------------
# GENERATE EXECUTABLE
#-------------------------------------------------------------------------------
# Set additional include directories
include_directories(${INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/commands)
# Generate the executable
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${COMMAND_SOURCE_FILES})
define_file_basename_for_sources(${PROJECT_NAME})