From 8f64860b5dc97843fe79aadb044f0b39d6f4058f Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Wed, 12 Oct 2016 17:03:46 +0200 Subject: [PATCH] Preparing changes to use automatic CMakeFiles also in the ROS projects. (#48) --- cmake/functions.cmake | 27 +++++++---------- scripts/update_cmakelists.py | 57 +++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index d2e196f..960b87a 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -16,22 +16,23 @@ include(CMakeParseArguments) macro(_parse_arguments ARGS) set(OPTIONS + USES_BOOST USES_CERES USES_EIGEN + USES_GFLAGS + USES_GLOG USES_GLOG USES_LUA - USES_BOOST USES_WEBP - USES_GLOG - USES_GFLAGS ) # Options only used by projects using Cartographers cmake files. list(APPEND OPTIONS USES_CARTOGRAPHER - USES_ROS - USES_ZLIB USES_PCL + USES_ROS + USES_YAMLCPP + USES_ZLIB ) set(ONE_VALUE_ARG ) set(MULTI_VALUE_ARGS SRCS HDRS DEPENDS) @@ -108,6 +109,10 @@ macro(_common_compile_stuff VISIBILITY) endforeach() endif() + if(ARG_USES_YAMLCPP) + target_link_libraries("${NAME}" yaml-cpp) + endif() + set_target_properties(${NAME} PROPERTIES COMPILE_FLAGS ${TARGET_COMPILE_FLAGS}) @@ -165,17 +170,6 @@ function(google_combined_library NAME) DEPENDS ${ARG_SRCS} ) - add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" - "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --cpp_out ${CMAKE_BINARY_DIR} -I - ${CMAKE_BINARY_DIR} ${REWRITTEN_PROTO} - DEPENDS ${REWRITTEN_PROTO} - COMMENT "Running C++ protocol buffer compiler on ${FIL}" - VERBATIM - ) - # Just a dummy library, we will overwrite its output directly after again # with its POST_BUILD step. google_library(${NAME} @@ -273,6 +267,7 @@ function(google_library NAME) STATIC ${ARG_SRCS} ${ARG_HDRS} ) + set_property(TARGET "${NAME}" PROPERTY POSITION_INDEPENDENT_CODE ON) # Update the global variable that contains all static libraries. SET(ALL_LIBRARIES "${ALL_LIBRARIES};${NAME}" CACHE INTERNAL "ALL_LIBRARIES") diff --git a/scripts/update_cmakelists.py b/scripts/update_cmakelists.py index 9313aa0..dcd63fa 100755 --- a/scripts/update_cmakelists.py +++ b/scripts/update_cmakelists.py @@ -19,6 +19,7 @@ import os from os import path import re +import argparse def MakeRelative(filename, directory): @@ -72,20 +73,20 @@ class Target(object): return "\n".join(lines) -def ExtractCartographerIncludes(source): +def ExtractProjectIncludes(project_name, source): """Returns all locally included files.""" includes = set() for line in open(MaybeUseCmakeFile(source)): if source.endswith(".proto"): - match = re.match(r'^import "(cartographer/[^"]+)', line) + match = re.match(r'^import "(' + project_name + r'/[^"]+)', line) else: - match = re.match(r'^#include "(cartographer/[^"]+)"', line) + match = re.match(r'^#include "(' + project_name + r'/[^"]+)"', line) if match: includes.add(match.group(1)) return includes -def ExtractUses(source): +def ExtractUses(project_name, source): """Finds the options for the third_party libraries used.""" uses = set() for line in open(MaybeUseCmakeFile(source)): @@ -99,10 +100,21 @@ def ExtractUses(source): uses.add("USES_GLOG") if re.match(r'^#include "gflags/', line): uses.add("USES_GFLAGS") - if re.match(r"^#include