@@ -24,6 +24,7 @@ function(add_phasar_unittest test_name)
2424 phasar_mono
2525 phasar_db
2626 phasar_experimental
27+
2728 # phasar_clang
2829 phasar_passes
2930 phasar_pointer
@@ -49,23 +50,28 @@ endfunction()
4950function (generate_ll_file)
5051 set (options MEM2REG DEBUG O1 O2 O3)
5152 set (testfile FILE)
52- cmake_parse_arguments (GEN_LL "${options} " "${testfile} " "" ${ARGN} )
53+ cmake_parse_arguments (GEN_LL "${options} " "${testfile} " "" ${ARGN} )
54+
5355 # get file extension
5456 get_filename_component (test_code_file_ext ${GEN_LL_FILE} EXT )
5557 string (REPLACE "." "_" ll_file_suffix ${test_code_file_ext} )
58+
5659 # define .ll file name
57- # set(ll_file_suffix "_${test_code_file_ext}")
60+ # set(ll_file_suffix "_${test_code_file_ext}")
5861 if (GEN_LL_MEM2REG)
5962 set (ll_file_suffix "${ll_file_suffix} _m2r" )
6063 endif ()
64+
6165 if (GEN_LL_DEBUG)
6266 set (ll_file_suffix "${ll_file_suffix} _dbg" )
6367 endif ()
64- # set(ll_file_suffix "${ll_file_suffix}.ll")
68+
69+ # set(ll_file_suffix "${ll_file_suffix}.ll")
6570 string (REPLACE ${test_code_file_ext}
6671 "${ll_file_suffix} .ll" test_code_ll_file
6772 ${GEN_LL_FILE}
6873 )
74+
6975 # get file path
7076 set (test_code_file_path "${CMAKE_CURRENT_SOURCE_DIR} /${GEN_LL_FILE} " )
7177
@@ -79,31 +85,37 @@ function(generate_ll_file)
7985 set (GEN_CXX_FLAGS -std=c++17 -fno-discard-value -names -emit-llvm -S)
8086 set (GEN_C_FLAGS -fno-discard-value -names -emit-llvm -S)
8187 set (GEN_CMD_COMMENT "[LL]" )
88+
8289 if (GEN_LL_MEM2REG)
8390 list (APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone)
8491 list (APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone)
8592 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} [M2R]" )
8693 endif ()
94+
8795 if (GEN_LL_DEBUG)
8896 list (APPEND GEN_CXX_FLAGS -g)
8997 list (APPEND GEN_C_FLAGS -g)
9098 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} [DBG]" )
9199 endif ()
100+
92101 if (GEN_LL_O1)
93102 list (APPEND GEN_CXX_FLAGS -O1)
94103 list (APPEND GEN_C_FLAGS -O1)
95104 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} [O1]" )
96105 endif ()
106+
97107 if (GEN_LL_O2)
98108 list (APPEND GEN_CXX_FLAGS -O2)
99109 list (APPEND GEN_C_FLAGS -O2)
100110 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} [O2]" )
101111 endif ()
112+
102113 if (GEN_LL_03)
103114 list (APPEND GEN_CXX_FLAGS -O3)
104115 list (APPEND GEN_C_FLAGS -O3)
105116 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} [O3]" )
106117 endif ()
118+
107119 set (GEN_CMD_COMMENT "${GEN_CMD_COMMENT} ${GEN_LL_FILE} " )
108120
109121 # define .ll file generation command
@@ -114,6 +126,7 @@ function(generate_ll_file)
114126 set (GEN_CMD ${CMAKE_C_COMPILER_LAUNCHER} ${CMAKE_C_COMPILER} )
115127 list (APPEND GEN_CMD ${GEN_C_FLAGS} )
116128 endif ()
129+
117130 if (GEN_LL_MEM2REG)
118131 add_custom_command (
119132 OUTPUT ${test_code_ll_file}
@@ -125,13 +138,14 @@ function(generate_ll_file)
125138 )
126139 else ()
127140 add_custom_command (
128- OUTPUT ${test_code_ll_file}
129- COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
130- COMMENT ${GEN_CMD_COMMENT}
131- DEPENDS ${GEN_LL_FILE}
132- VERBATIM
141+ OUTPUT ${test_code_ll_file}
142+ COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file}
143+ COMMENT ${GEN_CMD_COMMENT}
144+ DEPENDS ${GEN_LL_FILE}
145+ VERBATIM
133146 )
134147 endif ()
148+
135149 add_custom_target (${test_code_file_target}
136150 DEPENDS ${test_code_ll_file}
137151 )
@@ -141,41 +155,46 @@ endfunction()
141155macro (add_phasar_executable name )
142156 set (LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR} /${CMAKE_CFG_INTDIR} /bin)
143157 set (LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR} /${CMAKE_CFG_INTDIR} /lib)
144- add_llvm_executable( ${name} ${ARGN} )
158+ add_llvm_executable(${name} ${ARGN} )
145159 set_target_properties (${name} PROPERTIES FOLDER "phasar_executables" )
146- install (TARGETS ${name}
160+ install (TARGETS ${name}
147161 RUNTIME DESTINATION bin
148162 )
149163endmacro (add_phasar_executable)
150164
151165macro (add_phasar_library name )
152166 set (srcs ${ARGN} )
167+
153168 if (MSVC_IDE OR XCODE)
154- file ( GLOB_RECURSE headers *.h *.td *.def)
169+ file (GLOB_RECURSE headers *.h *.td *.def)
155170 set (srcs ${srcs} ${headers} )
156- string ( REGEX MATCHALL "/[^/]" split_path ${CMAKE_CURRENT_SOURCE_DIR} )
157- list ( GET split_path -1 dir)
158- file ( GLOB_RECURSE headers
171+ string (REGEX MATCHALL "/[^/]" split_path ${CMAKE_CURRENT_SOURCE_DIR} )
172+ list (GET split_path -1 dir)
173+ file (GLOB_RECURSE headers
159174 ../../include /phasar${dir} /*.h)
160175 set (srcs ${srcs} ${headers} )
161176 endif (MSVC_IDE OR XCODE)
162- if (MODULE)
177+
178+ if (MODULE)
163179 set (libkind MODULE)
164- elseif (SHARED_LIBRARY)
180+ elseif (SHARED_LIBRARY)
165181 set (libkind SHARED)
166182 else ()
167183 set (libkind)
168184 endif ()
169- add_library ( ${name} ${libkind} ${srcs} )
170- add_library ( phasar::${name} ALIAS ${name} )
171- if ( LLVM_COMMON_DEPENDS )
172- add_dependencies ( ${name} ${LLVM_COMMON_DEPENDS} )
173- endif ( LLVM_COMMON_DEPENDS )
174- if ( LLVM_USED_LIBS )
185+
186+ add_library (${name} ${libkind} ${srcs} )
187+ add_library (phasar::${name} ALIAS ${name} )
188+
189+ if (LLVM_COMMON_DEPENDS)
190+ add_dependencies (${name} ${LLVM_COMMON_DEPENDS} )
191+ endif (LLVM_COMMON_DEPENDS)
192+
193+ if (LLVM_USED_LIBS)
175194 foreach (lib ${LLVM_USED_LIBS} )
176- target_link_libraries ( ${name} ${lib} )
195+ target_link_libraries (${name} ${lib} )
177196 endforeach (lib)
178- endif ( LLVM_USED_LIBS )
197+ endif (LLVM_USED_LIBS)
179198
180199 if (PHASAR_LINK_LIBS)
181200 foreach (lib ${PHASAR_LINK_LIBS} )
@@ -187,65 +206,71 @@ macro(add_phasar_library name)
187206 endforeach (lib)
188207 endif (PHASAR_LINK_LIBS)
189208
190- if ( LLVM_LINK_COMPONENTS )
191- if ( USE_LLVM_FAT_LIB )
209+ if (LLVM_LINK_COMPONENTS)
210+ if (USE_LLVM_FAT_LIB)
192211 llvm_config(${name} USE_SHARED ${LLVM_LINK_COMPONENTS} )
193212 else ()
194213 llvm_config(${name} ${LLVM_LINK_COMPONENTS} )
195214 endif ()
196- endif ( LLVM_LINK_COMPONENTS )
215+ endif (LLVM_LINK_COMPONENTS)
216+
197217 if (MSVC )
198218 get_target_property (cflag ${name} COMPILE_FLAGS )
219+
199220 if (NOT cflag)
200221 set (cflag "" )
201222 endif (NOT cflag)
223+
202224 set (cflag "${cflag} /Za" )
203225 set_target_properties (${name} PROPERTIES COMPILE_FLAGS ${cflag} )
204226 endif (MSVC )
205- #cut off prefix phasar_ for convenient component names
227+
228+ # cut off prefix phasar_ for convenient component names
206229 string (REGEX REPLACE phasar_ "" name component_name)
230+
207231 if (PHASAR_IN_TREE)
208232 install (TARGETS ${name}
209233 EXPORT LLVMExports
210234 LIBRARY DESTINATION lib
211235 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} )
212236 else ()
213- install (TARGETS ${name}
214- EXPORT phasarTargets
215- LIBRARY DESTINATION ${PHASAR_INSTALL_LIBDIR}
216- ARCHIVE DESTINATION ${PHASAR_INSTALL_LIBDIR} )
217237 install (TARGETS ${name}
218238 EXPORT ${name} -targets
219239 COMPONENT ${component_name}
220- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/phasar
221- LIBRARY DESTINATION ${PHASAR_INSTALL_LIBDIR}
222- ARCHIVE DESTINATION ${PHASAR_INSTALL_LIBDIR} )
240+
241+ # NOTE: Library, archive and runtime destination are automatically set by
242+ # GNUInstallDirs which is included in the top-level CMakeLists.txt
243+ )
223244 install (EXPORT ${name} -targets
224245 FILE ${name} -targets.cmake
225246 NAMESPACE phasar::
226- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/phasar
227- COMPONENT ${component_name} )
228- install (FILES ${name} -config.cmake
229- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/phasar)
247+ DESTINATION lib/cmake/phasar
248+ COMPONENT ${component_name}
249+ )
230250 endif ()
251+
231252 set_property (GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name} )
232253endmacro (add_phasar_library)
233254
234255macro (add_phasar_loadable_module name )
235256 set (srcs ${ARGN} )
257+
236258 # klduge: pass different values for MODULE with multiple targets in same dir
237259 # this allows building shared-lib and module in same dir
238260 # there must be a cleaner way to achieve this....
239- if (MODULE)
261+ if (MODULE)
240262 else ()
241263 set (GLOBAL_NOT_MODULE TRUE )
242264 endif ()
265+
243266 set (MODULE TRUE )
244267 add_phasar_library(${name} ${srcs} )
245- if (GLOBAL_NOT_MODULE)
246- unset (MODULE)
268+
269+ if (GLOBAL_NOT_MODULE)
270+ unset (MODULE)
247271 endif ()
248- if (APPLE )
272+
273+ if (APPLE )
249274 # Darwin-specific linker flags for loadable modules.
250275 set_target_properties (${name} PROPERTIES
251276 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress" )
@@ -255,10 +280,12 @@ endmacro(add_phasar_loadable_module)
255280macro (subdirlist result curdir)
256281 file (GLOB children RELATIVE ${curdir} ${curdir} /*)
257282 set (dirlist "" )
283+
258284 foreach (child ${children} )
259285 if (IS_DIRECTORY ${curdir} /${child} )
260286 list (APPEND dirlist ${child} )
261287 endif ()
262288 endforeach ()
289+
263290 set (${result} ${dirlist} )
264291endmacro (subdirlist)
0 commit comments