diff --git a/CMakeLists.txt b/CMakeLists.txt index 2100c53ad2..70d663a89c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,34 @@ if(DEFINED ENV{DEPS_BUILD_DIR}) set(DEPS_PREFIX "$ENV{DEPS_BUILD_DIR}/usr" CACHE PATH "Path prefix for finding dependencies") else() set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" CACHE PATH "Path prefix for finding dependencies") + # When running from within CLion or Visual Studio, + # build bundled dependencies automatically. + if(NOT EXISTS ${DEPS_PREFIX} + AND (DEFINED ENV{CLION_IDE} + OR DEFINED ENV{VisualStudioEdition})) + message(STATUS "Building dependencies...") + set(DEPS_BUILD_DIR ${PROJECT_BINARY_DIR}/.deps) + file(MAKE_DIRECTORY ${DEPS_BUILD_DIR}) + execute_process( + COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} + -DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL} + -DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO} + -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE} + -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + ${PROJECT_SOURCE_DIR}/third-party + WORKING_DIRECTORY ${DEPS_BUILD_DIR}) + execute_process( + COMMAND ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR} + --config ${CMAKE_BUILD_TYPE}) + set(DEPS_PREFIX ${DEPS_BUILD_DIR}/usr) + endif() endif() + if(CMAKE_CROSSCOMPILING AND NOT UNIX) list(INSERT CMAKE_FIND_ROOT_PATH 0 ${DEPS_PREFIX}) list(INSERT CMAKE_PREFIX_PATH 0 ${DEPS_PREFIX}/../host/bin)