Files
allwpilib/simulation/gz_msgs/CMakeLists.txt
Peter_Mitrano acc7fbbf01 finishing up FRCSim installer
adds build of gz_msgs on end-user computer
This means we don't need to provide different zips for different
versions of ubuntu.
The problem was that gazebo on 14.04 comes with protobuf 2.5 but gazebo on 15.10 comes with 2.6
added a few other fixes to the install script as well

also fix dependency between simluation publishing and libwpilibcsim
building

Change-Id: I57d5a26ed7795bc61a25402e2986c6023d1d78ac
2015-12-29 13:48:59 -05:00

90 lines
2.9 KiB
CMake

Cmake_minimum_required(VERSION 2.8)
project(gz_msgs)
#copied from GazeboUtils.cmake
macro (APPEND_TO_CACHED_STRING _string _cacheDesc)
FOREACH (newItem ${ARGN})
SET (${_string} "${${_string}} ${newItem}" CACHE INTERNAL ${_cacheDesc} FORCE)
ENDFOREACH (newItem ${ARGN})
endmacro (APPEND_TO_CACHED_STRING)
find_package(Protobuf REQUIRED)
if (NOT PROTOBUF_FOUND)
MESSAGE ("Missing: Google Protobuf (libprotobuf-dev)")
endif()
if (NOT PROTOBUF_PROTOC_EXECUTABLE)
MESSAGE ( "Missing: Google Protobuf Compiler (protobuf-compiler)")
endif()
if (NOT PROTOBUF_PROTOC_LIBRARY)
MESSAGE ("Missing: Google Protobuf Compiler Library (libprotoc-dev)")
endif()
#list all proto files used
get_filename_component(PROTO_DIR src/main/proto ABSOLUTE)
set(msgs
"${PROTO_DIR}/bool.proto"
"${PROTO_DIR}/driver-station.proto"
"${PROTO_DIR}/float64.proto"
"${PROTO_DIR}/frc_joystick.proto"
)
set (GZ_MSGS_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE FILEPATH "gz_msgs include directory")
set (GZ_MSGS_INCLUDE_SUBDIR "${GZ_MSGS_INCLUDE_DIR}/simulation/gz_msgs")
file(MAKE_DIRECTORY ${GZ_MSGS_INCLUDE_SUBDIR})
set(PROTO_SRCS)
set(PROTO_HDRS)
set(MSGS_HEADER "${GZ_MSGS_INCLUDE_SUBDIR}/msgs.h")
foreach(FIL ${msgs})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
list(APPEND PROTO_SRCS "${GZ_MSGS_INCLUDE_SUBDIR}/${FIL_WE}.pb.cc")
list(APPEND PROTO_HDRS "${GZ_MSGS_INCLUDE_SUBDIR}/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT
"${GZ_MSGS_INCLUDE_SUBDIR}/${FIL_WE}.pb.cc"
"${GZ_MSGS_INCLUDE_SUBDIR}/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out=${GZ_MSGS_INCLUDE_SUBDIR} --proto_path=${PROTO_DIR} ${ABS_FIL}
COMMENT "compiling ${ABS_FIL}"
VERBATIM)
endforeach()
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
###############################################
#Generating msgs.h
#create the message_headers and keep it in cache
set (message_headers "" CACHE INTERNAL "Include dirs description")
#add includes to the msgs.h file
foreach (hdr ${PROTO_HDRS})
string (REPLACE "${CMAKE_CURRENT_BINARY_DIR}/generated/" "" hdr ${hdr})
APPEND_TO_CACHED_STRING(message_headers
"Message Types" "#include \"${hdr}\"\n")
endforeach()
configure_file(msgs.h.in ${MSGS_HEADER})
file(GLOB_RECURSE COM_SRC_FILES msgs/*.cc)
include_directories(msgs ${PROTOBUF_INCLUDE_DIR})
if (WIN32)
add_library(${PROJECT_NAME} ${PROTO_SRCS} ${SRC_FILES})
else()
add_library(${PROJECT_NAME} SHARED ${PROTO_SRCS} ${SRC_FILES})
endif()
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES})
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "$ENV{HOME}/wpilib/simulation/lib")
install(TARGETS ${PROJECT_NAME}
DESTINATION "$ENV{HOME}/wpilib/simulation/lib")
install(DIRECTORY "${GZ_MSGS_INCLUDE_DIR}/simulation"
DESTINATION "$ENV{HOME}/wpilib/simulation/include")