forked from Koihik/LuaFormatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
135 lines (107 loc) · 4.04 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
cmake_minimum_required(VERSION 3.9)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
project("lua-formatter" VERSION 1.3.0 LANGUAGES CXX)
option(BUILD_TESTS "set ON to build tests" ON)
option(COVERAGE "set ON to enable coverage" ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(CheckIPOSupported)
check_ipo_supported(RESULT lto OUTPUT error)
if(lto)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
# The code is modified from
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
include(CheckIncludeFileCXX)
check_include_file_cxx("filesystem" HAVE_FILESYSTEM_H)
if(NOT HAVE_FILESYSTEM_H)
message(WARNING "filesystem not found, use experimental/filesystem as fallback."
" It's recommended to use a stable C++17 compliant compiler/libstdc++.")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/ConfigCheck.h)
if(NOT CMAKE_BUILD_TYPE)
message("set build type to Release.")
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_CXX_COMPILER_VERSION LESS 9))))
set(extra-libs "stdc++fs")
else()
set(extra-libs "")
endif()
try_run(TEST_RUN_RESULT
TEST_COMPILE_RESULT
${CMAKE_CURRENT_BINARY_DIR}/
${PROJECT_SOURCE_DIR}/test/cpp17/fs.cpp
LINK_LIBRARIES ${extra-libs}
OUTPUT_VARIABLE var)
message("${var}")
if(NOT "${TEST_COMPILE_RESULT}" OR (NOT "${TEST_RUN_RESULT}" EQUAL 0))
message(FATAL_ERROR "Your compiler does not fully support the C++17 standard and libraries")
endif()
include_directories(
${PROJECT_SOURCE_DIR}/generated/
${PROJECT_SOURCE_DIR}/third_party/
${PROJECT_SOURCE_DIR}/third_party/Catch2/single_include
${PROJECT_SOURCE_DIR}/third_party/yaml-cpp/include
${PROJECT_SOURCE_DIR}/third_party/antlr4/runtime/Cpp/runtime/src
${PROJECT_SOURCE_DIR}/src/
)
set(src_dir
${PROJECT_SOURCE_DIR}/src/lua-format.cpp
${PROJECT_SOURCE_DIR}/src/Config.cpp
${PROJECT_SOURCE_DIR}/src/FormatVisitor.cpp
${PROJECT_SOURCE_DIR}/generated/LuaLexer.cpp
${PROJECT_SOURCE_DIR}/generated/LuaParser.cpp
${PROJECT_SOURCE_DIR}/generated/LuaVisitor.cpp
${PROJECT_SOURCE_DIR}/generated/LuaBaseVisitor.cpp
)
file(GLOB_RECURSE antlr4-cpp-src
${PROJECT_SOURCE_DIR}/third_party/antlr4/runtime/Cpp/runtime/src/*.cpp
)
file(GLOB_RECURSE yaml-cpp-src
${PROJECT_SOURCE_DIR}/third_party/yaml-cpp/src/*.cpp
)
add_library (antlr4-cpp-runtime ${antlr4-cpp-src})
add_library (yaml-cpp ${yaml-cpp-src})
add_executable(lua-format ${src_dir} src/main.cpp)
if(WIN32)
target_compile_definitions(antlr4-cpp-runtime PRIVATE ANTLR4CPP_EXPORTS)
target_compile_definitions(yaml-cpp PRIVATE YAMLCPP_EXPORTS)
endif()
set_target_properties(lua-format PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(lua-format yaml-cpp antlr4-cpp-runtime ${extra-libs})
install(TARGETS lua-format
RUNTIME DESTINATION bin
)
if(BUILD_TESTS)
message("BUILD_TESTS enabled.")
enable_testing()
add_executable(lua-format-test
${src_dir}
test/test.cpp
test/test_config.cpp
test/test_format_file.cpp
test/test_parser.cpp
test/test_args.cpp
test/test_validation.cpp
)
set_target_properties(lua-format-test PROPERTIES LINKER_LANGUAGE CXX)
if(COVERAGE AND CMAKE_BUILD_TYPE MATCHES "Debug")
message("COVERAGE enabled.")
set_target_properties(lua-format-test
PROPERTIES COMPILE_FLAGS "-fprofile-arcs -ftest-coverage ${CMAKE_CXX_FLAGS}"
LINK_FLAGS "-fprofile-arcs"
)
endif()
target_compile_definitions(lua-format-test PUBLIC PROJECT_PATH="${PROJECT_SOURCE_DIR}")
target_link_libraries(lua-format-test yaml-cpp antlr4-cpp-runtime ${extra-libs})
add_test(all_tests lua-format-test)
endif()