Skip to content

Commit

Permalink
Modernize CMake configuration (#240)
Browse files Browse the repository at this point in the history
* Modernize CMake configuration

* Use GNUInstallDirs
* Remove old CMake cruft
* Set minimum CMake version to 3.13

* more testing

* set CMAKE_CURRENT_BINARY_DIR for PATH

* test jiggering

* more test execution stuff

* add bin path for gtest_main

* typo

* alternative sub

* execute tests in binary bin

* drop conda

* put conda bacK

* bin fiddling

* win32 path

* SHELL_PATH

* swing some more

* try another path

* lint

* more linting

* just install it

* src

* output locations

* test locations
  • Loading branch information
hobu committed May 6, 2024
1 parent e8ca373 commit 2d2c944
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 180 deletions.
170 changes: 14 additions & 156 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,31 @@
#
# (based originally on the PDAL and libLAS files copyright Mateusz Loskot)

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.13)

#------------------------------------------------------------------------------
# libspatialindex general settings
#------------------------------------------------------------------------------

set(SIDX_VERSION_MAJOR "1")
set(SIDX_VERSION_MINOR "9")
set(SIDX_VERSION_PATCH "3")
set(SIDX_VERSION_MAJOR "2")
set(SIDX_VERSION_MINOR "0")
set(SIDX_VERSION_PATCH "0")
set(SIDX_VERSION_STRING
"${SIDX_VERSION_MAJOR}.${SIDX_VERSION_MINOR}.${SIDX_VERSION_PATCH}")
set(SIDX_LIB_VERSION "6.1.1")
set(SIDX_LIB_SOVERSION "6")

# disable incremental linker
set(MSVC_INCREMENTAL_DEFAULT NO)
set(SIDX_LIB_VERSION "7.0.0")
set(SIDX_LIB_SOVERSION "7")

project(spatialindex
VERSION ${SIDX_VERSION_STRING}
LANGUAGES CXX
)

include(GNUInstallDirs)

message(STATUS
"Configuring CMake ${CMAKE_VERSION} to build spatialindex ${PROJECT_VERSION}")

#------------------------------------------------------------------------------
# internal cmake settings
#------------------------------------------------------------------------------

# Allow advanced users to generate Makefiles printing detailed commands
mark_as_advanced(CMAKE_VERBOSE_MAKEFILE)

# Only interpret if() arguments as variables or keywords when unquoted
cmake_policy(SET CMP0054 NEW)

if(WIN32 AND NOT CMAKE_VERSION VERSION_LESS "3.15")
# MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default
cmake_policy(SET CMP0092 NEW)
endif()

if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()

#------------------------------------------------------------------------------
# libspatialindex general cmake options
#------------------------------------------------------------------------------

include(CTest)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_TESTING "Enables integrated test suites" OFF)

Expand Down Expand Up @@ -94,125 +71,6 @@ check_function_exists(bcopy HAVE_BCOPY)

include(CheckIncludeFiles)


#------------------------------------------------------------------------------
# General build settings
#------------------------------------------------------------------------------

# note we default to RelWithDebInfo mode
if(NOT MSVC_IDE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: \
None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
message(STATUS
"Setting libspatialindex build type - ${CMAKE_BUILD_TYPE}")
endif()

set(SIDX_BUILD_TYPE ${CMAKE_BUILD_TYPE})

# TODO: Still testing the output paths --mloskot
set(SIDX_BUILD_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")

# Output directory in which to build RUNTIME target files.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SIDX_BUILD_OUTPUT_DIRECTORY})

# Output directory in which to build LIBRARY target files
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SIDX_BUILD_OUTPUT_DIRECTORY})

# Output directory in which to build ARCHIVE target files.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SIDX_BUILD_OUTPUT_DIRECTORY})


#------------------------------------------------------------------------------
# Platform and compiler specific settings
#------------------------------------------------------------------------------

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Recommended C++ compilation flags
set(SIDX_COMMON_CXX_FLAGS
-pedantic
-Wall
-Wpointer-arith
-Wcast-align
-Wcast-qual
-Wredundant-decls
-Wno-long-long
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if(WIN32)
set(SIDX_COMMON_CXX_FLAGS
/Wall
/Qdiag-disable:2203 # cast discards qualifiers from target type
)
else()
set(SIDX_COMMON_CXX_FLAGS
-Wall
-Wpointer-arith
-diag-disable=2203 # cast discards qualifiers from target type
)
endif()
endif()

if(APPLE)
set(SO_EXT dylib)
set(CMAKE_FIND_FRAMEWORK "LAST")
elseif(WIN32)
set(SO_EXT dll)
else()
set(SO_EXT so)
endif()


#------------------------------------------------------------------------------
# installation path settings
#------------------------------------------------------------------------------

if(WIN32)
set(DEFAULT_LIB_SUBDIR lib)
set(DEFAULT_DATA_SUBDIR .)
set(DEFAULT_INCLUDE_SUBDIR include)

if(MSVC)
set(DEFAULT_BIN_SUBDIR bin)
else()
set(DEFAULT_BIN_SUBDIR .)
endif()
else()
# Common locations for Unix and Mac OS X
set(DEFAULT_BIN_SUBDIR bin)
set(DEFAULT_LIB_SUBDIR lib${LIB_SUFFIX})
set(DEFAULT_DATA_SUBDIR share/spatialindex)
set(DEFAULT_INCLUDE_SUBDIR include)
endif()

# Locations are changeable by user to customize layout of SIDX installation
# (default values are platform-specific)
set(SIDX_BIN_SUBDIR ${DEFAULT_BIN_SUBDIR} CACHE STRING
"Subdirectory where executables will be installed")
set(SIDX_LIB_SUBDIR ${DEFAULT_LIB_SUBDIR} CACHE STRING
"Subdirectory where libraries will be installed")
set(SIDX_INCLUDE_SUBDIR ${DEFAULT_INCLUDE_SUBDIR} CACHE STRING
"Subdirectory where header files will be installed")
set(SIDX_DATA_SUBDIR ${DEFAULT_DATA_SUBDIR} CACHE STRING
"Subdirectory where data will be installed")

# Mark *_SUBDIR variables as advanced and dedicated to use by power-users only.
mark_as_advanced(SIDX_BIN_SUBDIR
SIDX_LIB_SUBDIR SIDX_INCLUDE_SUBDIR SIDX_DATA_SUBDIR)

# Full paths for the installation
set(SIDX_BIN_DIR ${SIDX_BIN_SUBDIR})
set(SIDX_LIB_DIR ${SIDX_LIB_SUBDIR})
set(SIDX_INCLUDE_DIR ${SIDX_INCLUDE_SUBDIR})
set(SIDX_DATA_DIR ${SIDX_DATA_SUBDIR})

#------------------------------------------------------------------------------
# subdirectory controls
#------------------------------------------------------------------------------

add_subdirectory(src)

if(BUILD_TESTING)
Expand All @@ -225,13 +83,13 @@ endif()

include(CMakePackageConfigHelpers)

set(INCLUDE_INSTALL_DIR ${SIDX_INCLUDE_DIR} CACHE PATH "include directory")
set(LIB_INSTALL_DIR ${SIDX_LIB_DIR} CACHE PATH "lib directory")
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "include directory")
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "lib directory")

configure_package_config_file(
libspatialindexConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libspatialindexConfig.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/libspatialindex
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libspatialindex
PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)

write_basic_package_version_file(
Expand All @@ -242,7 +100,7 @@ write_basic_package_version_file(
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libspatialindexConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/libspatialindexConfigVersion.cmake
DESTINATION ${LIB_INSTALL_DIR}/cmake/libspatialindex)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libspatialindex)

#------------------------------------------------------------------------------
# pkg-config support
Expand All @@ -255,7 +113,7 @@ if(NOT WIN32)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libspatialindex.pc
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ci/compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

ninja
ninja install
7 changes: 6 additions & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/bash

ctest -V
ls `pwd`/bin
ls `pwd`/test
ls `pwd`/test/gtest
env

ctest -VV --rerun-failed --output-on-failure
42 changes: 29 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ target_compile_options(spatialindex
target_compile_options(spatialindex_c
PRIVATE ${SIDX_COMMON_CXX_FLAGS})

set_target_properties( spatialindex PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin)

set_target_properties( spatialindex_c PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin)


if(MSVC)
target_compile_options(spatialindex PRIVATE /wd4068)
target_compile_options(spatialindex_c PRIVATE /wd4068)
Expand Down Expand Up @@ -239,45 +248,52 @@ if(HAVE_BCOPY)
endif()



if(APPLE)
set_target_properties(spatialindex spatialindex_c PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
)
set(MACOSX_RPATH ON)
set_target_properties(spatialindex spatialindex_c
PROPERTIES INSTALL_NAME_DIR "@rpath")
endif()

###############################################################################
# Targets installation

install(TARGETS spatialindex spatialindex_c
EXPORT libspatialindexTargets
RUNTIME DESTINATION ${SIDX_BIN_DIR}
LIBRARY DESTINATION ${SIDX_LIB_DIR}
ARCHIVE DESTINATION ${SIDX_LIB_DIR})
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

export(
TARGETS
spatialindex spatialindex_c
NAMESPACE
libspatialindex::
FILE
"${SIDX_LIB_DIR}/libspatialindexTargets.cmake")
"${CMAKE_INSTALL_LIBDIR}/libspatialindexTargets.cmake")

install(
EXPORT
libspatialindexTargets
DESTINATION
"${SIDX_LIB_DIR}/cmake/libspatialindex")
"${CMAKE_INSTALL_LIBDIR}/cmake/libspatialindex")

target_include_directories(spatialindex_c
INTERFACE
$<INSTALL_INTERFACE:include>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(spatialindex
INTERFACE
$<INSTALL_INTERFACE:include>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(DIRECTORY ${SIDX_HEADERS_DIR}
DESTINATION include/spatialindex
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/spatialindex"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PERMISSIONS
GROUP_EXECUTE WORLD_EXECUTE OWNER_EXECUTE
GROUP_READ WORLD_READ OWNER_READ
OWNER_WRITE

)


19 changes: 14 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(SOURCES

foreach(test ${SOURCES})
add_executable(test-${DIR}-${test} ${DIR}/${test}.cc)
target_link_libraries(test-${DIR}-${test} spatialindex)
target_link_libraries(test-${DIR}-${test} PRIVATE spatialindex)
endforeach()

set(DIR rtree)
Expand All @@ -21,7 +21,7 @@ set(SOURCES

foreach(test ${SOURCES})
add_executable(test-${DIR}-${test} ${DIR}/${test}.cc)
target_link_libraries(test-${DIR}-${test} spatialindex)
target_link_libraries(test-${DIR}-${test} PRIVATE spatialindex)
endforeach()

set(DIR mvrtree)
Expand All @@ -35,7 +35,7 @@ set(SOURCES

foreach(test ${SOURCES})
add_executable(test-${DIR}-${test} ${DIR}/${test}.cc)
target_link_libraries(test-${DIR}-${test} spatialindex)
target_link_libraries(test-${DIR}-${test} PRIVATE spatialindex)
endforeach()

set(DIR tools)
Expand All @@ -46,7 +46,7 @@ set(SOURCES

foreach(test ${SOURCES})
add_executable(test-${DIR}-${test} ${DIR}/${test}.cc)
target_link_libraries(test-${DIR}-${test} spatialindex)
target_link_libraries(test-${DIR}-${test} PRIVATE spatialindex)
endforeach()

set(DIR tprtree)
Expand All @@ -61,7 +61,16 @@ set(SOURCES
foreach(test ${SOURCES})
add_executable(test-${DIR}-${test}
${DIR}/${test}.cc ${DIR}/RandomGenerator.cc)
target_link_libraries(test-${DIR}-${test} spatialindex)
target_link_libraries(test-${DIR}-${test} PRIVATE spatialindex)

endforeach()

if (UNIX)
find_program (BASH_PROGRAM bash)
add_test(NAME index-tests
COMMAND ${BASH_PROGRAM} "${CMAKE_CURRENT_SOURCE_DIR}/index-tests.sh"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_property(TEST index-tests PROPERTY ENVIRONMENT
"PATH=${CMAKE_BINARY_DIR}/test/:$ENV{PATH}")
endif (UNIX)
add_subdirectory(gtest)
11 changes: 7 additions & 4 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ set(SOURCES

set(TESTNAME libsidxtest)
add_executable(${TESTNAME} ${SOURCES})
target_link_libraries(${TESTNAME} spatialindex_c gtest)
target_link_libraries(${TESTNAME} PRIVATE spatialindex_c gtest )

add_test(${TESTNAME}
"${PROJECT_BINARY_DIR}/bin/${TESTNAME}"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/..")
add_test(NAME ${TESTNAME}
COMMAND "${CMAKE_BINARY_DIR}/bin/${TESTNAME}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

set_target_properties( ${TESTNAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin)

0 comments on commit 2d2c944

Please sign in to comment.