@@ -15,14 +15,22 @@ set(CMAKE_CXX_STANDARD 17)
1515set (CMAKE_CXX_STANDARD_REQUIRED ON )
1616set (CMAKE_CXX_EXTENSIONS OFF )
1717
18+ include (GNUInstallDirs )
19+
1820set_property (GLOBAL PROPERTY TARGET_MESSAGES OFF )
1921
2022if (NOT CMAKE_BUILD_TYPE )
21- set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build mode ('Debug' or 'Release', default is 'Debug')" FORCE )
23+ set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build mode ('DebugSan' or ' Debug' or 'Release', default is 'Debug')" FORCE )
2224endif ()
23- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
25+
26+ if (CMAKE_BUILD_TYPE STREQUAL "DebugSan" )
27+ message (STATUS "Selected Debug Build with sanitizers" )
28+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g -fno-omit-frame-pointer -fsanitize=address,undefined" )
29+ elseif (CMAKE_BUILD_TYPE STREQUAL "Debug" )
30+ message (STATUS "Selected Debug Build" )
2431 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g" )
2532else ()
33+ message (STATUS "Selected Release Build" )
2634 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -march=native" )
2735endif ()
2836
@@ -41,7 +49,6 @@ file(STRINGS ${PHASAR_SRC_DIR}/include/phasar/Config/Version.h VERSION_NUMBER_FI
4149string (REPLACE " " ";" VERSION_NUMBER_FILE ${VERSION_NUMBER_FILE} )
4250list (GET VERSION_NUMBER_FILE 2 VERSION_NUMBER_PHASAR)
4351
44-
4552include ("phasar_macros" )
4653
4754option (PHASAR_BUILD_UNITTESTS "Build all tests (default is ON)" ON )
@@ -50,6 +57,8 @@ option(PHASAR_BUILD_OPENSSL_TS_UNITTESTS "Build OPENSSL typestate tests (require
5057
5158option (PHASAR_BUILD_IR "Build IR test code (default is ON)" ON )
5259
60+ option (PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD "Run clang-tidy during build (default is OFF)" OFF )
61+
5362option (PHASAR_BUILD_DOC "Build documentation" OFF )
5463
5564option (PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF )
@@ -94,12 +103,13 @@ endif()
94103configure_file (config.h.in config.h @ONLY )
95104include_directories (${CMAKE_CURRENT_BINARY_DIR} )
96105
97-
98106include_directories (
99107 ${PHASAR_SRC_DIR} /include
100108)
101109
102- set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX} /lib" )
110+ set (PHASAR_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} /phasar)
111+
112+ set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX} /${PHASAR_INSTALL_LIBDIR} )
103113set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
104114
105115if (LLVM_ENABLE_LIBCXX)
@@ -117,17 +127,38 @@ find_package(Boost 1.65.1 COMPONENTS filesystem graph system program_options log
117127#find_package(Boost 1.72.0 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
118128include_directories (${Boost_INCLUDE_DIRS} )
119129
120- # JSON library
121- option (JSON_BuildTests OFF )
122- set (JSON_Install ON )
123- add_subdirectory (external/json EXCLUDE_FROM_ALL )
130+ # Disable clang-tidy for the external projects
131+ set (CMAKE_CXX_CLANG_TIDY "" )
132+
133+ # We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here
134+ # The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator
135+ # is not installed, leading to linker error. But just including nlohmann_json is not sufficient, as
136+ # in the installed state the nlohmann_json_schema_validator needs the nlohmann_json package which needs
137+ # to be installed.
138+ # The following workaround may collapse or become unnecessary once the issue is
139+ # changed or fixed in nlohmann_json_schema_validator.
140+
141+ #Override option of nlohmann_json_schema_validator to not build its tests
142+ set (BUILD_TESTS OFF CACHE BOOL "Build json-schema-validator-tests" )
143+
144+ # Make nlohmann_json_schema_validator happy by telling it how to find the single include of nlohmann_json
124145include_directories (external/json/single_include/ )
125146
126- # JSON Schema Validator
127- set (BUILD_TESTS OFF )
128- set (BUILD_EXAMPLES OFF )
129- add_subdirectory (external/json-schema-validator EXCLUDE_FROM_ALL )
130- include_directories (external/json-schema-validator/src )
147+ if (PHASAR_IN_TREE)
148+ set_property (GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json_schema_validator )
149+ endif ()
150+
151+ set (nlohmann_json_DIR ${PHASAR_SRC_DIR} /external/json/single_include/)
152+
153+ # Json Schema Validator
154+ set (JSON_VALIDATOR_INSTALL ON )
155+ add_subdirectory (external/json-schema-validator )
156+ include_directories (external/json-schema-validator/src/ )
157+
158+ # now we finally add the subdirectory
159+ set (JSON_BuildTests OFF )
160+ set (JSON_Install ON )
161+ add_subdirectory (external/json )
131162
132163# Googletest
133164if (NOT PHASAR_IN_TREE)
@@ -166,7 +197,7 @@ endif()
166197# Clang
167198# The clang-cpp shared library is now the preferred way to link dynamically against libclang if we build out of tree.
168199if (NOT PHASAR_IN_TREE)
169- find_library (CLANG_LIBRARY NAMES clang-cpp REQUIRED HINTS ${LLVM_LIBRARY_DIRS} )
200+ find_library (CLANG_LIBRARY NAMES clang-cpp libclang-cpp REQUIRED HINTS ${LLVM_LIBRARY_DIRS} )
170201 if (${CLANG_LIBRARY} STREQUAL "CLANG_LIBRARY-NOTFOUND" )
171202 set (NEED_LIBCLANG_COMPONENT_LIBS on )
172203 endif ()
@@ -214,8 +245,17 @@ endif()
214245add_subdirectory (external/WALi-OpenNWA )
215246include_directories (external/WALi-OpenNWA/Source/wali/include )
216247
248+ # Set up clang-tidy to run during PhASAR's compilation to indicate code smells
249+ if (PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD)
250+ message (STATUS "Enabled clang-tidy during build" )
251+ set (CMAKE_CXX_CLANG_TIDY
252+ clang-tidy;
253+ -header-filter=include/phasar.*h$;
254+ # -warnings-as-errors=*;
255+ )
256+ endif ()
217257
218- # Add the Phasar subdirectories
258+ # Add PhASAR's subdirectories
219259add_subdirectory (include )
220260add_subdirectory (lib )
221261
0 commit comments