Skip to content

Commit

Permalink
Add examples using static libraries (#202)
Browse files Browse the repository at this point in the history
This adds an example that builds a static library
and a second example that links against that static
library.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Jan 7, 2022
1 parent 7eb246d commit 3f918e0
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ set(example_directories
no_ignition_prefix
prerelease
core_nodep
core_nodep_static
core_child
core_child_private
core_static_child
comp_deps
)
if (NOT CMAKE_GENERATOR MATCHES "Visual Studio")
Expand All @@ -36,12 +38,18 @@ foreach(example ${example_directories})
elseif (${example} STREQUAL "core_nodep")
set(example_tarball_name ignition-core_no_deps-0.1.0.tar.bz2)
set(run_codecheck true)
elseif (${example} STREQUAL "core_nodep_static")
set(example_tarball_name ignition-core_no_deps_static-0.1.0.tar.bz2)
set(run_codecheck true)
elseif (${example} STREQUAL "core_child")
set(example_tarball_name ignition-core_child-0.1.0.tar.bz2)
set(run_codecheck true)
elseif (${example} STREQUAL "core_child_private")
set(example_tarball_name ignition-core_child_private-0.1.0.tar.bz2)
set(run_codecheck true)
elseif (${example} STREQUAL "core_static_child")
set(example_tarball_name ignition-core_static_child-0.1.0.tar.bz2)
set(run_codecheck true)
elseif (${example} STREQUAL "comp_deps")
set(example_tarball_name ignition-component_deps-0.1.0.tar.bz2)
elseif (${example} STREQUAL "use_component_depsA")
Expand Down Expand Up @@ -153,6 +161,7 @@ endforeach()
foreach (build_type ${build_types})
add_dependencies(core_child_${build_type} core_nodep_${build_type})
add_dependencies(core_child_private_${build_type} core_nodep_${build_type})
add_dependencies(core_static_child_${build_type} core_nodep_static_${build_type})
if (TARGET use_component_depsA_${build_type})
add_dependencies(use_component_depsA_${build_type} comp_deps_${build_type})
endif()
Expand Down
8 changes: 8 additions & 0 deletions examples/core_nodep_static/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(ignition-core_no_deps_static VERSION 0.1.0)
find_package(ignition-cmake2 REQUIRED)
ign_configure_project()
OPTION(BUILD_SHARED_LIBS OFF)
ign_configure_build(QUIT_IF_BUILD_ERRORS)
ign_create_packages()
ign_create_docs()
14 changes: 14 additions & 0 deletions examples/core_nodep_static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# core\_nodep\_static example

This package sets the `BUILD_SHARED_LIBS` cmake variable to `OFF`,
ensuring that a static library will be created.
The package has no dependencies.

To build:

~~~
mkdir build
cd build
cmake ..
make
~~~
Empty file.
29 changes: 29 additions & 0 deletions examples/core_nodep_static/src/AlmostEmpty.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <ignition/core_no_deps_static/Export.hh>

namespace ignition
{
namespace core_no_deps
{
class IGNITION_CORE_NO_DEPS_STATIC_VISIBLE AlmostEmpty
{
public: AlmostEmpty() = default;
};
}
}
3 changes: 3 additions & 0 deletions examples/core_nodep_static/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ign_get_libsources_and_unittests(sources gtest_sources)
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 11)
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
Empty file.
8 changes: 8 additions & 0 deletions examples/core_static_child/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(ignition-core_static_child VERSION 0.1.0)
find_package(ignition-cmake2 REQUIRED)
ign_configure_project()
ign_find_package(ignition-core_no_deps_static REQUIRED)
ign_configure_build(QUIT_IF_BUILD_ERRORS)
ign_create_packages()
ign_create_docs(TAGFILES "${IGNITION-CORE_NO_DEPS_STATIC_DOXYGEN_TAGFILE} = ${IGNITION-CORE_NO_DEPS_STATIC_API_URL}")
15 changes: 15 additions & 0 deletions examples/core_static_child/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# core\_static\_child example

This package links against that static library provided by
the `core_no_deps_static` package.

To build, ensure that `core_no_deps_static` has been installed somewhere
in your `CMAKE_PREFIX_PATH` and then run:

~~~
mkdir build
cd build
cmake ..
make
~~~

Empty file.
6 changes: 6 additions & 0 deletions examples/core_static_child/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ign_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})
17 changes: 17 additions & 0 deletions examples/core_static_child/src/empty.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

Empty file.

0 comments on commit 3f918e0

Please sign in to comment.