Skip to content

Commit e15b72f

Browse files
committed
allow compile_commands to be customisable
1 parent 51d9cbd commit e15b72f

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

cmake/compile_commands.cmake

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
function (link_compile_commands)
1+
function (link_compile_commands name)
22
if (MSVC OR NOT CMAKE_EXPORT_COMPILE_COMMANDS)
33
return()
44
endif ()
5-
set(_current_list_path ${CMAKE_CURRENT_LIST_DIR})
65

7-
string(
8-
REGEX
9-
REPLACE "\/|\\|\ "
10-
"_"
11-
_dir
12-
${_current_list_path}
13-
)
6+
string(REGEX REPLACE "\/|\\|\ |\." "_" _dir ${CMAKE_CURRENT_LIST_DIR})
7+
string(REGEX REPLACE "\/|\\|\ |\." "_" _name ${name})
148

15-
add_custom_target(
16-
${_dir}_compile_commands ALL
17-
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json
18-
${_current_list_path}/compile_commands.json
9+
set(cmd_target "${CMAKE_CURRENT_LIST_DIR}/${name}")
10+
add_custom_command(
11+
OUTPUT ${cmd_target}
12+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_BINARY_DIR}/${name}"
13+
"${CMAKE_CURRENT_LIST_DIR}/${name}"
1914
)
2015

16+
add_custom_target(${_dir}_${name} ALL DEPENDS ${cmd_target})
2117
endfunction ()

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
link_compile_commands()
1+
link_compile_commands(compile_commands.json)
22

33
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_SOURCE_DIR}/src/*.cpp")
44
list(REMOVE_ITEM SOURCE_FILES ${MAIN})

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
link_compile_commands()
1+
link_compile_commands(compile_commands.json)
22

33
file(GLOB_RECURSE TEST_FILES "${CMAKE_SOURCE_DIR}/tests/*.cpp")
44
add_executable(${TEST_NAME} ${TEST_FILES})

0 commit comments

Comments
 (0)