Skip to content

Commit

Permalink
Support configurable, CMake, and example file migration (#274)
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Jul 12, 2022
1 parent 7784120 commit 61a7f05
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 34 deletions.
38 changes: 33 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ install(DIRECTORY tools/

#--------------------------------------
# Create configuration and installation variables
set(gz_config_input "${CMAKE_CURRENT_SOURCE_DIR}/config/ignition-cmake-config.cmake.in")
set(gz_config_input "${CMAKE_CURRENT_SOURCE_DIR}/config/gz-cmake-config.cmake.in")
set(gz_config_output "${PROJECT_NAME_LOWER}-config.cmake")
set(gz_version_output "${PROJECT_NAME_LOWER}-config-version.cmake")
set(gz_config_install_dir "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME_LOWER}")
set(ign_pkgconfig_input "${CMAKE_CURRENT_SOURCE_DIR}/config/ignition-cmake.pc.in")
set(ign_pkgconfig_input "${CMAKE_CURRENT_SOURCE_DIR}/config/gz-cmake.pc.in")
set(ign_pkgconfig_output "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
set(ign_pkgconfig_install_dir "${IGN_LIB_INSTALL_DIR}/pkgconfig")
set(ign_utilities_target ${PROJECT_EXPORT_NAME}-utilities)
Expand Down Expand Up @@ -141,25 +141,53 @@ install(
#============================================================================
# Install the files for this package
#============================================================================
set(ign_modules_install_dir "${gz_config_install_dir}/cmake${PROJECT_VERSION_MAJOR}")
set(gz_modules_install_dir "${gz_config_install_dir}/cmake${PROJECT_VERSION_MAJOR}")

file(GLOB modules "cmake/*.cmake")
file(GLOB templates "cmake/*.in")

install(
FILES ${modules} ${templates}
DESTINATION ${ign_modules_install_dir}
DESTINATION ${gz_modules_install_dir}
COMPONENT modules)

file(GLOB pkgconfig_templates "cmake/pkgconfig/*.in")

install(
FILES ${pkgconfig_templates}
DESTINATION ${ign_modules_install_dir}/pkgconfig
DESTINATION ${gz_modules_install_dir}/pkgconfig
COMPONENT modules)

message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")

# TODO(CH3): Deprecated. Remove on tock.
# Install symlinks for IgnPython and IgnBenchmark
set(tick_tocked_cmake_files
"GzPython.cmake"
"GzBenchmark.cmake")

# TODO(CH3): Deprecated. Remove on tock.
# Install symlinks for IgnPython and IgnBenchmark
foreach(cmake_file ${tick_tocked_cmake_files})
string(REGEX REPLACE "^Gz" "Ign" ign_cmake_file ${cmake_file})
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/cmake")

if (WIN32) # Windows requires copy instead of symlink
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy \
${CMAKE_INSTALL_PREFIX}\/${gz_modules_install_dir}\/${cmake_file} \
${PROJECT_BINARY_DIR}\/cmake/${ign_cmake_file})")
else()
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \
${CMAKE_INSTALL_PREFIX}\/${gz_modules_install_dir}\/${cmake_file} \
${PROJECT_BINARY_DIR}\/cmake/${ign_cmake_file})")
endif()

install(
FILES ${PROJECT_BINARY_DIR}/cmake/${ign_cmake_file}
DESTINATION ${gz_modules_install_dir}
COMPONENT modules)
endforeach()

include(CTest)
if (BUILD_TESTING)
add_subdirectory(test)
Expand Down
18 changes: 9 additions & 9 deletions cmake/GzPackaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ endmacro()
# gz_add_component(~), so users of gz-cmake should not call this
# function.
#
# NOTE: For gz-cmake developers, the variables needed by ignition.pc.in or
# ignition-component.pc.in MUST be set before calling this function.
# NOTE: For gz-cmake developers, the variables needed by gz.pc.in or
# gz-component.pc.in MUST be set before calling this function.
#
# Create a pkgconfig file for your target, and install it.
function(_gz_create_pkgconfig)
Expand All @@ -197,10 +197,10 @@ function(_gz_create_pkgconfig)
#------------------------------------
# Choose which input file to use
if(_gz_create_pkgconfig_COMPONENT)
set(pkgconfig_input "${IGNITION_CMAKE_DIR}/pkgconfig/ignition-component.pc.in")
set(pkgconfig_input "${IGNITION_CMAKE_DIR}/pkgconfig/gz-component.pc.in")
set(target_name ${PROJECT_LIBRARY_TARGET_NAME}-${_gz_create_pkgconfig_COMPONENT})
else()
set(pkgconfig_input "${IGNITION_CMAKE_DIR}/pkgconfig/ignition.pc.in")
set(pkgconfig_input "${IGNITION_CMAKE_DIR}/pkgconfig/gz.pc.in")
set(target_name ${PROJECT_LIBRARY_TARGET_NAME})
endif()

Expand Down Expand Up @@ -239,7 +239,7 @@ endfunction()
# function.
#
# NOTE: For gz-cmake developers, some of the variables needed by
# ignition-config.cmake.in or ignition-component-config.cmake.in MUST be
# gz-config.cmake.in or gz-component-config.cmake.in MUST be
# set before calling this function. The following variables are set
# automatically by this function:
# - import_target_name
Expand Down Expand Up @@ -270,20 +270,20 @@ function(_gz_create_cmake_package)

set(component ${_gz_create_cmake_package_COMPONENT})
set(target_name ${PROJECT_LIBRARY_TARGET_NAME}-${component})
set(gz_config_input "${IGNITION_CMAKE_DIR}/ignition-component-config.cmake.in")
set(gz_config_input "${IGNITION_CMAKE_DIR}/gz-component-config.cmake.in")
set(simple_import_name ${component})

elseif(_gz_create_cmake_package_ALL)

set(gz_config_input "${IGNITION_CMAKE_DIR}/ignition-all-config.cmake.in")
set(gz_config_input "${IGNITION_CMAKE_DIR}/gz-all-config.cmake.in")
set(target_name ${PROJECT_LIBRARY_TARGET_NAME}-all)
set(all_pkg_name ${PROJECT_LIBRARY_TARGET_NAME}-all)
set(simple_import_name all)

else()

set(target_name ${PROJECT_LIBRARY_TARGET_NAME})
set(gz_config_input "${IGNITION_CMAKE_DIR}/ignition-config.cmake.in")
set(gz_config_input "${IGNITION_CMAKE_DIR}/gz-config.cmake.in")
set(simple_import_name core)

endif()
Expand All @@ -298,7 +298,7 @@ function(_gz_create_cmake_package)

endif()

# This gets used by the ignition-*.config.cmake.in files
# This gets used by the gz-*.config.cmake.in files
set(target_output_filename ${target_name}-targets.cmake)
set(gz_config_output "${PROJECT_BINARY_DIR}/cmake/${target_name}-config.cmake")
set(gz_version_output "${PROJECT_BINARY_DIR}/cmake/${target_name}-config-version.cmake")
Expand Down
12 changes: 6 additions & 6 deletions cmake/GzUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ endfunction()
# ${IGN_DESIGNATION}.hh. This will only add them to the header, it will not
# generate or install them.
#
# This will also run configure_file on ign_auto_headers.hh.in and config.hh.in
# This will also run configure_file on gz_auto_headers.hh.in and config.hh.in
# and install them. This will NOT install any other files or directories that
# appear in the ${CMAKE_CURRENT_BINARY_DIR}.
#
Expand Down Expand Up @@ -821,7 +821,7 @@ function(gz_install_all_headers)
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR}/${component_name})

# Define the input/output of the configuration for the component "master" header
set(master_header_in ${IGNITION_CMAKE_DIR}/ign_auto_headers.hh.in)
set(master_header_in ${IGNITION_CMAKE_DIR}/gz_auto_headers.hh.in)
set(master_header_out ${CMAKE_CURRENT_BINARY_DIR}/${component_name}.hh)

else()
Expand All @@ -830,7 +830,7 @@ function(gz_install_all_headers)
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR})

# Define the input/output of the configuration for the core "master" header
set(master_header_in ${IGNITION_CMAKE_DIR}/ign_auto_headers.hh.in)
set(master_header_in ${IGNITION_CMAKE_DIR}/gz_auto_headers.hh.in)
set(master_header_out ${CMAKE_CURRENT_BINARY_DIR}/../${IGN_DESIGNATION}.hh)

endif()
Expand Down Expand Up @@ -1377,7 +1377,7 @@ function(gz_add_component component_name)
endif()

#------------------------------------
# Set variables that are needed by cmake/ignition-component-config.cmake.in
# Set variables that are needed by cmake/gz-component-config.cmake.in
set(component_pkg_name ${component_target_name})
if(gz_add_component_INTERFACE)
set(component_pkgconfig_lib)
Expand All @@ -1389,7 +1389,7 @@ function(gz_add_component component_name)
# variable is used in config files
set(component_name ${component_name})

# ... and by cmake/pkgconfig/ignition-component.pc.in
# ... and by cmake/pkgconfig/gz-component.pc.in
set(component_pkgconfig_requires ${${component_name}_PKGCONFIG_REQUIRES})
set(component_pkgconfig_requires_private ${${component_name}_PKGCONFIG_REQUIRES_PRIVATE})
set(component_pkgconfig_lib_deps ${${component_name}_PKGCONFIG_LIBS})
Expand Down Expand Up @@ -1437,7 +1437,7 @@ endfunction()
# Exports the `all` target. This function is private to gz-cmake.
function(_gz_export_target_all)

# find_all_pkg_components is used as a variable in ignition-all-config.cmake.in
# find_all_pkg_components is used as a variable in gz-all-config.cmake.in
set(find_all_pkg_components "")
get_property(all_known_components TARGET ${PROJECT_LIBRARY_TARGET_NAME}-all
PROPERTY INTERFACE_IGN_ALL_KNOWN_COMPONENTS)
Expand Down
2 changes: 1 addition & 1 deletion cmake/gz_auto_headers.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// ****** Do not modify this file. ******
// This file is automatically generated by CMake. Changes should instead be
// made to cmake/ign_auto_headers.hh.in in gz-cmake
// made to cmake/gz_auto_headers.hh.in in gz-cmake

#include <@PROJECT_INCLUDE_DIR@/config.hh>
${ign_headers}
2 changes: 1 addition & 1 deletion examples/comp_deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(gz-component_deps VERSION 0.1.0)
find_package(gz-cmake3 REQUIRED)
gz_configure_project(
REPLACE_IGNITION_INCLUDE_PATH gz
REPLACE_IGNITION_INCLUDE_PATH gz/component_deps
)
gz_configure_build(QUIT_IF_BUILD_ERRORS
COMPONENTS child parent)
Expand Down
2 changes: 1 addition & 1 deletion examples/core_nodep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(gz-core_no_deps VERSION 0.1.0)
find_package(gz-cmake3 REQUIRED)
gz_configure_project(
REPLACE_IGNITION_INCLUDE_PATH gz
REPLACE_IGNITION_INCLUDE_PATH gz/core_no_deps
)
gz_configure_build(QUIT_IF_BUILD_ERRORS)
gz_create_packages()
Expand Down
2 changes: 1 addition & 1 deletion examples/core_nodep_static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(gz-core_no_deps_static VERSION 0.1.0)
find_package(gz-cmake3 REQUIRED)
gz_configure_project(
REPLACE_IGNITION_INCLUDE_PATH gz
REPLACE_IGNITION_INCLUDE_PATH gz/core_no_deps_static
)
OPTION(BUILD_SHARED_LIBS OFF)
gz_configure_build(QUIT_IF_BUILD_ERRORS)
Expand Down
2 changes: 1 addition & 1 deletion examples/find_ogre2/ogre-2.1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ find_package(gz-cmake3 REQUIRED)

message(STATUS "Finding OGRE 2.1")

gz_find_package(IgnOGRE2 VERSION 2.1.0
gz_find_package(GzOGRE2 VERSION 2.1.0
COMPONENTS HlmsPbs HlmsUnlit Overlay)

message(STATUS "OGRE2_FOUND: " ${OGRE2_FOUND})
Expand Down
2 changes: 1 addition & 1 deletion examples/find_ogre2/ogre-2.2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ find_package(gz-cmake3 REQUIRED)

message(STATUS "Finding OGRE 2.2")

gz_find_package(IgnOGRE2 VERSION 2.2.0
gz_find_package(GzOGRE2 VERSION 2.2.0
COMPONENTS HlmsPbs HlmsUnlit Overlay)

message(STATUS "OGRE2_FOUND: " ${OGRE2_FOUND})
Expand Down
16 changes: 8 additions & 8 deletions test/cmake_minimum_required.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

export CMAKE_FILES_TO_CHECK="
$1/CMakeLists.txt
$1/cmake/ignition-all-config.cmake.in
$1/cmake/ignition-component-config.cmake.in
$1/cmake/ignition-config.cmake.in
$1/config/ignition-cmake-config.cmake.in"
$1/cmake/gz-all-config.cmake.in
$1/cmake/gz-component-config.cmake.in
$1/cmake/gz-config.cmake.in
$1/config/gz-cmake-config.cmake.in"
unset TEST_CMAKE_MIN_REQUIRED_FAILED
# first argument is root of gz-cmake repository
if [[ ! -d "$1" \
|| ! -a "$1/CMakeLists.txt" \
|| ! -a "$1/cmake/ignition-all-config.cmake.in" \
|| ! -a "$1/cmake/ignition-component-config.cmake.in" \
|| ! -a "$1/cmake/ignition-config.cmake.in" \
|| ! -a "$1/config/ignition-cmake-config.cmake.in" ]]; then
|| ! -a "$1/cmake/gz-all-config.cmake.in" \
|| ! -a "$1/cmake/gz-component-config.cmake.in" \
|| ! -a "$1/cmake/gz-config.cmake.in" \
|| ! -a "$1/config/gz-cmake-config.cmake.in" ]]; then
echo the first argument must be the root of the gz-cmake repository
export TEST_CMAKE_MIN_REQUIRED_FAILED=1
else
Expand Down

0 comments on commit 61a7f05

Please sign in to comment.