Skip to content

Commit

Permalink
Fix CMake
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed May 17, 2023
1 parent f593edc commit 91ddb20
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 74 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ gz_find_package(GzProtobuf
gz_find_package(gz-utils2 REQUIRED)
set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR})


#--------------------------------------
# Find gz-math
gz_find_package(gz-math7 REQUIRED)
set(GZ_MATH_VER ${gz-math7_VERSION_MAJOR})
Expand All @@ -98,7 +98,7 @@ gz_find_package(TINYXML2 REQUIRED PRIVATE PRETTY tinyxml2)
#============================================================================
# Configure the build
#============================================================================
gz_configure_build(QUIT_IF_BUILD_ERRORS)
gz_configure_build(QUIT_IF_BUILD_ERRORS COMPONENTS compiled)

#============================================================================
# gz command line support
Expand All @@ -119,8 +119,6 @@ add_subdirectory(tools)
# projects.
add_subdirectory(proto)

add_subdirectory(compiled)

#============================================================================
# Create package information
#============================================================================
Expand Down
8 changes: 6 additions & 2 deletions cmake/gz_msgs_generate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
function(gz_msgs_generate_messages_impl)
set(options "")
set(oneValueArgs MSGS_PATH TARGET PROTO_PACKAGE MSGS_GEN_SCRIPT GZ_PROTOC_PLUGIN FACTORY_GEN_SCRIPT MSGS_LIB PROTO_PATH)
set(multiValueArgs INPUT_PROTOS)
set(multiValueArgs INPUT_PROTOS DEPENDENCIES)

cmake_parse_arguments(generate_messages "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
string(REPLACE "." "_" gen_dir ${generate_messages_PROTO_PACKAGE})

# Extract dependency information from targets
set(depends_proto_paths)
set(depends_includes)

foreach(dep ${generate_messages_DEPENDENCIES})
get_target_property(dep_proto_path ${dep} PROTO_DIR)
get_target_property(dep_proto_include_path ${dep} PROTO_INCLUDE_DIR)

list(APPEND depends_proto_paths ${dep_proto_path})
list(APPEND depends_includes ${dep_proto_include_path})
endforeach()

message(STATUS "Dependencies: ${generate_messages_DEPENDENCIES} (${depends_proto_paths}) (${depends_includes})")

foreach(proto_file ${generate_messages_INPUT_PROTOS})
gz_msgs_protoc(
MSGS_GEN_SCRIPT
Expand Down Expand Up @@ -100,7 +104,7 @@ function(gz_msgs_generate_messages_impl)

# Export the messages path and dependency messages paths for potential dependent message libs
set(PROTO_DIR)
list(APPEND PROTO_DIR ${generate_messages_MSGS_PATH})
list(APPEND PROTO_DIR ${generate_messages_PROTO_PATH})
list(APPEND PROTO_DIR ${depends_proto_paths})

set(PROTO_INCLUDE_DIR)
Expand Down
2 changes: 1 addition & 1 deletion compiled/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gz_msgs_generate_messages_impl(
FACTORY_GEN_SCRIPT
${PROJECT_SOURCE_DIR}/tools/gz_msgs_generate_factory.py
GZ_PROTOC_PLUGIN
$<TARGET_FILE:gz_msgs_gen>
$<TARGET_FILE:${PROJECT_NAME}_protoc_plugin>
INPUT_PROTOS
${proto_files}
PROTO_PACKAGE
Expand Down
59 changes: 56 additions & 3 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
add_subdirectory(generator)
add_subdirectory(src)
add_subdirectory(include)
##################################################
# Build a custom protoc plugin
set(PROTOC_PLUGIN ${PROJECT_NAME}_protoc_plugin)

gz_add_executable(${PROTOC_PLUGIN}
generator/Generator.cc
generator/generator_main.cc)
target_link_libraries(${PROTOC_PLUGIN}
protobuf::libprotoc
protobuf::libprotobuf)
target_include_directories(${PROTOC_PLUGIN} PRIVATE ${PROTOBUF_INCLUDE_DIR})
target_compile_features(${PROTOC_PLUGIN} PRIVATE ${GZ_CXX_11_FEATURES})

if (UNIX)
target_link_libraries(${PROTOC_PLUGIN} pthread)
endif()

install(TARGETS ${PROTOC_PLUGIN} DESTINATION ${GZ_BIN_INSTALL_DIR})

##################################################
# Build core library
gz_get_libsources_and_unittests(sources gtest_sources)

gz_create_core_library(SOURCES
src/Factory.cc
src/MessageFactory.cc
src/DynamicFactory.cc
)

target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
protobuf::libprotobuf
gz-math${GZ_MATH_VER}::gz-math${GZ_MATH_VER}
PRIVATE
TINYXML2::TINYXML2
)

target_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
SYSTEM PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Disable warning in generated *.pb.cc code
target_compile_options(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE -Wno-invalid-offsetof)
endif()

##################################################
# Build unit tests
# Build the unit tests.
gz_build_tests(TYPE UNIT
SOURCES
${gtest_sources}
LIB_DEPS
TINYXML2::TINYXML2
)

add_subdirectory(include/gz/msgs)
20 changes: 0 additions & 20 deletions core/generator/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion core/include/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion core/include/gz/CMakeLists.txt

This file was deleted.

41 changes: 0 additions & 41 deletions core/src/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install(
DIRECTORY gz
DESTINATION "${GZ_INCLUDE_INSTALL_DIR_FULL}"
DESTINATION share/protos
COMPONENT proto
FILES_MATCHING PATTERN "*.proto")

0 comments on commit 91ddb20

Please sign in to comment.