Skip to content

Commit

Permalink
Revert "Improvements to SITL to make paths more flexible. (#5181)"
Browse files Browse the repository at this point in the history
This reverts commit 699b6a2.
  • Loading branch information
LorenzMeier committed Aug 5, 2016
1 parent bbe3525 commit 102f5b5
Show file tree
Hide file tree
Showing 72 changed files with 671 additions and 642 deletions.
65 changes: 22 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@
# and leads to wrong toolchain detection
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PX4_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")

execute_process(
COMMAND Tools/check_submodules.sh
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)

# Use clang
#SET (CMAKE_C_COMPILER /usr/bin/clang-3.6)
#SET (CMAKE_CXX_COMPILER /usr/bin/clang++-3.6)
Expand Down Expand Up @@ -163,9 +155,6 @@ message(STATUS "${target_name}")
# Define GNU standard installation directories
include(GNUInstallDirs)

# Add support for external project building
include(ExternalProject)

# Setup install paths
if(NOT CMAKE_INSTALL_PREFIX)
if (${OS} STREQUAL "posix")
Expand All @@ -174,8 +163,12 @@ if(NOT CMAKE_INSTALL_PREFIX)
endif()
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")

list(APPEND CMAKE_MODULE_PATH "${PX4_SOURCE_DIR}/cmake")
message(STATUS "cmake module path: ${CMAKE_MODULE_PATH}")
# switch to ros CMake file if building ros
if (${OS} STREQUAL "ros")
include("cmake/ros-CMakeLists.txt")
else() # otherwise use the rest of this file

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(config_module "configs/${CONFIG}")
include(${config_module})

Expand Down Expand Up @@ -206,9 +199,6 @@ if(DEFINED config_df_driver_list)
message("DF Drivers: ${config_df_driver_list}")
endif()

# force static lib build
set(BUILD_SHARED_LIBS OFF)

#=============================================================================
# project definition
#
Expand All @@ -229,22 +219,8 @@ set(version "${version_major}.${version_minor}.${version_patch}")
set(package-contact "[email protected]")

#=============================================================================
# find programs and packages
# programs
#

# see if catkin was invoked to build this
if (CATKIN_DEVEL_PREFIX)
message(STATUS "catkin ENABLED")
find_package(catkin REQUIRED)
if (catkin_FOUND)
catkin_package()
else()
message(FATAL_ERROR "catkin not found")
endif()
else()
message(STATUS "catkin DISABLED")
endif()

find_package(PythonInterp REQUIRED)

#=============================================================================
Expand Down Expand Up @@ -281,7 +257,7 @@ px4_add_git_submodule(TARGET git_matrix PATH "src/lib/matrix")
px4_add_git_submodule(TARGET git_cmake_hexagon PATH "cmake/cmake_hexagon")

add_custom_target(submodule_clean
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND git submodule deinit -f .
COMMAND rm -rf .git/modules/*
)
Expand All @@ -291,12 +267,12 @@ add_custom_target(submodule_clean
#
add_custom_target(check_format
COMMAND Tools/check_code_style.sh
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

add_custom_target(config
COMMAND cmake-gui .
WORKING_DIRECTORY ${PX4_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

#=============================================================================
Expand Down Expand Up @@ -345,7 +321,7 @@ add_custom_target(xml_gen
# external projects
#

set(ep_base ${PX4_BINARY_DIR}/external)
set(ep_base ${CMAKE_BINARY_DIR}/external)
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})

# add external project install folders to build
Expand Down Expand Up @@ -374,7 +350,7 @@ foreach(module ${config_module_list})
if(external_module)
STRING(REGEX REPLACE "//" "/" EXT_MODULE ${module})
STRING(REGEX REPLACE "/" "__" EXT_MODULE_PREFIX ${EXT_MODULE})
add_subdirectory(${module} ${PX4_BINARY_DIR}/${EXT_MODULE_PREFIX})
add_subdirectory(${module} ${CMAKE_BINARY_DIR}/${EXT_MODULE_PREFIX})
else()
add_subdirectory(src/${module})
endif()
Expand All @@ -399,7 +375,7 @@ endif()
#=============================================================================
# generate git version
#
px4_create_git_hash_header(HEADER ${PX4_BINARY_DIR}/build_git_version.h)
px4_create_git_hash_header(HEADER ${CMAKE_BINARY_DIR}/build_git_version.h)

#=============================================================================
# packaging
Expand All @@ -418,14 +394,17 @@ set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CONFIG}-${version}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${version}")
set(CPACK_SOURCE_GENERATOR "ZIP;TBZ2")
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
set(CPACK_SET_DESTDIR "OFF")
if ("${CMAKE_SYSTEM}" MATCHES "Linux")
find_program(DPKG_PROGRAM dpkg)
if (EXISTS ${DPKG_PROGRAM})
list (APPEND CPACK_GENERATOR "DEB")
endif()
find_program(DPKG_PROGRAM dpkg)
if (EXISTS ${DPKG_PROGRAM})
list (APPEND CPACK_GENERATOR "DEB")
endif()
endif()
if (${OS} STREQUAL "posix")
set(CPACK_SET_DESTDIR "ON")
endif()
include(CPack)

endif() # ros alternative endif

# vim: set noet fenc=utf-8 ff=unix ft=cmake :
33 changes: 20 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,20 @@ else
BUILD_DIR_SUFFIX :=
endif

SRC_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Functions
# --------------------------------------------------------------------
# describe how to build a cmake config
define cmake-build
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi
+@(echo "PX4 CONFIG: $(BUILD_DIR)" && cd $(BUILD_DIR) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e ./build_$@$(BUILD_DIR_SUFFIX)/Makefile ]; then rm -rf ./build_$@$(BUILD_DIR_SUFFIX); fi
+@if [ ! -e ./build_$@$(BUILD_DIR_SUFFIX)/CMakeCache.txt ]; then Tools/check_submodules.sh && mkdir -p ./build_$@$(BUILD_DIR_SUFFIX) && cd ./build_$@$(BUILD_DIR_SUFFIX) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf ./build_$@$(BUILD_DIR_SUFFIX)); fi
+@Tools/check_submodules.sh
+@(echo "PX4 CONFIG: $@$(BUILD_DIR_SUFFIX)" && cd ./build_$@$(BUILD_DIR_SUFFIX) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS))
endef

define cmake-build-other
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(2) -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi
+@(cd $(BUILD_DIR) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e ./build_$@/Makefile ]; then rm -rf ./build_$@; fi
+@if [ ! -e ./build_$@/CMakeCache.txt ]; then Tools/check_submodules.sh && mkdir -p ./build_$@ && cd ./build_$@ && cmake $(2) -G$(PX4_CMAKE_GENERATOR) || (cd .. && rm -rf ./build_$@); fi
+@(cd ./build_$@ && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS))
endef

# create empty targets to avoid msgs for targets passed to cmake
Expand Down Expand Up @@ -236,8 +233,14 @@ run_sitl_ros: sitl_deprecation
# Other targets
# --------------------------------------------------------------------

.PHONY: uavcan_firmware check check_format unittest tests qgc_firmware package_firmware clean submodulesclean distclean
.NOTPARALLEL: uavcan_firmware check check_format unittest tests qgc_firmware package_firmware clean submodulesclean distclean
.PHONY: gazebo_build uavcan_firmware check check_format unittest tests qgc_firmware package_firmware clean submodulesclean distclean
.NOTPARALLEL: gazebo_build uavcan_firmware check check_format unittest tests qgc_firmware package_firmware clean submodulesclean distclean

gazebo_build:
@mkdir -p build_gazebo
@if [ ! -e ./build_gazebo/CMakeCache.txt ];then cd build_gazebo && cmake -Wno-dev -G$(PX4_CMAKE_GENERATOR) ../Tools/sitl_gazebo; fi
@cd build_gazebo && $(PX4_MAKE) $(PX4_MAKE_ARGS)
@cd build_gazebo && $(PX4_MAKE) $(PX4_MAKE_ARGS) sdf

uavcan_firmware:
ifeq ($(VECTORCONTROL),1)
Expand Down Expand Up @@ -299,7 +302,11 @@ unittest: posix_sitl_default
@(cd build_unittest && ctest -j2 --output-on-failure)

run_tests_posix: posix_sitl_default
@(cd build_posix_sitl_default/ && ctest -V)
@mkdir -p build_posix_sitl_default/src/firmware/posix/rootfs/fs/microsd
@mkdir -p build_posix_sitl_default/src/firmware/posix/rootfs/eeprom
@touch build_posix_sitl_default/src/firmware/posix/rootfs/eeprom/parameters
@(cd build_posix_sitl_default/src/firmware/posix && ./px4 -d ../../../../posix-configs/SITL/init/rcS_tests | tee test_output)
@(cd build_posix_sitl_default/src/firmware/posix && grep --color=always "All tests passed" test_output)

tests: check_unittest run_tests_posix

Expand Down
2 changes: 1 addition & 1 deletion Tools/sitl_gazebo
83 changes: 39 additions & 44 deletions Tools/sitl_run.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
#!/bin/bash

set -e

echo args: $@

sitl_bin=$1
rc_script=$2
debugger=$3
program=$4
model=$5
src_path=$6
build_path=$7
rc_script=$1
debugger=$2
program=$3
model=$4
build_path=$5
curr_dir=`pwd`

echo SITL ARGS

echo sitl_bin: $sitl_bin
echo rc_script: $rc_script
echo debugger: $debugger
echo program: $program
echo model: $model
echo src_path: $src_path
echo build_path: $build_path

working_dir=`pwd`
sitl_bin=$build_path/src/firmware/posix/px4
mkdir -p $build_path/src/firmware/posix/rootfs/fs/microsd
mkdir -p $build_path/src/firmware/posix/rootfs/eeprom
touch $build_path/src/firmware/posix/rootfs/eeprom/parameters

if [ "$chroot" == "1" ]
then
Expand All @@ -42,36 +35,32 @@ fi

if [ "$#" -lt 5 ]
then
echo usage: sitl_run.sh rc_script debugger program model devel_path
echo usage: sitl_run.sh rc_script debugger program model build_path
echo ""
exit 1
fi

command_exists () {
type "$1" &> /dev/null ;
}

# kill process names that might stil
# be running from last time
pgrep gazebo && pkill gazebo
pgrep px4 && pkill px4
if command_exists jps
pkill gazebo
pkill px4
jmavsim_pid=`jps | grep Simulator | cut -d" " -f1`
if [ -n "$jmavsim_pid" ]
then
jmavsim_pid=`jps | grep Simulator | cut -d" " -f1`
if [ -n "$jmavsim_pid" ]
then
kill $jmavsim_pid
fi
kill $jmavsim_pid
fi

cp $src_path/Tools/posix_lldbinit $working_dir/.lldbinit
cp $src_path/Tools/posix.gdbinit $working_dir/.gdbinit
set -e

cd $build_path/..
cp Tools/posix_lldbinit $build_path/src/firmware/posix/.lldbinit
cp Tools/posix.gdbinit $build_path/src/firmware/posix/.gdbinit

SIM_PID=0

if [ "$program" == "jmavsim" ] && [ ! -n "$no_sim" ]
then
cd $src_path/Tools/jMAVSim
cd Tools/jMAVSim
ant create_run_jar copy_res
cd out/production
java -Djava.ext.dirs= -jar jmavsim_run.jar -udp 127.0.0.1:14560 &
Expand All @@ -82,9 +71,15 @@ then
if [ -x "$(command -v gazebo)" ]
then
# Set the plugin path so Gazebo finds our model and sim
source /usr/share/gazebo/setup.sh
source $src_path/integrationtests/setup_gazebo_ros.bash ${src_path} ${build_path}
gzserver --verbose worlds/${model}.world &
export GAZEBO_PLUGIN_PATH=$curr_dir/build_gazebo:${GAZEBO_PLUGIN_PATH}
# Set the model path so Gazebo finds the airframes
export GAZEBO_MODEL_PATH=${GAZEBO_MODEL_PATH}:$curr_dir/Tools/sitl_gazebo/models
# The next line would disable online model lookup, can be commented in, in case of unstable behaviour.
# export GAZEBO_MODEL_DATABASE_URI=""
export SITL_GAZEBO_PATH=$curr_dir/Tools/sitl_gazebo
make --no-print-directory gazebo_build

gzserver --verbose $curr_dir/Tools/sitl_gazebo/worlds/${model}.world &
SIM_PID=`echo $!`

if [[ -n "$HEADLESS" ]]; then
Expand All @@ -103,17 +98,17 @@ then
# This is not a simulator, but a log file to replay

# Check if we need to creat a param file to allow user to change parameters
if ! [ -f "$rootfs/replay_params.txt" ]
if ! [ -f "${build_path}/src/firmware/posix/rootfs/replay_params.txt" ]
then
touch $rootfs/replay_params.txt
touch ${build_path}/src/firmware/posix/rootfs/replay_params.txt
fi
fi

cd $working_dir
cd $build_path/src/firmware/posix

if [ "$logfile" != "" ]
then
cp $logfile $rootfs/replay.px4log
cp $logfile rootfs/replay.px4log
fi

# Do not exit on failure now from here on because we want the complete cleanup
Expand All @@ -122,18 +117,18 @@ set +e
# Start Java simulator
if [ "$debugger" == "lldb" ]
then
lldb -- $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
lldb -- px4 ../../../../${rc_script}_${program}_${model}
elif [ "$debugger" == "gdb" ]
then
gdb --args $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
gdb --args px4 ../../../../${rc_script}_${program}_${model}
elif [ "$debugger" == "ddd" ]
then
ddd --debugger gdb --args px4 $src_path $src_path/${rc_script}_${program}_${model}
ddd --debugger gdb --args px4 ../../../../${rc_script}_${program}_${model}
elif [ "$debugger" == "valgrind" ]
then
valgrind $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
valgrind ./px4 ../../../../${rc_script}_${program}_${model}
else
$sudo_enabled $sitl_bin $chroot_enabled $src_path $src_path/${rc_script}_${program}_${model}
$sudo_enabled ./px4 $chroot_enabled ../../../../${rc_script}_${program}_${model}
fi

if [ "$program" == "jmavsim" ]
Expand Down
Loading

0 comments on commit 102f5b5

Please sign in to comment.