Skip to content

Commit

Permalink
related to #234 and #235, CMake "improvements"
Browse files Browse the repository at this point in the history
  - moved some options (e.g., PDAL_BUILD_STATIC) to pdal_options.cmake
  - created (really borrowed from PCL) macros for adding libraries and
    executables: PDAL_ADD_LIBRARY, PDAL_ADD_EXECUTABLE
  - library linkage (i.e., PUBLIC/PRIVATE) determined at the top level
    in pdal_options.cmake
  - embedded boost lib name does not need quotes, in fact, we lose the
    correct path on Windows if they're there
  - install commands (mostly) moved inside the PDAL_ADD_* macros
  • Loading branch information
chambbj committed Jan 27, 2014
1 parent 1a37e0a commit 616c785
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 68 deletions.
21 changes: 3 additions & 18 deletions CMakeLists.txt
Expand Up @@ -25,6 +25,8 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH}
# PDAL general settings
#------------------------------------------------------------------------------

include("${PDAL_SOURCE_DIR}/cmake/pdal_options.cmake")
include("${PDAL_SOURCE_DIR}/cmake/pdal_targets.cmake")
include("${PDAL_SOURCE_DIR}/cmake/pdal_utils.cmake")

# the next line is the ONLY place in the entire pdal system where
Expand Down Expand Up @@ -93,8 +95,6 @@ set(ENABLE_CTEST FALSE CACHE BOOL
# General build settings
#------------------------------------------------------------------------------

option(PDAL_BUILD_STATIC "Build PDAL as a static library" OFF)

if(WIN32)
if(MSVC)
option(PDAL_USE_STATIC_RUNTIME "Use the static runtime" OFF)
Expand Down Expand Up @@ -126,20 +126,6 @@ endif()

set(PDAL_BUILD_TYPE ${CMAKE_BUILD_TYPE})

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

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

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

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

link_directories(${PDAL_BINARY_DIR}/${PDAL_LIB_DIR})


#------------------------------------------------------------------------------
# Platform and compiler specific settings
Expand Down Expand Up @@ -269,8 +255,7 @@ else()
mark_as_advanced(FORCE PDALBOOST_LIB_NAME)

if (WIN32)
set(Boost_LIBRARIES "${PDALBOOST_LIB_NAME}.lib")
link_directories("${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
set(Boost_LIBRARIES ${PDALBOOST_LIB_NAME})
else()
# Some Cmake versions are borken here. See
# http://www.cmake.org/Bug/view.php?id=12258#c26851
Expand Down
9 changes: 2 additions & 7 deletions apps/CMakeLists.txt
Expand Up @@ -38,19 +38,14 @@ link_directories(${Boost_LIBRARY_DIRS})

if(PDAL_UTILITY)
list(APPEND PDAL_UTILITIES ${PDAL_UTILITY})
add_executable(${PDAL_UTILITY} pdal.cpp)
target_link_libraries(${PDAL_UTILITY} ${PDAL_LIB_NAME})
PDAL_ADD_EXECUTABLE(${PDAL_UTILITY} pdal.cpp)
target_link_libraries(${PDAL_UTILITY} ${PDAL_LINKAGE} ${PDAL_LIB_NAME})
endif()

#------------------------------------------------------------------------------
# Targets installation
#------------------------------------------------------------------------------

install(TARGETS ${PDAL_UTILITIES}
RUNTIME DESTINATION ${PDAL_BIN_DIR}
LIBRARY DESTINATION ${PDAL_LIB_DIR}
ARCHIVE DESTINATION ${PDAL_LIB_DIR})

if(UNIX)

if(WITH_PKGCONFIG)
Expand Down
69 changes: 69 additions & 0 deletions cmake/pdal_options.cmake
@@ -0,0 +1,69 @@
##########################################################################
# These macros were taken from the Point Cloud Library (pointclouds.org) #
# and have been modified for PDAL. License details follow. #
##########################################################################
# Software License Agreement (BSD License) #
# #
# Point Cloud Library (PCL) - www.pointclouds.org #
# Copyright (c) 2009-2012, Willow Garage, Inc. #
# Copyright (c) 2012-, Open Perception, Inc. #
# Copyright (c) XXX, respective authors. #
# #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions #
# are met: #
# #
# * Redistributions of source code must retain the above copyright #
# notice, this list of conditions and the following disclaimer. #
# * Redistributions in binary form must reproduce the above #
# copyright notice, this list of conditions and the following #
# disclaimer in the documentation and/or other materials provided #
# with the distribution. #
# * Neither the name of the copyright holder(s) nor the names of its #
# contributors may be used to endorse or promote products derived #
# from this software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS #
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, #
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, #
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; #
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
# POSSIBILITY OF SUCH DAMAGE. #
##########################################################################

# Options for building PDAL.

# Build shared libraries by default.
option(PDAL_BUILD_STATIC "Build PDAL as a static library" OFF)
if(NOT PDAL_BUILD_STATIC)
set(PDAL_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
set(PDAL_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(PDAL_LIB_TYPE "SHARED")
# set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_IMPORT_LIBRARY_SUFFIX})
endif(WIN32)
else(NOT PDAL_BUILD_STATIC)
set(PDAL_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
set(PDAL_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(PDAL_LIB_TYPE "STATIC")
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif(NOT PDAL_BUILD_STATIC)
mark_as_advanced(PDAL_BUILD_STATIC)

if (CMAKE_VERSION VERSION_GREATER 2.8.10)
set(PDAL_LINKAGE "PUBLIC;general")
set(BOOST_LINKAGE "LINK_PRIVATE;general")
else()
set(PDAL_LINKAGE "")
set(BOOST_LINKAGE "")
endif()

85 changes: 85 additions & 0 deletions cmake/pdal_targets.cmake
@@ -0,0 +1,85 @@
##########################################################################
# These macros were taken from the Point Cloud Library (pointclouds.org) #
# and have been modified for PDAL. License details follow. #
##########################################################################
# Software License Agreement (BSD License) #
# #
# Point Cloud Library (PCL) - www.pointclouds.org #
# Copyright (c) 2009-2012, Willow Garage, Inc. #
# Copyright (c) 2012-, Open Perception, Inc. #
# Copyright (c) XXX, respective authors. #
# #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions #
# are met: #
# #
# * Redistributions of source code must retain the above copyright #
# notice, this list of conditions and the following disclaimer. #
# * Redistributions in binary form must reproduce the above #
# copyright notice, this list of conditions and the following #
# disclaimer in the documentation and/or other materials provided #
# with the distribution. #
# * Neither the name of the copyright holder(s) nor the names of its #
# contributors may be used to endorse or promote products derived #
# from this software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS #
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, #
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, #
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; #
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
# POSSIBILITY OF SUCH DAMAGE. #
##########################################################################


###############################################################################
# Add a set of include files to install.
# _component The part of PDAL that the install files belong to.
# _subdir The sub-directory for these include files.
# ARGN The include files.
macro(PDAL_ADD_INCLUDES _subdir)
install(FILES ${ARGN} DESTINATION ${PDAL_INCLUDE_DIR}/${_subdir})
endmacro(PDAL_ADD_INCLUDES)


###############################################################################
# Add a library target.
# _name The library name.
# _component The part of PDAL that this library belongs to.
# ARGN The source files for the library.
macro(PDAL_ADD_LIBRARY _name)
add_library(${_name} ${PDAL_LIB_TYPE} ${ARGN})

# must link explicitly against boost.
target_link_libraries(${_name} ${BOOST_LINKAGE} ${Boost_LIBRARIES})

install(TARGETS ${_name}
RUNTIME DESTINATION ${PDAL_BIN_DIR}
LIBRARY DESTINATION ${PDAL_LIB_DIR}
ARCHIVE DESTINATION ${PDAL_LIB_DIR})
endmacro(PDAL_ADD_LIBRARY)


###############################################################################
# Add an executable target.
# _name The executable name.
# _component The part of PDAL that this library belongs to.
# ARGN the source files for the library.
macro(PDAL_ADD_EXECUTABLE _name)
add_executable(${_name} ${ARGN})

# must link explicitly against boost.
target_link_libraries(${_name} ${BOOST_LINKAGE} ${Boost_LIBRARIES})

set(PDAL_EXECUTABLES ${PDAL_EXECUTABLES} ${_name})
install(TARGETS ${_name} RUNTIME DESTINATION ${PDAL_BIN_DIR})
endmacro(PDAL_ADD_EXECUTABLE)

12 changes: 3 additions & 9 deletions cmake/pdal_utils.cmake
Expand Up @@ -39,6 +39,7 @@
# POSSIBILITY OF SUCH DAMAGE. #
##########################################################################


###############################################################################
# Pull the component parts out of the version number.
macro(DISSECT_VERSION)
Expand All @@ -53,6 +54,7 @@ macro(DISSECT_VERSION)
PDAL_CANDIDATE_VERSION "${PDAL_VERSION_STRING}")
endmacro(DISSECT_VERSION)


###############################################################################
# Get the operating system information. Generally, CMake does a good job of
# this. Sometimes, though, it doesn't give enough information. This macro will
Expand All @@ -69,6 +71,7 @@ macro(GET_OS_INFO)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
endmacro(GET_OS_INFO)


###############################################################################
# Set the destination directories for installing stuff.
# Sets PDAL_LIB_DIR. Install libraries here.
Expand All @@ -93,12 +96,3 @@ macro(SET_INSTALL_DIRS)
endif(WIN32)
endmacro(SET_INSTALL_DIRS)

###############################################################################
# Add a set of include files to install.
# _component The part of PDAL that the install files belong to.
# _subdir The sub-directory for these include files.
# ARGN The include files.
macro(PDAL_ADD_INCLUDES _component _subdir)
install(FILES ${ARGN} DESTINATION ${PDAL_INCLUDE_DIR}/${_subdir}
COMPONENT ${_component})
endmacro(PDAL_ADD_INCLUDES)
31 changes: 6 additions & 25 deletions src/CMakeLists.txt
Expand Up @@ -649,26 +649,12 @@ set(PDAL_SOURCES

if(WIN32)
add_definitions("-DPDAL_DLL_EXPORT=1")
if (NOT WITH_STATIC_LASZIP)
add_definitions("-DLASZIP_DLL_IMPORT=1")
endif()
endif()

if (PDAL_BUILD_STATIC)
set(PDAL_LIB_TYPE STATIC)
else()
set(PDAL_LIB_TYPE SHARED)
if (NOT WITH_STATIC_LASZIP)
add_definitions("-DLASZIP_DLL_IMPORT=1")
endif()
endif()


add_library(${PDAL_LIB_NAME} ${PDAL_LIB_TYPE} ${PDAL_SOURCES})
if (CMAKE_VERSION VERSION_GREATER 2.8.10)
set(PDAL_LINKAGE "PUBLIC;general")
set(BOOST_LINKAGE "LINK_PRIVATE;general")
else()
set(PDAL_LINKAGE "")
set(BOOST_LINKAGE "")
endif()
PDAL_ADD_LIBRARY(${PDAL_LIB_NAME} ${PDAL_SOURCES})

set (SQLITE_LIBRARIES ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN} ${SQLITE3_LIBRARY})

Expand Down Expand Up @@ -697,11 +683,11 @@ endif()
endif()

if (WITH_LASZIP)
target_link_libraries(${PDAL_LIB_NAME} ${PDAL_LINKAGE} "${LASZIP_LIBRARY}")
target_link_libraries(${PDAL_LIB_NAME} ${PDAL_LINKAGE} "${LASZIP_LIBRARY}")
endif()

if (WITH_PYTHON)
target_link_libraries(${PDAL_LIB_NAME} ${PDAL_LINKAGE} "${PYTHON_LIBRARY}")
target_link_libraries(${PDAL_LIB_NAME} ${PDAL_LINKAGE} "${PYTHON_LIBRARY}")
endif()

target_link_libraries(${PDAL_LIB_NAME} ${PDAL_LINKAGE}
Expand Down Expand Up @@ -806,11 +792,6 @@ endif()
###############################################################################
# Targets installation

install(TARGETS ${PDAL_LIB_NAME} ${PDAL_C_LIB_NAME}
RUNTIME DESTINATION ${PDAL_BIN_DIR}
LIBRARY DESTINATION ${PDAL_LIB_DIR}
ARCHIVE DESTINATION ${PDAL_LIB_DIR})

install(DIRECTORY "${PDAL_HEADERS_DIR}/"
DESTINATION "${PDAL_INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
10 changes: 1 addition & 9 deletions test/unit/CMakeLists.txt
Expand Up @@ -168,7 +168,7 @@ INCLUDE_DIRECTORIES(
${GEOTIFF_INCLUDE_DIR}
${ORACLE_INCLUDE_DIR})

ADD_EXECUTABLE(${PDAL_UNIT_TEST} ${PDAL_UNITTEST_SOURCES})
PDAL_ADD_EXECUTABLE(${PDAL_UNIT_TEST} ${PDAL_UNITTEST_SOURCES})

set_target_properties(${PDAL_UNIT_TEST} PROPERTIES COMPILE_DEFINITIONS PDAL_DLL_IMPORT)

Expand All @@ -190,14 +190,6 @@ else()
endif()
endif()

if (CMAKE_VERSION VERSION_GREATER 2.8.10)
set(PDAL_LINKAGE "PUBLIC;general")
set(BOOST_LINKAGE "PRIVATE;general")
else()
set(PDAL_LINKAGE "")
set(BOOST_LINKAGE "")
endif()

TARGET_LINK_LIBRARIES( ${PDAL_UNIT_TEST} ${PDAL_LINKAGE}
${PDAL_LIB_NAME} )

Expand Down

0 comments on commit 616c785

Please sign in to comment.