Skip to content

Commit fd2e261

Browse files
authored
Project option: REPLACE_IGNITION_INCLUDE_PATH (#190)
* Add REPLACE_IGNITION_INCLUDE_PATH option to IgnConfigureProject. The include paths are now configurable and default to ignition/${IGN_DESIGNATION} to match existing behavior. * Use ign_install_all_headers in example Confirm location of auto-generated headers by including them from AlmostEmpty.cc * Use IGN_INCLUDE_INSTALL_DIR_POSTFIX in templates Signed-off-by: Steve Peters <scpeters@openrobotics.org>
1 parent 3971db8 commit fd2e261

13 files changed

+57
-29
lines changed

cmake/IgnConfigureBuild.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ macro(ign_configure_build)
169169
set (CPPCHECK_INCLUDE_DIRS)
170170
set (potential_cppcheck_include_dirs
171171
${CMAKE_BINARY_DIR}
172-
${CMAKE_SOURCE_DIR}/include/ignition/${IGN_DESIGNATION}
172+
${CMAKE_SOURCE_DIR}/include/${PROJECT_INCLUDE_DIR}
173173
${CMAKE_SOURCE_DIR}/test/integration
174174
${CMAKE_SOURCE_DIR}/test/regression
175175
${CMAKE_SOURCE_DIR}/test/performance)
@@ -323,8 +323,8 @@ function(_ign_find_include_script)
323323
add_subdirectory("${include_start}/include")
324324
elseif(EXISTS "${include_start}/include/ignition/CMakeLists.txt")
325325
add_subdirectory("${include_start}/include/ignition")
326-
elseif(EXISTS "${include_start}/include/ignition/${IGN_DESIGNATION}/CMakeLists.txt")
327-
add_subdirectory("${include_start}/include/ignition/${IGN_DESIGNATION}")
326+
elseif(EXISTS "${include_start}/include/${PROJECT_INCLUDE_DIR}/CMakeLists.txt")
327+
add_subdirectory("${include_start}/include/${PROJECT_INCLUDE_DIR}")
328328
else()
329329
message(AUTHOR_WARNING
330330
"You have an include directory [${include_start}/include] without a "

cmake/IgnConfigureProject.cmake

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
# Sets up an ignition library project.
88
#
99
# NO_IGNITION_PREFIX: Optional. Don't use ignition as prefix in
10-
# cmake project name.
10+
# cmake project name.
11+
# REPLACE_IGNITION_INCLUDE_PATH: Optional. Specify include folder
12+
# names to replace the default value of
13+
# ignition/${IGN_DESIGNATION}
1114
# VERSION_SUFFIX: Optional. Specify a prerelease version suffix.
1215
#
1316
#===============================================================================
@@ -32,7 +35,7 @@ macro(ign_configure_project)
3235
#------------------------------------
3336
# Define the expected arguments
3437
set(options NO_IGNITION_PREFIX)
35-
set(oneValueArgs VERSION_SUFFIX)
38+
set(oneValueArgs REPLACE_IGNITION_INCLUDE_PATH VERSION_SUFFIX)
3639
set(multiValueArgs) # We are not using multiValueArgs yet
3740

3841
#------------------------------------
@@ -82,6 +85,12 @@ macro(ign_configure_project)
8285
set(PROJECT_EXPORT_NAME ${PROJECT_NAME_LOWER})
8386
set(PROJECT_LIBRARY_TARGET_NAME ${PROJECT_NAME_LOWER})
8487

88+
if(ign_configure_project_REPLACE_IGNITION_INCLUDE_PATH)
89+
set(PROJECT_INCLUDE_DIR ${ign_configure_project_REPLACE_IGNITION_INCLUDE_PATH})
90+
else()
91+
set(PROJECT_INCLUDE_DIR ignition/${IGN_DESIGNATION})
92+
endif()
93+
8594
# version <major>.<minor>
8695
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
8796

cmake/IgnUtils.cmake

+8-8
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,13 @@ function(ign_install_all_headers)
682682

683683
# Add each header, prefixed by its directory, to the auto headers variable
684684
foreach(header ${headers})
685-
set(ign_headers "${ign_headers}#include <ignition/${IGN_DESIGNATION}/${header}>\n")
685+
set(ign_headers "${ign_headers}#include <${PROJECT_INCLUDE_DIR}/${header}>\n")
686686
endforeach()
687687

688688
if("." STREQUAL ${dir})
689-
set(destination "${IGN_INCLUDE_INSTALL_DIR_FULL}/ignition/${IGN_DESIGNATION}")
689+
set(destination "${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR}")
690690
else()
691-
set(destination "${IGN_INCLUDE_INSTALL_DIR_FULL}/ignition/${IGN_DESIGNATION}/${dir}")
691+
set(destination "${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR}/${dir}")
692692
endif()
693693

694694
install(
@@ -700,15 +700,15 @@ function(ign_install_all_headers)
700700

701701
# Add generated headers to the list of includes
702702
foreach(header ${ign_install_all_headers_GENERATED_HEADERS})
703-
set(ign_headers "${ign_headers}#include <ignition/${IGN_DESIGNATION}/${header}>\n")
703+
set(ign_headers "${ign_headers}#include <${PROJECT_INCLUDE_DIR}/${header}>\n")
704704
endforeach()
705705

706706
if(ign_install_all_headers_COMPONENT)
707707

708708
set(component_name ${ign_install_all_headers_COMPONENT})
709709

710710
# Define the install directory for the component meta header
711-
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/ignition/${IGN_DESIGNATION}/${component_name})
711+
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR}/${component_name})
712712

713713
# Define the input/output of the configuration for the component "master" header
714714
set(master_header_in ${IGNITION_CMAKE_DIR}/ign_auto_headers.hh.in)
@@ -717,7 +717,7 @@ function(ign_install_all_headers)
717717
else()
718718

719719
# Define the install directory for the core master meta header
720-
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/ignition/${IGN_DESIGNATION})
720+
set(meta_header_install_dir ${IGN_INCLUDE_INSTALL_DIR_FULL}/${PROJECT_INCLUDE_DIR})
721721

722722
# Define the input/output of the configuration for the core "master" header
723723
set(master_header_in ${IGNITION_CMAKE_DIR}/ign_auto_headers.hh.in)
@@ -936,7 +936,7 @@ function(ign_create_core_library)
936936
# Create the target for the core library, and configure it to be installed
937937
_ign_add_library_or_component(
938938
LIB_NAME ${PROJECT_LIBRARY_TARGET_NAME}
939-
INCLUDE_DIR "ignition/${IGN_DESIGNATION_LOWER}"
939+
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}"
940940
EXPORT_BASE IGNITION_${IGN_DESIGNATION_UPPER}
941941
SOURCES ${sources}
942942
${interface_option})
@@ -1120,7 +1120,7 @@ function(ign_add_component component_name)
11201120
# Create the target for this component, and configure it to be installed
11211121
_ign_add_library_or_component(
11221122
LIB_NAME ${component_target_name}
1123-
INCLUDE_DIR "ignition/${IGN_DESIGNATION_LOWER}/${include_subdir}"
1123+
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}/${include_subdir}"
11241124
EXPORT_BASE IGNITION_${IGN_DESIGNATION_UPPER}_${component_name_upper}
11251125
SOURCES ${sources}
11261126
${interface_option})

cmake/ign_auto_headers.hh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
// This file is automatically generated by CMake. Changes should instead be
2020
// made to cmake/ign_auto_headers.hh.in in ignition-cmake
2121

22-
#include <ignition/@IGN_DESIGNATION@/config.hh>
22+
#include <@PROJECT_INCLUDE_DIR@/config.hh>
2323
${ign_headers}

cmake/pkgconfig/ignition-component.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
prefix=${pcfiledir}/@PC_CONFIG_RELATIVE_PATH_TO_PREFIX@
22
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3-
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/ignition/@IGN_DESIGNATION@@PROJECT_VERSION_MAJOR@
3+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@IGN_INCLUDE_INSTALL_DIR_POSTFIX@
44

55
Name: Ignition @IGN_DESIGNATION@ @component_name@
66
Description: A set of @IGN_DESIGNATION@ @component_name@ classes for robot applications

cmake/pkgconfig/ignition.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
prefix=${pcfiledir}/@PC_CONFIG_RELATIVE_PATH_TO_PREFIX@
22
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3-
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/ignition/@IGN_DESIGNATION@@PROJECT_VERSION_MAJOR@
3+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@IGN_INCLUDE_INSTALL_DIR_POSTFIX@
44

55
Name: Ignition @IGN_DESIGNATION@
66
Description: A set of @IGN_DESIGNATION@ classes for robot applications

config/ignition-cmake.pc.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
prefix=${pcfiledir}/@IGN_PC_CONFIG_RELATIVE_PATH_TO_PREFIX@
2-
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/ignition/@IGN_DESIGNATION@@PROJECT_VERSION_MAJOR@
2+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@IGN_INCLUDE_INSTALL_DIR_POSTFIX@
33

44
Name: Ignition @IGN_DESIGNATION@
55
Description: Build system package for the ignition libraries
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
22
project(no_ignition_prefix VERSION 0.1.0)
33
find_package(ignition-cmake2 REQUIRED)
4-
ign_configure_project(NO_IGNITION_PREFIX)
4+
ign_configure_project(
5+
NO_IGNITION_PREFIX
6+
REPLACE_IGNITION_INCLUDE_PATH no_ign)
57
ign_configure_build(QUIT_IF_BUILD_ERRORS)
68
ign_create_packages()
79
ign_create_docs()

examples/no_ignition_prefix/README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
# no\_ignition\_prefix
1+
# no\_ignition\_prefix example
22

3-
This package uses the `NO_IGNITION_PREFIX` option to `ign_configure_project`
3+
## Configuring project name
4+
5+
This package uses the `NO_IGNITION_PREFIX` option in `ign_configure_project`
46
to allow a cmake package name without the `ignition-` prefix.
5-
To confirm, build this package and then observe that the tarball,
7+
To confirm, configure this package and
8+
`package_source` and then observe that the tarball,
69
pkg-config `.pc` file, and cmake config files omit the `ignition-` prefix:
710

811
~~~
912
mkdir build
1013
cd build
1114
cmake ..
12-
make
1315
make package_source
1416
~~~
1517

1618
* `no_ignition_prefix-0.1.0.tar.bz2`
1719
* `cmake/no_ignition_prefix-config.cmake`
1820
* `cmake/pkgconfig/no_ignition_prefix.pc`
21+
22+
## Configuring include directory names
23+
24+
This package uses the `REPLACE_IGNITION_INCLUDE_PATH` option in `ign_configure_project`
25+
to allow a custom include path of `no_ign`, which doesn't start with `ignition/`.
26+
To confirm, build the package and observe that `AlmostEmpty.cc`
27+
compiles successfully while including `no_ign/Export.hh`:
28+
29+
~~~
30+
mkdir build
31+
cd build
32+
cmake ..
33+
make
34+
~~~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(no_ign)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ign_install_all_headers()

examples/no_ignition_prefix/include/no_ign/config.hh.in

Whitespace-only changes.

examples/no_ignition_prefix/src/AlmostEmpty.cc

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*
1616
*/
1717

18-
#include <ignition/no_ignition_prefix/Export.hh>
18+
#include <no_ignition_prefix.hh>
19+
#include <no_ign/config.hh>
20+
#include <no_ign/Export.hh>
1921

20-
namespace ignition
22+
namespace no_ignition_prefix
2123
{
22-
namespace no_ignition_prefix
24+
class IGNITION_NO_IGNITION_PREFIX_VISIBLE AlmostEmpty
2325
{
24-
class IGNITION_NO_IGNITION_PREFIX_VISIBLE AlmostEmpty
25-
{
26-
};
27-
}
26+
};
2827
}

0 commit comments

Comments
 (0)