Skip to content

Commit

Permalink
better cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed Sep 21, 2024
1 parent d878f70 commit 3290618
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
65 changes: 53 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.11)

project(
Geodesy
Expand All @@ -9,20 +9,61 @@ project(
# We need Eigen
find_package(Eigen3 3.3 REQUIRED)

# The library
add_subdirectory(src)

# The tests
include(CTest)
add_subdirectory(test//unit_tests)
add_subdirectory(test/unit_tests)
enable_testing()

add_compile_options(
-Wall -Wextra -Werror -pedantic -W -Wshadow -march=native -DEIGEN_NO_AUTOMATIC_RESIZING
$<$<CONFIG:RELEASE>:-O2 -march=native -DEIGEN_NO_AUTOMATIC_RESIZING>
$<$<CONFIG:DEBUG>:-g -pg -Wdisabled-optimization -DDEBUG>
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
add_compile_options(-Wall
-Wextra
-Werror
-pedantic
-W
-Wshadow
$<$<CONFIG:Release>:-O2>
$<$<CONFIG:Release>:-march=native>
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-pg>
$<$<CONFIG:Debug>:-Wdisabled-optimization>
)
add_compile_definitions(
$<$<CONFIG:Debug>:DEBUG>
)

add_library(geodesy)
target_include_directories(geodesy PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/geodesy>
)

add_subdirectory(src)

# Install headers at: $PREFIX/datetime/...
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include/geodesy
)

# install library
install(TARGETS geodesy
EXPORT geodesyTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(EXPORT geodesyTargets
FILE geodesyTargets.cmake
NAMESPACE dso::
DESTINATION lib/cmake/geodesy
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"geodesyConfigVersion.cmake"
VERSION ${geodesy_version}
COMPATIBILITY AnyNewerVersion
)
install(FILES "geodesyConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/geodesyConfigVersion.cmake"
DESTINATION lib/cmake/dso
)
3 changes: 3 additions & 0 deletions geodesyConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(CMakeFindDependencyMacro)
# find_dependency(xxx 2.0)
include(${CMAKE_CURRENT_LIST_DIR}/geodesyTargets.cmake)
28 changes: 3 additions & 25 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
add_library(geodesy)

target_sources(geodesy
PRIVATE
cartesian_to_spherical.cpp
geodetic_to_lvlh.cpp
spherical_to_cartesian.cpp
${CMAKE_SOURCE_DIR}/src/cartesian_to_spherical.cpp
${CMAKE_SOURCE_DIR}/src/geodetic_to_lvlh.cpp
${CMAKE_SOURCE_DIR}/src/spherical_to_cartesian.cpp
)

target_include_directories(geodesy
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../include/core
)

# We need the Eigen-3 library
target_link_libraries(geodesy PRIVATE Eigen3::Eigen)

# Install headers at: $PREFIX/geodesy/...
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../include/
DESTINATION include/geodesy
)

# install library
install(TARGETS geodesy
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

0 comments on commit 3290618

Please sign in to comment.