Skip to content

Commit 3b494c2

Browse files
committed
vf cmake
1 parent 29f12ca commit 3b494c2

File tree

5 files changed

+53
-42
lines changed

5 files changed

+53
-42
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ ifeq ($(MATCHCOMPILER),yes)
2727
$(error Did not find a Python interpreter)
2828
endif
2929
ifdef VERIFY
30-
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)
30+
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --recursive --verify)
3131
else
32-
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)
32+
matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --recursive)
33+
endif
34+
ifneq ($(.SHELLSTATUS),0)
35+
$(error matchcompiler execution failed)
3336
endif
3437
libcppdir:=build
3538
else

lib/CMakeLists.txt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
file(GLOB_RECURSE hdrs "*.h")
2-
file(GLOB_RECURSE srcs "*.cpp")
1+
add_subdirectory(vf)
2+
3+
file(GLOB hdrs "*.h")
4+
file(GLOB srcs "*.cpp")
35

46
function(build_src output filename)
5-
get_filename_component(file ${filename} NAME)
6-
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/build/mc_${file})
7+
if (USE_MATCHCOMPILER_OPT STREQUAL "Off")
8+
set(${output} ${${output}} ${filename} PARENT_SCOPE)
9+
return()
10+
endif()
11+
12+
file(RELATIVE_PATH file ${CMAKE_CURRENT_SOURCE_DIR} ${filename})
13+
get_filename_component(basedir ${file} DIRECTORY)
14+
set(basedir "/${basedir}")
15+
get_filename_component(basename ${filename} NAME)
16+
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/build/${file})
717
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
818
if (USE_MATCHCOMPILER STREQUAL "Verify")
919
set(verify_option "--verify")
1020
endif()
1121
add_custom_command(
1222
OUTPUT ${outfile}
13-
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tools/matchcompiler.py"
14-
--read-dir="${CMAKE_CURRENT_SOURCE_DIR}"
15-
--prefix="mc_"
16-
--line
23+
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tools/matchcompiler.py"
24+
--read-dir="${CMAKE_CURRENT_SOURCE_DIR}${basedir}"
25+
--write-dir="${CMAKE_CURRENT_BINARY_DIR}/build${basedir}"
26+
--line
1727
${verify_option}
18-
${file}
28+
${basename}
1929
DEPENDS ${file}
2030
DEPENDS ${PROJECT_SOURCE_DIR}/tools/matchcompiler.py
2131
)
2232
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
2333
endfunction()
2434

25-
if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
26-
foreach(file ${srcs})
27-
build_src(srcs_build ${file})
28-
endforeach()
29-
30-
set(srcs_lib ${srcs_build})
31-
else()
32-
set(srcs_lib ${srcs})
33-
endif()
35+
foreach(file ${srcs} ${vf_srcs})
36+
build_src(srcs_lib ${file})
37+
endforeach()
3438

3539
if (BUILD_CORE_DLL)
36-
add_library(cppcheck-core SHARED ${srcs_lib} ${hdrs} $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs> version.rc)
40+
add_library(cppcheck-core SHARED ${srcs_lib} ${hdrs} ${vf_hdrs} $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs> version.rc)
3741
target_compile_definitions(cppcheck-core PRIVATE CPPCHECKLIB_EXPORT TINYXML2_EXPORT SIMPLECPP_EXPORT)
3842
else()
39-
add_library(cppcheck-core OBJECT ${srcs_lib} ${hdrs})
43+
add_library(cppcheck-core OBJECT ${srcs_lib} ${hdrs} ${vf_hdrs})
4044
endif()
4145
target_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
4246
if(USE_BUNDLED_TINYXML2)

lib/vf/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(GLOB hdrs "*.h")
2+
file(GLOB srcs "*.cpp")
3+
4+
set(vf_hdrs ${hdrs} PARENT_SCOPE)
5+
set(vf_srcs ${srcs} PARENT_SCOPE)

tools/dmake.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,12 @@ int main(int argc, char **argv)
455455
<< " $(error Did not find a Python interpreter)\n"
456456
<< " endif\n"
457457
<< " ifdef VERIFY\n"
458-
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --verify)\n"
458+
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --recursive --verify)\n"
459459
<< " else\n"
460-
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py)\n"
460+
<< " matchcompiler_S := $(shell $(PYTHON_INTERPRETER) tools/matchcompiler.py --recursive)\n"
461+
<< " endif\n"
462+
<< " ifneq ($(.SHELLSTATUS),0)\n"
463+
<< " $(error matchcompiler execution failed)\n"
461464
<< " endif\n"
462465
<< " libcppdir:=build\n"
463466
<< "else\n"

tools/matchcompiler.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,10 @@ def main():
746746
help='directory from which files are read')
747747
parser.add_argument('--write-dir', default="build",
748748
help='directory into which files are written')
749-
parser.add_argument('--prefix', default="",
750-
help='prefix for build files')
751749
parser.add_argument('--line', action='store_true', default=False,
752750
help='add line directive to input files into build files')
751+
parser.add_argument('--recursive', action='store_true', default=False,
752+
help='scan input directory recursively when no files are specified')
753753
parser.add_argument('file', nargs='*',
754754
help='file to compile')
755755
args = parser.parse_args()
@@ -758,38 +758,34 @@ def main():
758758
line_directive = args.line
759759
files = args.file
760760

761+
if len(files) > 0 and args.recursive:
762+
print('--recursive has not effect since files were explicitly specified.')
763+
761764
# Check if we are invoked from the right place
762765
if not os.path.exists(lib_dir):
763766
print('Directory "' + lib_dir + '"not found.')
764767
sys.exit(-1)
765768

766769
# Create build directory if needed
767-
try:
768-
os.makedirs(build_dir)
769-
except OSError as e:
770-
# due to race condition in case of parallel build,
771-
# makedirs may fail. Ignore that; if there's actual
772-
# problem with directory creation, it'll be caught
773-
# by the following isdir check
774-
if e.errno != errno.EEXIST:
775-
raise
770+
os.makedirs(build_dir, exist_ok=True)
776771

777772
if not os.path.isdir(build_dir):
778773
raise Exception(build_dir + ' is not a directory')
779774

780-
mc = MatchCompiler(verify_mode=args.verify,
781-
show_skipped=args.show_skipped)
782-
783775
if not files:
784776
# select all *.cpp files in lib_dir
785-
for f in glob.glob(lib_dir + '/*.cpp'):
777+
for f in glob.glob(lib_dir + '/**/*.cpp', recursive=args.recursive):
786778
files.append(f[len(lib_dir) + 1:])
787779

780+
mc = MatchCompiler(verify_mode=args.verify,
781+
show_skipped=args.show_skipped)
782+
788783
# convert files
789784
for fi in files:
790-
pi = lib_dir + '/' + fi
791-
fo = args.prefix + fi
792-
po = build_dir + '/' + fo
785+
pi = os.path.join(lib_dir, fi)
786+
po = os.path.join(build_dir, fi)
787+
if args.recursive:
788+
os.makedirs(os.path.dirname(po), exist_ok=True)
793789
print(pi + ' => ' + po)
794790
mc.convertFile(pi, po, line_directive)
795791

0 commit comments

Comments
 (0)