Skip to content

Commit

Permalink
CMake: Use GNUInstallDirs for install destination (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
podsvirov authored Apr 24, 2021
1 parent af60e1f commit 57fc29b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 23 deletions.
48 changes: 26 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
include(FeatureSummary)
include(FindPackageHandleStandardArgs)
include(GNUInstallDirs)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Avoid "Policy CMP0042 is not set" warning on macOS.
Expand Down Expand Up @@ -333,7 +334,7 @@ install(FILES src/s2/_fp_contract_off.h
src/s2/s2wedge_relations.h
src/s2/sequence_lexicon.h
src/s2/value_lexicon.h
DESTINATION include/s2)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2")
install(FILES src/s2/base/casts.h
src/s2/base/commandlineflags.h
src/s2/base/integral_types.h
Expand All @@ -342,11 +343,11 @@ install(FILES src/s2/base/casts.h
src/s2/base/mutex.h
src/s2/base/port.h
src/s2/base/spinlock.h
DESTINATION include/s2/base)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/base")
install(FILES src/s2/strings/ostringstream.h
DESTINATION include/s2/strings)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/strings")
install(FILES src/s2/third_party/absl/algorithm/algorithm.h
DESTINATION include/s2/third_party/absl/algorithm)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/algorithm")
install(FILES src/s2/third_party/absl/base/attributes.h
src/s2/third_party/absl/base/casts.h
src/s2/third_party/absl/base/config.h
Expand All @@ -357,42 +358,42 @@ install(FILES src/s2/third_party/absl/base/attributes.h
src/s2/third_party/absl/base/policy_checks.h
src/s2/third_party/absl/base/port.h
src/s2/third_party/absl/base/thread_annotations.h
DESTINATION include/s2/third_party/absl/base)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/base")
install(FILES src/s2/third_party/absl/base/internal/identity.h
src/s2/third_party/absl/base/internal/inline_variable.h
src/s2/third_party/absl/base/internal/invoke.h
src/s2/third_party/absl/base/internal/throw_delegate.h
src/s2/third_party/absl/base/internal/unaligned_access.h
DESTINATION include/s2/third_party/absl/base/internal)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/base/internal")
install(FILES src/s2/third_party/absl/container/inlined_vector.h
DESTINATION include/s2/third_party/absl/container)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/container")
install(FILES src/s2/third_party/absl/container/internal/compressed_tuple.h
src/s2/third_party/absl/container/internal/container_memory.h
src/s2/third_party/absl/container/internal/layout.h
DESTINATION include/s2/third_party/absl/container/internal)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/container/internal")
install(FILES src/s2/third_party/absl/memory/memory.h
DESTINATION include/s2/third_party/absl/memory)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/memory")
install(FILES src/s2/third_party/absl/meta/type_traits.h
DESTINATION include/s2/third_party/absl/meta)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/meta")
install(FILES src/s2/third_party/absl/numeric/int128.h
src/s2/third_party/absl/numeric/int128_have_intrinsic.inc
src/s2/third_party/absl/numeric/int128_no_intrinsic.inc
DESTINATION include/s2/third_party/absl/numeric)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/numeric")
install(FILES src/s2/third_party/absl/strings/numbers.h
src/s2/third_party/absl/strings/str_cat.h
src/s2/third_party/absl/strings/string_view.h
DESTINATION include/s2/third_party/absl/strings)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/strings")
install(FILES src/s2/third_party/absl/types/span.h
DESTINATION include/s2/third_party/absl/types)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/types")
install(FILES src/s2/third_party/absl/utility/utility.h
DESTINATION include/s2/third_party/absl/utility)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/third_party/absl/utility")
install(FILES src/s2/util/bits/bits.h
DESTINATION include/s2/util/bits)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/bits")
install(FILES src/s2/util/coding/coder.h
src/s2/util/coding/varint.h
DESTINATION include/s2/util/coding)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/coding")
install(FILES src/s2/util/endian/endian.h
DESTINATION include/s2/util/endian)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/endian")
install(FILES src/s2/util/gtl/btree.h
src/s2/util/gtl/btree_container.h
src/s2/util/gtl/btree_map.h
Expand All @@ -403,18 +404,21 @@ install(FILES src/s2/util/gtl/btree.h
src/s2/util/gtl/densehashtable.h
src/s2/util/gtl/hashtable_common.h
src/s2/util/gtl/layout.h
DESTINATION include/s2/util/gtl)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/gtl")
install(FILES src/s2/util/hash/mix.h
DESTINATION include/s2/util/hash)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/hash")
install(FILES src/s2/util/math/mathutil.h
src/s2/util/math/matrix3x3.h
src/s2/util/math/vector.h
src/s2/util/math/vector3_hash.h
DESTINATION include/s2/util/math)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/math")
install(FILES src/s2/util/units/length-units.h
src/s2/util/units/physical-units.h
DESTINATION include/s2/util/units)
install(TARGETS s2 s2testing DESTINATION lib)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/util/units")
install(TARGETS s2 s2testing
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

message("GTEST_ROOT: ${GTEST_ROOT}")
if (GTEST_ROOT)
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,46 @@ cd build
cmake -DGTEST_ROOT=/usr/src/gtest ..
make
make test # If GTEST_ROOT specified above.
sudo make install
```

Enable gflags and glog with `cmake -DWITH_GFLAGS=ON -DWITH_GLOG=ON ...`.

Disable building of shared libraries with `-DBUILD_SHARED_LIBS=OFF`.

## Installing

From `build` subdirectory:

```
make install
```

Prefix it with `sudo` if needed:

```
sudo make install
```

_NOTE_: There is not `uninstall` target but `install_manifest.txt` may be helpfull.

All files will be installed at location specified in `CMAKE_INSTALL_PREFIX` variable.

Several suffix variables used for some file groups:

Variable | Default | Description
-------- | ------- | -----------
`CMAKE_INSTALL_INCLUDEDIR` | `include` | For header files
`CMAKE_INSTALL_BINDIR` | `bin` | For executables and `*.dll` files on `DLL`-based platforms
`CMAKE_INSTALL_LIBDIR` | `lib` | For library files (`*.so`, `*.a`, `*.lib` etc)

If needed set this variables on command line as `cmake` arguments with `-D` prefix or edit from `build` subdirectory:

```
make edit_cache
```

For more info read: [The CMake Cache](https://cmake.org/cmake/help/latest/guide/user-interaction/index.html#the-cmake-cache).

## Python

If you want the Python interface, you will also need:
Expand Down

0 comments on commit 57fc29b

Please sign in to comment.