Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues when including Polaris in an external CMake project. #54

Merged
merged 11 commits into from
Aug 16, 2023
Merged
20 changes: 18 additions & 2 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ jobs:
cd cmake_build
MSBuild.exe p1_polaris_client.sln

- name: Build External Project Example (CMake, Linux)
if: matrix.tool == 'cmake' && matrix.os == 'ubuntu-latest'
run: |
mkdir examples/external_cmake_project/build
cd examples/external_cmake_project/build
cmake ..
make

# Bazel build support.
- name: Use Bazel 4.2.2
if: matrix.tool == 'bazel'
Expand Down Expand Up @@ -205,11 +213,11 @@ jobs:
make -j

# CMake build support.
- name: Install CMake 3.16.x
- name: Install CMake 3.18.x
if: matrix.tool == 'cmake'
uses: jwlawson/actions-setup-cmake@v1.4
with:
cmake-version: '3.16.x'
cmake-version: '3.18.x'

- name: Setup Build (CMake)
if: matrix.tool == 'cmake'
Expand All @@ -231,6 +239,14 @@ jobs:
cd cmake_build
MSBuild.exe p1_polaris_c_client.sln

- name: Build External Project Example (CMake, Linux)
if: matrix.tool == 'cmake' && matrix.os == 'ubuntu-latest'
run: |
mkdir examples/external_cmake_project/build
cd examples/external_cmake_project/build
cmake ..
make

# Bazel build support.
- name: Use Bazel 4.2.2
if: matrix.tool == 'bazel'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ build/

# Python
*.pyc
.idea/
venv/

# Visual Studio Code
.vscode
Expand Down
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Copyright (C) Point One Navigation - All Rights Reserved
project(p1_polaris_client)

cmake_minimum_required(VERSION 3.3.2)
cmake_minimum_required(VERSION 3.6)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

# Option definitions.
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries."
ON)

option(BUILD_EXAMPLES "Build example applications." ON)
option(POLARIS_BUILD_EXAMPLES "Build example applications." ON)

# Backwards compatibility. BUILD_EXAMPLES is deprecated and may be removed in a
# future release.
if (DEFINED BUILD_EXAMPLES AND BUILD_EXAMPLES)
set(POLARIS_BUILD_EXAMPLES ${BUILD_EXAMPLES})
endif()

# Set toolchain parameters before calling project().
set(CMAKE_CXX_STANDARD 11)

# Define the project and setup the compiler toolchain.
project(p1_polaris_client)

# Set compilation flags.
if (MSVC)
Expand Down Expand Up @@ -39,15 +49,12 @@ include_directories(${GLOG_INCLUDE_DIRS})

# Add the C library, used by the C++ library.
add_subdirectory(c)
include_directories(${PROJECT_SOURCE_DIR}/c/src)

# Add the source directory to the include path.
include_directories(${PROJECT_SOURCE_DIR}/src)

# Polaris client C++ library - all messages and supporting code.
add_library(polaris_cpp_client
src/point_one/polaris/polaris_client.cc
src/point_one/polaris/polaris_interface.cc)
target_include_directories(polaris_client PUBLIC ${PROJECT_SOURCE_DIR}/src)
if (MSVC)
target_compile_definitions(polaris_cpp_client PRIVATE BUILDING_DLL)
endif()
Expand All @@ -69,6 +76,6 @@ install(DIRECTORY src/point_one DESTINATION include
# Example Applications
################################################################################

if (BUILD_EXAMPLES)
if (POLARIS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
21 changes: 13 additions & 8 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# Copyright (C) Point One Navigation - All Rights Reserved
project(p1_polaris_c_client)

cmake_minimum_required(VERSION 3.3.2)
cmake_minimum_required(VERSION 3.6)

# Option definitions.
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries."
ON)

option(BUILD_EXAMPLES "Build example applications." ON)
option(POLARIS_BUILD_EXAMPLES "Build example applications." ON)

option(POLARIS_ENABLE_PRINT
"Enable Polaris debug/trace print messages." ON)

option(POLARIS_ENABLE_TLS "Enable TLS support when connecting to Polaris." ON)

# Backwards compatibility. BUILD_EXAMPLES is deprecated and may be removed in a
# future release.
if (DEFINED BUILD_EXAMPLES AND BUILD_EXAMPLES)
set(POLARIS_BUILD_EXAMPLES ${BUILD_EXAMPLES})
endif()

# Define the project and setup the compiler toolchain.
project(p1_polaris_c_client)

# Set compilation flags.
if (MSVC)
add_compile_options(/W4 /WX)
Expand All @@ -38,13 +45,11 @@ endif()
# Library Definitions
################################################################################

# Add the source directory to the include path.
include_directories(${PROJECT_SOURCE_DIR}/src)

# Polaris client C library - all messages and supporting code.
add_library(polaris_client
src/point_one/polaris/polaris.c
src/point_one/polaris/polaris_internal.c)
target_include_directories(polaris_client PUBLIC ${PROJECT_SOURCE_DIR}/src)
if (MSVC)
target_compile_definitions(polaris_client PRIVATE BUILDING_DLL)
endif()
Expand All @@ -65,6 +70,6 @@ install(DIRECTORY src/point_one DESTINATION include
# Example Applications
################################################################################

if (BUILD_EXAMPLES)
if (POLARIS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
52 changes: 52 additions & 0 deletions c/examples/external_cmake_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
################################################################################
# This is a simple example of how to import the Polaris client library in
# your own project using the CMake FetchContent feature. We strongly encourage
# you to use FetchContent to download Polaris client from the publicly available
# source code.
#
# Alternatively, you may choose to use a git submodule to import the source code
# into your repository. We do not recommend copying the Polaris client souce
# code directly into your repository. Doing so makes it much more difficult to
# receive updates as new features and improvements are released.
################################################################################

# Note: CMake 3.18 or newer required to use SOURCE_SUBDIR below in order to
# include just the Polaris C library and not the top-level C++ library.
cmake_minimum_required(VERSION 3.18)

project(polaris_usage_example C)

# Use FetchContent to import the Polaris client C library using Git.
#
# Note that we always recommend using a specific version of the library in your
# code by specifying a git tag (e.g., `GIT_TAG v1.3.1`), and updating that as
# new versions are released. That way, you can be sure that your code is always
# built with a known version of Polaris client. If you prefer, however, you can
# set the GIT_TAG to track the latest changes by setting `GIT_TAG master` below.
#
# We explicitly disable example applications from the Polaris client library by
# setting POLARIS_BUILD_EXAMPLES to OFF below. We only want to build the library
# and make the fusion_engine_client CMake target available here. By default, if
# we do not tell it otherwise, FetchContent_MakeAvailable() will also import all
# of the example applications in polaris/c/examples/.
#
# It is important to specify it as an INTERNAL variable. If you do not do this,
# the option definition in the fusion-engine-client CMakeLists.txt file will
# override this value and enable the example applications anyway. This is a
# result of CMP0077, which was added in CMake 3.13.
include(FetchContent)
FetchContent_Declare(
polaris
#GIT_REPOSITORY https://github.com/PointOneNav/polaris.git
#GIT_TAG v1.3.1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..
SOURCE_SUBDIR c
)
set(POLARIS_BUILD_EXAMPLES OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(polaris)

# Now we define an example application that uses the Polaris client library.
# In your own code, you can link any add_executable() or add_library() target
# with polaris_client by calling target_link_libraries() as shown.
add_executable(example_app main.c)
target_link_libraries(example_app PUBLIC polaris_client)
12 changes: 12 additions & 0 deletions c/examples/external_cmake_project/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**************************************************************************/ /**
* @brief Example external cmake project.
*
* Copyright (c) Point One Navigation - All Rights Reserved
******************************************************************************/

#include <point_one/polaris/portability.h>

int main(int argc, const char* argv[]) {
P1_printf("Hello, world!\n");
return 0;
}
51 changes: 51 additions & 0 deletions examples/external_cmake_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
################################################################################
# This is a simple example of how to import the Polaris client library in
# your own project using the CMake FetchContent feature. We strongly encourage
# you to use FetchContent to download Polaris client from the publicly available
# source code.
#
# Alternatively, you may choose to use a git submodule to import the source code
# into your repository. We do not recommend copying the Polaris client souce
# code directly into your repository. Doing so makes it much more difficult to
# receive updates as new features and improvements are released.
################################################################################

cmake_minimum_required(VERSION 3.6)

set(CMAKE_CXX_STANDARD 11)

project(polaris_usage_example C CXX)

# Use FetchContent to import the Polaris client C library using Git.
#
# Note that we always recommend using a specific version of the library in your
# code by specifying a git tag (e.g., `GIT_TAG v1.3.1`), and updating that as
# new versions are released. That way, you can be sure that your code is always
# built with a known version of Polaris client. If you prefer, however, you can
# set the GIT_TAG to track the latest changes by setting `GIT_TAG master` below.
#
# We explicitly disable example applications from the Polaris client library by
# setting POLARIS_BUILD_EXAMPLES to OFF below. We only want to build the library
# and make the fusion_engine_client CMake target available here. By default, if
# we do not tell it otherwise, FetchContent_MakeAvailable() will also import all
# of the example applications in polaris/examples/.
#
# It is important to specify it as an INTERNAL variable. If you do not do this,
# the option definition in the fusion-engine-client CMakeLists.txt file will
# override this value and enable the example applications anyway. This is a
# result of CMP0077, which was added in CMake 3.13.
include(FetchContent)
FetchContent_Declare(
polaris
#GIT_REPOSITORY https://github.com/PointOneNav/polaris.git
#GIT_TAG v1.3.1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..
)
set(POLARIS_BUILD_EXAMPLES OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(polaris)

# Now we define an example application that uses the Polaris client library.
# In your own code, you can link any add_executable() or add_library() target
# with polaris_client by calling target_link_libraries() as shown.
add_executable(example_app main.cc)
target_link_libraries(example_app PUBLIC polaris_cpp_client)
16 changes: 16 additions & 0 deletions examples/external_cmake_project/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**************************************************************************/ /**
* @brief Example external cmake project.
*
* Copyright (c) Point One Navigation - All Rights Reserved
******************************************************************************/

#include <point_one/polaris/portability.h>
#include <point_one/polaris/polaris_client.h>

using namespace point_one::polaris;

int main(int argc, const char* argv[]) {
P1_printf("Hello, world!\n");
P1_printf("sizeof(PolarisClient): %zu B\n", sizeof(PolarisClient));
return 0;
}
Loading
Loading