CMAKE: converted some update libs targets and added debugger support

master
Martin Gerhardy 2018-06-19 20:40:13 +02:00
parent 1ad61c9b05
commit 3a2049bcab
3 changed files with 91 additions and 21 deletions

View File

@ -4,6 +4,7 @@ set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Root dir")
set(SCRIPTS_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake)
set(GENERATE_DIR ${CMAKE_BINARY_DIR}/generated CACHE STRING "Generated code dir")
add_custom_target(codegen)
add_custom_target(update-libs)
include(${SCRIPTS_CMAKE_DIR}/common.cmake)
include(${SCRIPTS_CMAKE_DIR}/macros.cmake)
@ -20,14 +21,26 @@ option(UNITTESTS_SANITIZER_ADDRESS "Builds tests with address sanitizer" OFF)
option(TOOLS "Builds with tools" ON)
option(RCON "Builds with rcon tool - also needs TOOLS to be active" ON)
option(SERVER "Builds with server" ON)
set(GDB_BINARY "gdb" CACHE STRING "The gnu debugger binary to use for the debug target")
set(LLDB_BINARY "lldb" CACHE STRING "The lldb binary to use for the debug target")
set(GIT_BINARY "git" CACHE STRING "The git binary to use for the update-libs target")
set(HG_BINARY "hg" CACHE STRING "The mercurial binary to use for the update-libs target")
option(USE_CCACHE "Use ccache" ON)
option(USE_GPROF "Use gprof - will become slow" OFF)
option(USE_GCOV "Use gcov - will become slow" OFF)
option(USE_DOXYGEN_CHECK "Use -Wdocumentation if available" OFF)
set(DEBUGGER "gdb" CACHE STRING "Which debugger should be used")
set_property(CACHE DEBUGGER PROPERTY STRINGS gdb lldb)
set(SERVER_HOST "localhost" CACHE STRING "Host where the server is running on")
set(SERVER_PORT "11337" CACHE STRING "Port where the server is listening on")
set(BASE_URL "http://localhost/" CACHE STRING "Base url of the http endpoints")
if (${DEBUGGER} STREQUAL "gdb")
set(DEBUGGER_COMMAND "${GDB_EXECUTABLE} -ex run --args" CACHE STRING "The gdb command line to debug and run an executable")
elseif (${DEBUGGER} STREQUAL "lldb")
set(DEBUGGER_COMMAND "${LLDB_EXECUTABLE} -b -o run" CACHE STRING "The lldb command line to debug and run an executable")
else()
message(WARN "Unknown DEBUGGER value - set to gdb or lldb")
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(WINDOWS 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
@ -103,6 +116,11 @@ else()
message(STATUS "ccache not found")
endif()
find_host_program(GDB_EXECUTABLE NAMES ${GDB_BINARY} gdb)
find_host_program(LLDB_EXECUTABLE NAMES ${LLDB_BINARY} lldb)
find_host_program(GIT_EXECUTABLE NAMES ${GIT_BINARY} git)
find_host_program(HG_EXECUTABLE NAMES ${HG_BINARY} hg)
configure_file(src/engine-config.h.in engine-config.h @ONLY)
message(STATUS "Generate config.h in ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
@ -149,3 +167,54 @@ if (DOXYGEN_FOUND)
DEPENDS codegen
)
endif(DOXYGEN_FOUND)
macro(engine_update_git_lib)
set(_OPTIONS_ARGS)
set(_ONE_VALUE_ARGS LIB URL TARGETDIR)
set(_MULTI_VALUE_ARGS COPY DELETE REVERT)
cmake_parse_arguments(UPDATE "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
if (NOT UPDATE_TARGETDIR)
set(UPDATE_TARGETDIR "contrib/libs/${UPDATE_LIB}")
endif()
if (GIT_EXECUTABLE)
set(CLONE_DIR ${CMAKE_BINARY_DIR}/${UPDATE_LIB}.sync)
set(CLONE_CMAKE ${CMAKE_BINARY_DIR}/UpdateGit${UPDATE_LIB}.cmake)
file(WRITE ${CLONE_CMAKE} "if (NOT EXISTS ${CLONE_DIR})\n\tmessage(STATUS \"Clone repository for ${UPDATE_LIB}\")\n")
file(APPEND ${CLONE_CMAKE} "\texecute_process(COMMAND ${GIT_EXECUTABLE} clone --depth=1 ${UPDATE_URL} ${CLONE_DIR})\n")
file(APPEND ${CLONE_CMAKE} "else()\n\tmessage(STATUS \"Update repository for ${UPDATE_LIB}\")\n")
file(APPEND ${CLONE_CMAKE} "\texecute_process(COMMAND ${GIT_EXECUTABLE} -C ${CLONE_DIR} pull --depth=1 --rebase)\n")
file(APPEND ${CLONE_CMAKE} "endif()\n")
if (UPDATE_DELETE)
file(APPEND ${CLONE_CMAKE} "foreach(file ${UPDATE_COPY})\n")
file(APPEND ${CLONE_CMAKE} "\tmessage(STATUS \"delete \${file}\")\n")
file(APPEND ${CLONE_CMAKE} "\t# TODO: delete file\n")
file(APPEND ${CLONE_CMAKE} "endforeach()\n")
endif()
if (UPDATE_COPY)
file(APPEND ${CLONE_CMAKE} "foreach(file ${UPDATE_COPY})\n")
file(APPEND ${CLONE_CMAKE} "\tmessage(STATUS \"check \${file}\")\n")
file(APPEND ${CLONE_CMAKE} "\tconfigure_file(${CLONE_DIR}/\${file} ${UPDATE_TARGETDIR}/\${file} COPYONLY)\n")
file(APPEND ${CLONE_CMAKE} "endforeach()\n")
endif()
if (UPDATE_REVERT)
file(APPEND ${CLONE_CMAKE} "foreach(file ${UPDATE_COPY})\n")
file(APPEND ${CLONE_CMAKE} "\tmessage(STATUS \"revert \${file}\")\n")
file(APPEND ${CLONE_CMAKE} "\texecute_process(COMMAND ${GIT_EXECUTABLE} checkout -f ${UPDATE_TARGETDIR}/\${file})\n")
file(APPEND ${CLONE_CMAKE} "endforeach()\n")
endif()
add_custom_target(update-libs-${UPDATE_LIB} ${CMAKE_COMMAND} -P ${CLONE_CMAKE})
add_dependencies(update-libs update-libs-${UPDATE_LIB})
else()
message(STATUS "Could not add update-libs-${UPDATE_LIB} target - no git installed or found")
endif()
endmacro()
engine_update_git_lib(LIB simplecpp URL "https://github.com/danmar/simplecpp.git" COPY simplecpp.cpp simplecpp.h)
engine_update_git_lib(LIB nuklear URL "https://github.com/danmar/simplecpp.git" COPY simplecpp.cpp simplecpp.h TARGETDIR src/modules/ui/nuklear/private)
# TODO cp $(UPDATEDIR)/nuklear.sync/demo/overview.c src/tests/testnuklear
engine_update_git_lib(LIB json URL "https://github.com/nlohmann/json.git" COPY src/json.hpp TARGETDIR src/modules/core)
engine_update_git_lib(LIB stringview URL "https://github.com/satoren/string_view.git" COPY string_view.hpp TARGETDIR contrib/libs/string_view)
engine_update_git_lib(LIB voxelizer URL "https://github.com/karimnaaji/voxelizer.git" COPY voxelizer.h TARGETDIR src/tools/voxedit/ui/editorscene/)

View File

@ -155,11 +155,6 @@ update-stb:
cp $(UPDATEDIR)/stb.sync/stb_truetype.h src/modules/voxelfont/stb_truetype.h
cp $(UPDATEDIR)/stb.sync/stb_image.h contrib/libs/libturbobadger/tb/thirdparty
cp $(UPDATEDIR)/stb.sync/stb_truetype.h contrib/libs/libturbobadger/tb/thirdparty
# TODO: dearimgui
update-simplecpp:
$(call UPDATE_GIT,simplecpp,https://github.com/danmar/simplecpp.git)
cp $(UPDATEDIR)/simplecpp.sync/simplecpp.* contrib/libs/simplecpp
update-googletest:
$(call UPDATE_GIT,googletest,https://github.com/google/googletest.git)
@ -252,23 +247,11 @@ update-nuklear:
cp $(UPDATEDIR)/nuklear.sync/nuklear.h src/modules/ui/nuklear/private
cp $(UPDATEDIR)/nuklear.sync/demo/overview.c src/tests/testnuklear
update-json:
$(call UPDATE_GIT,json,https://github.com/nlohmann/json)
cp $(UPDATEDIR)/json.sync/src/json.hpp src/modules/core
# currently not part of updatelibs - intentional - we adopted the original code.
update-simplexnoise:
$(call UPDATE_GIT,simplexnoise,https://github.com/simongeilfus/SimplexNoise.git)
cp $(UPDATEDIR)/simplexnoise.sync/include/Simplex.h src/modules/noise
update-stringview:
$(call UPDATE_GIT,string_view,https://github.com/satoren/string_view.git)
cp $(UPDATEDIR)/string_view.sync/string_view.hpp contrib/libs/string_view
update-voxelizer:
$(call UPDATE_GIT,voxelizer,https://github.com/karimnaaji/voxelizer)
cp $(UPDATEDIR)/voxelizer.sync/voxelizer.h src/tools/voxedit/ui/editorscene/
update-curl:
$(call UPDATE_GIT,curl,https://github.com/curl/curl.git)
cp $(UPDATEDIR)/curl.sync/lib/*.[ch]* contrib/libs/libcurl/lib
@ -279,4 +262,5 @@ update-curl:
# TODO native file dialog support
# TODO simpleai support
updatelibs: update-voxelizer update-nuklear update-stringview update-restclient-cpp update-libuv update-stb update-googletest update-benchmark update-backward update-dearimgui update-flatbuffers update-assimp update-enet update-glm update-sdl2 update-turbobadger update-curl update-glslang
updatelibs: update-nuklear update-restclient-cpp update-libuv update-stb update-googletest update-benchmark update-backward update-dearimgui update-flatbuffers update-assimp update-enet update-glm update-sdl2 update-turbobadger update-curl update-glslang
$(MAKE) -C $(BUILDDIR) update-libs

View File

@ -420,6 +420,7 @@ macro(engine_add_valgrind TARGET)
--trace-children=no --log-file=$<TARGET_FILE:${TARGET}>.memcheck.log
$<TARGET_FILE:${TARGET}>
COMMENT "memcheck log for ${TARGET}: $<TARGET_FILE:${TARGET}>.memcheck.log"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET}
DEPENDS ${TARGET}
)
add_custom_target(${TARGET}-helgrind)
@ -429,6 +430,7 @@ macro(engine_add_valgrind TARGET)
--trace-children=no --log-file=$<TARGET_FILE:${TARGET}>.helgrind.log
$<TARGET_FILE:${TARGET}>
COMMENT "helgrind log for ${TARGET}: $<TARGET_FILE:${TARGET}>.helgrind.log"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET}
DEPENDS ${TARGET}
)
endif()
@ -442,6 +444,7 @@ macro(engine_add_perf TARGET)
COMMAND
${PERF_EXECUTABLE} record --call-graph dwarf
$<TARGET_FILE:${TARGET}>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET}
DEPENDS ${TARGET}
)
endif()
@ -458,11 +461,22 @@ macro(engina_add_vogl TARGET)
--vogl_force_debug_context
$<TARGET_FILE:${TARGET}>
COMMENT "vogl trace file for ${TARGET}: ${CMAKE_BINARY_DIR}/${TARGET}.trace.bin"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET}
DEPENDS ${TARGET}
)
endif()
endmacro()
macro(engine_add_debuggger TARGET)
add_custom_target(${TARGET}-debug)
add_custom_command(TARGET ${TARGET}-debug
COMMAND ${DEBUGGER_COMMAND} $<TARGET_FILE:${TARGET}>
COMMENT "Starting debugger session for ${TARGET}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET}
DEPENDS ${TARGET}
)
endmacro()
#-------------------------------------------------------------------------------
# Macros for generating google unit tests.
#-------------------------------------------------------------------------------
@ -742,7 +756,9 @@ macro(engine_add_executable)
if (INSTALL_DATA)
install(FILES lua/${luasrc} DESTINATION ${INSTALL_DATA_DIR}/${luasrcdir} COMPONENT ${_EXE_TARGET})
endif()
configure_file(lua/${luasrc} ${INSTALL_DATA_DIR}/${luasrcdir}/${luasrc})
get_filename_component(filename ${luasrc} NAME)
get_filename_component(datafiledir ${luasrc} DIRECTORY)
configure_file(lua/${luasrc} ${CMAKE_BINARY_DIR}/${_EXE_TARGET}/${datafiledir}/${filename} COPYONLY)
endforeach()
set(ICON "${_EXE_TARGET}-icon.png")
if (EXISTS ${ROOT_DIR}/contrib/${ICON})
@ -755,12 +771,13 @@ macro(engine_add_executable)
if (INSTALL_DATA)
install(FILES ${DATA_DIR}/${KEYBINDINGS} DESTINATION ${INSTALL_DATA_DIR}/ COMPONENT ${_EXE_TARGET})
endif()
configure_file(${DATA_DIR}/${KEYBINDINGS} ${INSTALL_DATA_DIR}/${KEYBINDINGS})
configure_file(${DATA_DIR}/${KEYBINDINGS} ${CMAKE_BINARY_DIR}/${_EXE_TARGET}/${KEYBINDINGS} COPYONLY)
endif()
if (INSTALL_DATA)
install(TARGETS ${_EXE_TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_EXE_TARGET})
endif()
add_custom_target(${_EXE_TARGET}-run COMMAND $<TARGET_FILE:${_EXE_TARGET}> DEPENDS ${_EXE_TARGET} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${_EXE_TARGET}")
engine_add_debuggger(${_EXE_TARGET})
engine_add_valgrind(${_EXE_TARGET})
engine_add_perf(${_EXE_TARGET})
if (_EXE_WINDOWED)