Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 100 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,111 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4)
PROJECT(SGP4)
cmake_minimum_required(VERSION 3.16...4.0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bumped this slightly. 3.16 is maximum supported by Ubuntu 20.04 and 3.18 for Debian 11.

Further bump to 3.23 would give us file sets

See: https://repology.org/project/cmake/versions


if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
project(SGP4
VERSION 1.1.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose 1.1.0, because there already is a v1.0 git tag.

DESCRIPTION "Simplified perturbations models"
HOMEPAGE_URL https://github.com/dnwrnr/sgp4
LANGUAGES CXX
)

set(MAIN_PROJECT OFF)
# determine if SGP4 is built as a subproject (using add_subdirectory)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(BUILD_SHARED_LIBS "Build SGP4 as a shared library." ON)

include(CTest)
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
option(SGP4_BUILD_SHARED_LIBS "Build sgp4 target as SHARED instead of STATIC." ${BUILD_SHARED_LIBS})
option(SGP4_BUILD_STATIC_LIBS "Build sgp4-static target along with sgp4." ${MAIN_PROJECT})
option(SGP4_INSTALL "Install CMake targets during install step." ${MAIN_PROJECT})
option(SGP4_BUILD_TESTS "Enable SGP4 tests." ${MAIN_PROJECT})
option(SGP4_BUILD_EXAMPLES "Enable SGP4 examples." ${MAIN_PROJECT})
option(SGP4_ENABLE_PIC "Enable position-independent code (ignored for sgp4 target when SGP4_BUILD_SHARED_LIBS is enabled)." ON)

if(SGP4_BUILD_STATIC_LIBS AND NOT SGP4_BUILD_SHARED_LIBS)
message(WARNING "SGP4_BUILD_STATIC_LIBS only makes sense if BUILD_SHARED_LIBS is set to ON.")
message(WARNING "You might be building and installing two identical static libraries.")
message(WARNING "NOTE: to override BUILD_SHARED_LIBS for SGP4 only, you may use SGP4_BUILD_SHARED_LIBS.")
endif()

set(CMAKE_INSTALL_LIBDIR "/lib64")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT DEFINED SGP4_DEFAULT_TARGET_NAME)
# Allow overriding the target name when using FetchContent / add_subdirectory.
set(SGP4_DEFAULT_TARGET_NAME sgp4)
endif()
if(NOT DEFINED SGP4_STATIC_TARGET_NAME)
# Allow overriding the target name when using FetchContent / add_subdirectory.
set(SGP4_STATIC_TARGET_NAME sgp4-static)
endif()

set(SGP4_NAMESPACE_NAME libsgp4)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(src)

if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
endif(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(SGP4_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(SGP4_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

include_directories(libsgp4)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

add_subdirectory(libsgp4)
add_subdirectory(sattrack)
add_subdirectory(runtest)
add_subdirectory(passpredict)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
)

file(COPY SGP4-VER.TLE DESTINATION ${PROJECT_BINARY_DIR})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)

if(SGP4_INSTALL)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig"
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
)

install(TARGETS ${SGP4_DEFAULT_TARGET_NAME}
EXPORT "${PROJECT_NAME}Targets"
INCLUDES DESTINATION ${CMAKE_INSTALL_DATADIR}
# .so on UNIX
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# .dll on Windows
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# .lib on Windows
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

if(SGP4_BUILD_STATIC_LIBS)
install(TARGETS ${SGP4_STATIC_TARGET_NAME}
EXPORT "${PROJECT_NAME}Targets"
INCLUDES DESTINATION ${CMAKE_INSTALL_DATADIR}
# .lib on Windows, .a on UNIX
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

install(EXPORT "${PROJECT_NAME}Targets" NAMESPACE ${SGP4_NAMESPACE_NAME}:: DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}")

install(DIRECTORY "include/" TYPE INCLUDE)
endif()
92 changes: 88 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,92 @@
SGP4 library
============
# SGP4 library
## CMake support
### External
```cmake
# ./CMakeLists.txt

License
-------
find_package(SGP4 1.1 CONFIG REQUIRED)
# ...
add_library(foo ...)
# ...
target_link_libraries(foo PRIVATE libsgp4::sgp4)
# target_link_libraries(foo PRIVATE libsgp4::sgp4-static) # or static
```

### Embedded
```cmake
# ./CMakeLists.txt

# this affects if the libsgp4::sgp4 target is shared or static
set(SGP4_BUILD_SHARED_LIBS ON)
# this affects if the libsgp4::sgp4-static target is available
set(SGP4_BUILD_STATIC_LIBS ON)

add_subdirectory(thirdparty/sgp4)
# ...
add_library(foo ...)
# ...
target_link_libraries(foo PRIVATE libsgp4::sgp4)
# target_link_libraries(foo PRIVATE libsgp4::sgp4-static) # or static
```

### Embedded (FetchContent)
```cmake
# ./CMakeLists.txt

include(FetchContent)

# this affects if the libsgp4::sgp4 target is shared or static
set(SGP4_BUILD_SHARED_LIBS ON)
# this affects if the libsgp4::sgp4-static target is available
set(SGP4_BUILD_STATIC_LIBS ON)

FetchContent_Declare(sgp4
GIT_REPOSITORY https://github.com/dnwrnr/sgp4
# TODO: update this with an actual commit
GIT_TAG bdff20d3eb6f010af95574990a662f8089db93f8 # https://github.com/dnwrnr/sgp4/tree/bdff20d3eb6f010af95574990a662f8089db93f8
)
FetchContent_MakeAvailable(sgp4)
# ...
add_library(foo ...)
# ...
target_link_libraries(foo PRIVATE libsgp4::sgp4)
# target_link_libraries(foo PRIVATE libsgp4::sgp4-static) # or static
```

### External with embedded fallback
```cmake
# ./CMakeLists.txt

# this affects if the libsgp4::sgp4 fallback target is shared or static
set(SGP4_BUILD_SHARED_LIBS ON)
# this affects if the libsgp4::sgp4-static fallback target is available
set(SGP4_BUILD_STATIC_LIBS ON)

# use include instead of add_subdirectory, otherwise targets won't get propagated
include(thirdparty/CMakeLists.txt)
add_subdirectory(src)
```

```cmake
# ./src/CMakeLists.txt

add_library(foo ...)
# ...
target_link_libraries(foo PRIVATE libsgp4::sgp4)
# target_link_libraries(foo PRIVATE libsgp4::sgp4-static) # or static
```

```cmake
# ./thirdparty/CMakeLists.txt

find_package(SGP4 1.1 CONFIG)
if(NOT SGP4_FOUND)
message(STATUS "Using SGP4 submodule")
add_subdirectory("${CMAKE_SOURCE_DIR}/thirdparty/sgp4")
endif()
```

## License

Copyright 2017 Daniel Warner

Expand Down
8 changes: 8 additions & 0 deletions cmake/SGP4Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following variables are defined:
# - SGP4_IS_DEFAULT_TARGET_SHARED - whether sgp4 target is SHARED or not
# - SGP4_STATIC_LIBS_BUILT - whether we have built sgp4-static target

set(SGP4_IS_DEFAULT_TARGET_SHARED @SGP4_BUILD_SHARED_LIBS@)
set(SGP4_STATIC_LIBS_BUILT @SGP4_BUILD_STATIC_LIBS@)

include("${CMAKE_CURRENT_LIST_DIR}/SGP4Targets.cmake")
11 changes: 11 additions & 0 deletions cmake/pkg-config.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -l@SGP4_DEFAULT_TARGET_NAME@
Cflags: -I${includedir}
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(passpredict)
add_subdirectory(sattrack)
20 changes: 20 additions & 0 deletions examples/passpredict/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(SOURCE_LIST passpredict.cpp)

add_executable(passpredict ${SOURCE_LIST})

set_target_properties(passpredict PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

target_compile_features(passpredict PRIVATE cxx_std_17)
target_compile_options(passpredict PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall;-Wextra;-Wshadow;-Wnon-virtual-dtor;-pedantic;-Wno-long-long;-Wcast-align;-Wsign-conversion>
)
target_link_libraries(passpredict PRIVATE libsgp4::sgp4)

if(WIN32 AND SGP4_BUILD_SHARED_LIBS)
# copy sgp4 dll into the examples/passpredict directory
add_custom_command(TARGET passpredict POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:libsgp4::sgp4>" "$<TARGET_FILE_DIR:passpredict>")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/


#include <Observer.h>
#include <SGP4.h>
#include <Util.h>
#include <CoordTopocentric.h>
#include <CoordGeodetic.h>
#include <SGP4/Observer.h>
#include <SGP4/SGP4.h>
#include <SGP4/Util.h>
#include <SGP4/CoordTopocentric.h>
#include <SGP4/CoordGeodetic.h>

#include <cmath>
#include <iostream>
Expand Down
20 changes: 20 additions & 0 deletions examples/sattrack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(SOURCE_LIST sattrack.cpp)

add_executable(sattrack ${SOURCE_LIST})

set_target_properties(sattrack PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

target_compile_features(sattrack PRIVATE cxx_std_17)
target_compile_options(sattrack PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall;-Wextra;-Wshadow;-Wnon-virtual-dtor;-pedantic;-Wno-long-long;-Wcast-align;-Wsign-conversion>
)
target_link_libraries(sattrack PRIVATE libsgp4::sgp4)

if(WIN32 AND SGP4_BUILD_SHARED_LIBS)
# copy sgp4 dll into the examples/sattrack directory
add_custom_command(TARGET sattrack POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:libsgp4::sgp4>" "$<TARGET_FILE_DIR:sattrack>")
endif()
8 changes: 4 additions & 4 deletions sattrack/sattrack.cc → examples/sattrack/sattrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/


#include <CoordTopocentric.h>
#include <CoordGeodetic.h>
#include <Observer.h>
#include <SGP4.h>
#include <SGP4/CoordTopocentric.h>
#include <SGP4/CoordGeodetic.h>
#include <SGP4/Observer.h>
#include <SGP4/SGP4.h>

#include <iostream>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 0 additions & 41 deletions libsgp4/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion libsgp4/DecayedException.cc

This file was deleted.

1 change: 0 additions & 1 deletion libsgp4/SatelliteException.cc

This file was deleted.

1 change: 0 additions & 1 deletion libsgp4/TleException.cc

This file was deleted.

7 changes: 0 additions & 7 deletions passpredict/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions runtest/CMakeLists.txt

This file was deleted.

Loading