Skip to content

Commit

Permalink
Deprecate ign_build_tests, ign_get_libsources_and_unittests, ign_get_…
Browse files Browse the repository at this point in the history
…sources, ign_install_all_headers (#254)

Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored May 12, 2022
1 parent a99c66d commit 4eab833
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 40 deletions.
83 changes: 64 additions & 19 deletions cmake/IgnUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,24 @@ macro(_gz_list_to_string _output _input_list)
endmacro()

#################################################
# ign_get_sources_and_unittests(<lib_srcs> <tests>)
# gz_get_libsources_and_unittests(<lib_srcs> <tests>)
#
# Grab all the files ending in "*.cc" from either the "src/" subdirectory or the
# current subdirectory if "src/" does not exist. They will be collated into
# library source files <lib_sources_var> and unittest source files <tests_var>.
#
# These output variables can be consumed directly by ign_create_core_library(~),
# ign_add_component(~), ign_build_tests(~), and ign_build_executables(~).
# ign_add_component(~), gz_build_tests(~), and ign_build_executables(~).
function(ign_get_libsources_and_unittests lib_sources_var tests_var)
# TODO(chapulina) Enable warnings after all libraries have migrated.
# message(WARNING "ign_get_libsources_and_unittests is deprecated, use gz_get_libsources_and_unittests instead.")

gz_get_libsources_and_unittests(${lib_sources_var} ${tests_var})

set(${lib_sources_var} ${${lib_sources_var}} PARENT_SCOPE)
set(${tests_var} ${${tests_var}} PARENT_SCOPE)
endfunction()
function(gz_get_libsources_and_unittests lib_sources_var tests_var)

# Glob all the source files
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/src)
Expand Down Expand Up @@ -571,12 +580,20 @@ function(ign_get_libsources_and_unittests lib_sources_var tests_var)
endfunction()

#################################################
# ign_get_sources(<sources>)
# gz_get_sources(<sources>)
#
# From the current directory, grab all the source files and place them into
# <sources>. Remove their paths to make them suitable for passing into
# ign_add_[library/tests].
function(ign_get_sources sources_var)
# TODO(chapulina) Enable warnings after all libraries have migrated.
# message(WARNING "ign_get_sources is deprecated, use gz_get_sources instead.")

gz_get_sources(${sources_var})

set(${sources_var} ${${sources_var}} PARENT_SCOPE)
endfunction()
function(gz_get_sources sources_var)

# GLOB all the source files
file(GLOB source_files "*.cc")
Expand All @@ -599,7 +616,7 @@ function(ign_get_sources sources_var)
endfunction()

#################################################
# ign_install_all_headers(
# gz_install_all_headers(
# [EXCLUDE_FILES <excluded_headers>]
# [EXCLUDE_DIRS <dirs>]
# [GENERATED_HEADERS <headers>]
Expand All @@ -625,17 +642,31 @@ endfunction()
# config.hh file since it would be redundant with the core library.
#
function(ign_install_all_headers)
# TODO(chapulina) Enable warnings after all libraries have migrated.
# message(WARNING "ign_install_all_headers is deprecated, use gz_install_all_headers instead.")

#------------------------------------
# Define the expected arguments
set(options)
set(oneValueArgs COMPONENT) # We are not using oneValueArgs yet
set(oneValueArgs COMPONENT)
set(multiValueArgs EXCLUDE_FILES EXCLUDE_DIRS GENERATED_HEADERS)

#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_install_all_headers "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(gz_install_all_headers_skip_parsing true)
gz_install_all_headers()
endfunction()
function(gz_install_all_headers)

# Deprecated, remove skip parsing logic in version 4
if (NOT gz_install_all_headers_skip_parsing)
#------------------------------------
# Define the expected arguments
set(options)
set(oneValueArgs COMPONENT)
set(multiValueArgs EXCLUDE_FILES EXCLUDE_DIRS GENERATED_HEADERS)

#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_install_all_headers "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
endif()

#------------------------------------
# Build the list of directories
Expand Down Expand Up @@ -1597,7 +1628,7 @@ macro(ign_build_executables)
endmacro()

#################################################
# ign_build_tests(TYPE <test_type>
# gz_build_tests(TYPE <test_type>
# SOURCES <sources>
# [LIB_DEPS <library_dependencies>]
# [INCLUDE_DIRS <include_dependencies>]
Expand Down Expand Up @@ -1627,33 +1658,47 @@ endmacro()
# into your executable's directory.
#
macro(ign_build_tests)
# TODO(chapulina) Enable warnings after all libraries have migrated.
# message(WARNING "ign_build_tests is deprecated, use gz_build_tests instead.")

#------------------------------------
# Define the expected arguments
set(options SOURCE EXCLUDE_PROJECT_LIB) # NOTE: DO NOT USE "SOURCE", we're adding it here to catch typos
set(oneValueArgs TYPE TEST_LIST)
set(multiValueArgs SOURCES LIB_DEPS INCLUDE_DIRS)
_gz_cmake_parse_arguments(gz_build_tests "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(gz_build_tests_skip_parsing true)
gz_build_tests(${PACKAGE_NAME})
endmacro()
macro(gz_build_tests)

# Deprecated, remove skip parsing logic in version 4
if (NOT gz_build_tests_skip_parsing)
#------------------------------------
# Define the expected arguments
set(options SOURCE EXCLUDE_PROJECT_LIB) # NOTE: DO NOT USE "SOURCE", we're adding it here to catch typos
set(oneValueArgs TYPE TEST_LIST)
set(multiValueArgs SOURCES LIB_DEPS INCLUDE_DIRS)

#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_build_tests "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
#------------------------------------
# Parse the arguments
_gz_cmake_parse_arguments(gz_build_tests "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
endif()

if(NOT gz_build_tests_TYPE)
# If you have encountered this error, you are probably migrating to the
# new ignition-cmake system. Be sure to also provide a SOURCES argument
# when calling ign_build_tests.
# when calling gz_build_tests.
message(FATAL_ERROR "Developer error: You must specify a TYPE for your tests!")
endif()

if(gz_build_tests_SOURCE)

# We have encountered cases where someone accidentally passes a SOURCE
# argument instead of a SOURCES argument into ign_build_tests, and the macro
# argument instead of a SOURCES argument into gz_build_tests, and the macro
# didn't report any problem with it. Adding this warning should make it more
# clear when that particular typo occurs.
message(AUTHOR_WARNING
"Your script has specified SOURCE for ign_build_tests, which is not an "
"Your script has specified SOURCE for gz_build_tests, which is not an "
"option. Did you mean to specify SOURCES (note the plural)?")

endif()
Expand Down
2 changes: 1 addition & 1 deletion examples/comp_deps/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)

ign_create_core_library(SOURCES ${sources})
4 changes: 2 additions & 2 deletions examples/core_child/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-core_no_deps::ignition-core_no_deps)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/core_child_private/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PRIVATE
ignition-core_no_deps::ignition-core_no_deps)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/core_nodep/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/core_nodep_static/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/core_static_child/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-core_no_deps_static::ignition-core_no_deps_static)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
2 changes: 1 addition & 1 deletion examples/no_ignition_prefix/include/no_ign/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ign_install_all_headers()
gz_install_all_headers()
4 changes: 2 additions & 2 deletions examples/no_ignition_prefix/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
2 changes: 1 addition & 1 deletion examples/sanitizers/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_add_executable(asanfail ${sources})
add_test(asan asanfail)
4 changes: 2 additions & 2 deletions examples/use_component_depsA/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-component_deps::ignition-component_deps-child)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/use_component_depsB/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-component_deps::ignition-component_deps-child)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
4 changes: 2 additions & 2 deletions examples/use_component_depsC/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ign_get_libsources_and_unittests(sources gtest_sources)
gz_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-component_deps::ignition-component_deps-child)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})

0 comments on commit 4eab833

Please sign in to comment.