Skip to content

Commit

Permalink
cmake: export library and use targets
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Jul 4, 2021
1 parent 6d17ff1 commit 92a72b2
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 359 deletions.
34 changes: 30 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,36 @@ set(POTHOS_ROOT_ENV "POTHOS_ROOT" CACHE STRING
set(APPDATA_ENV "APPDATA" CACHE STRING
"Environment variable for Pothos::System::getUserDataPath()")

# Include the Pothos library config into the top level.
# This brings in LIB_SUFFIX and RPATH settings for submodules.
include(${PROJECT_SOURCE_DIR}/cmake/Modules/PothosLibraryConfig.cmake)

include(FeatureSummary)
include(CMakeDependentOption)

########################################################################
# rpath setup - http://www.cmake.org/Wiki/CMake_RPATH_handling
########################################################################
# use, i.e. don't skip the full RPATH for the build tree
option(CMAKE_SKIP_BUILD_RPATH "skip rpath build" FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
option(CMAKE_BUILD_WITH_INSTALL_RPATH "build with install rpath" FALSE)

# the RPATH to be used when installing, but only if it's not a system directory
option(CMAKE_AUTOSET_INSTALL_RPATH TRUE)
if(CMAKE_AUTOSET_INSTALL_RPATH)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")
endif(CMAKE_AUTOSET_INSTALL_RPATH)

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "build with automatic rpath" TRUE)

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

########################################################################
# POCO C++ utility libraries
########################################################################
Expand Down Expand Up @@ -198,6 +221,9 @@ endif()
cmake_dependent_option(ENABLE_LIBRARY "Enable Pothos Library component" ON "TRUE" OFF)
add_feature_info(Library ENABLE_LIBRARY "The main library for all Pothos projects")

#C++11 is a required language feature for this project
set(CMAKE_CXX_STANDARD 11)

if(ENABLE_LIBRARY)
find_package(Pothos CONFIG REQUIRED)
add_subdirectory(include)
Expand Down
37 changes: 18 additions & 19 deletions cmake/Modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ endif()
########################################################################
# Install cmake helper modules
########################################################################
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/PothosConfigVersion.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/PothosConfigVersion.cmake
@ONLY)
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${PROJECT_BINARY_DIR}/PothosConfigVersion.cmake
VERSION ${POTHOS_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES
${PROJECT_SOURCE_DIR}/cmake/Modules/PothosConfig.cmake
${PROJECT_SOURCE_DIR}/cmake/Modules/PothosUtil.cmake
${PROJECT_BINARY_DIR}/PothosConfigVersion.cmake
#poco support
${PROJECT_SOURCE_DIR}/cmake/Modules/FindPkgMacros.cmake
${PROJECT_SOURCE_DIR}/cmake/Modules/FindPoco.cmake
${PROJECT_SOURCE_DIR}/cmake/Modules/SetupPoco.cmake
#SIMD
${PROJECT_SOURCE_DIR}/cmake/Modules/PothosConfigSIMD.cmake

install(
FILES
PothosConfig.cmake
PothosStandardFlags.cmake
PothosLibraryConfig.cmake
PothosUtil.cmake
${CMAKE_CURRENT_BINARY_DIR}/PothosConfigVersion.cmake
#poco support
FindPkgMacros.cmake
FindPoco.cmake
SetupPoco.cmake
#SIMD
PothosConfigSIMD.cmake
DESTINATION ${POTHOS_CMAKE_DIRECTORY}
COMPONENT pothos_devel
)
COMPONENT pothos_devel)
89 changes: 28 additions & 61 deletions cmake/Modules/PothosConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,8 @@ set(INCLUDED_POTHOS_CONFIG_CMAKE TRUE)
# POTHOS_CMAKE_DIRECTORY - where to install CMake files
########################################################################
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR})
include(PothosStandardFlags) #compiler settings
include(PothosLibraryConfig) #library settings
include(PothosUtil) #utility functions

########################################################################
## locate the Poco development libraries
########################################################################
enable_language(C) #newer Poco config scrips require c to be enabled
include(SetupPoco)

if (Poco_FOUND)

message(STATUS "Poco_VERSION: ${Poco_VERSION}")
message(STATUS "Poco_INCLUDE_DIRS: ${Poco_INCLUDE_DIRS}")
message(STATUS "Poco_LIBRARIES: ${Poco_LIBRARIES}")

list(APPEND Pothos_LIBRARIES ${Poco_LIBRARIES})

if (Poco_INCLUDE_DIRS)
list(APPEND Pothos_INCLUDE_DIRS ${Poco_INCLUDE_DIRS})
endif (Poco_INCLUDE_DIRS)

else (Poco_FOUND)
message(WARNING "Pothos projects require Poco libraries...")
endif (Poco_FOUND)

########################################################################
# install directory for cmake files
########################################################################
if (UNIX)
set(POTHOS_CMAKE_DIRECTORY ${CMAKE_INSTALL_DATADIR}/cmake/Pothos)
elseif (WIN32)
set(POTHOS_CMAKE_DIRECTORY cmake)
endif ()

########################################################################
# select the release build type by default to get optimization flags
########################################################################
Expand All @@ -56,6 +23,14 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")

########################################################################
# Use GNU Install Dirs, but support LIB_SUFFIX if specified
########################################################################
include(GNUInstallDirs)
if(LIB_SUFFIX)
set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}") #support old lib suffix
endif(LIB_SUFFIX)

########################################################################
# extract the ABI version string from the Version.hpp header
########################################################################
Expand All @@ -68,6 +43,16 @@ function(_POTHOS_GET_ABI_VERSION VERSION INCLUDE_DIR)
set(${VERSION} "${CMAKE_MATCH_1}" CACHE INTERNAL "")
endfunction(_POTHOS_GET_ABI_VERSION)

########################################################################
# install directory for cmake files
# used publicly in PothosPython
########################################################################
if (UNIX)
set(POTHOS_CMAKE_DIRECTORY ${CMAKE_INSTALL_DATADIR}/cmake/Pothos)
elseif (WIN32)
set(POTHOS_CMAKE_DIRECTORY cmake)
endif ()

########################################################################
## in-tree build support
########################################################################
Expand All @@ -77,8 +62,6 @@ if (POTHOS_IN_TREE_SOURCE_DIR)
set(POTHOS_ROOT ${CMAKE_INSTALL_PREFIX})
endif(NOT POTHOS_ROOT)

list(INSERT Pothos_LIBRARIES 0 Pothos)
list(INSERT Pothos_INCLUDE_DIRS 0 ${POTHOS_IN_TREE_SOURCE_DIR}/include)
_POTHOS_GET_ABI_VERSION(POTHOS_ABI_VERSION ${POTHOS_IN_TREE_SOURCE_DIR}/include)

#a list of in-tree built libraries to generate a library path script
Expand Down Expand Up @@ -128,9 +111,9 @@ if (POTHOS_IN_TREE_SOURCE_DIR)
set(__POTHOS_UTIL_TARGET_NAME ${PROJECT_NAME}PothosUtil)
add_custom_target(${__POTHOS_UTIL_TARGET_NAME} DEPENDS ${POTHOS_UTIL_EXE})

#ensure that local headers get precedent over installed headers
include_directories(${POTHOS_IN_TREE_SOURCE_DIR}/include)

#set old-style variables
unset(Pothos_INCLUDE_DIRS)
set(Pothos_LIBRARIES Pothos)
return()
endif ()

Expand Down Expand Up @@ -190,29 +173,13 @@ if(NOT __result_code STREQUAL __success_code)
endif()

########################################################################
## locate the Pothos library
## create import library target
########################################################################
find_library(
POTHOS_LIBRARY Pothos Pothosd
PATHS ${POTHOS_ROOT}/${CMAKE_INSTALL_LIBDIR}
PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE}
NO_DEFAULT_PATH
)
if(NOT POTHOS_LIBRARY)
message(FATAL_ERROR "cannot find Pothos library in ${POTHOS_ROOT}/${CMAKE_INSTALL_LIBDIR}")
endif()
list(INSERT Pothos_LIBRARIES 0 ${POTHOS_LIBRARY})
include(PothosExport)
include(SetupPoco)

########################################################################
## locate the Pothos includes
########################################################################
find_path(
POTHOS_INCLUDE_DIR Pothos/Config.hpp
PATHS ${POTHOS_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}
NO_DEFAULT_PATH
)
if(NOT POTHOS_INCLUDE_DIR)
message(FATAL_ERROR "cannot find Pothos includes in ${POTHOS_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
list(INSERT Pothos_INCLUDE_DIRS 0 ${POTHOS_INCLUDE_DIR})
#set old-style variables
get_target_property(POTHOS_INCLUDE_DIR Pothos INTERFACE_INCLUDE_DIRECTORIES)
set(Pothos_INCLUDE_DIRS ${POTHOS_INCLUDE_DIR})
set(Pothos_LIBRARIES Pothos)
_POTHOS_GET_ABI_VERSION(POTHOS_ABI_VERSION ${POTHOS_INCLUDE_DIR})
39 changes: 0 additions & 39 deletions cmake/Modules/PothosLibraryConfig.cmake

This file was deleted.

75 changes: 0 additions & 75 deletions cmake/Modules/PothosStandardFlags.cmake

This file was deleted.

19 changes: 8 additions & 11 deletions cmake/Modules/PothosUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,24 @@ function(POTHOS_MODULE_UTIL)
endif(GIT_FOUND)
endif()

#setup module build and install rules
add_library(${POTHOS_MODULE_UTIL_TARGET} MODULE ${POTHOS_MODULE_UTIL_SOURCES})
target_link_libraries(${POTHOS_MODULE_UTIL_TARGET} PRIVATE Pothos ${POTHOS_MODULE_UTIL_LIBRARIES})
set_target_properties(${POTHOS_MODULE_UTIL_TARGET} PROPERTIES DEBUG_POSTFIX "") #same name in debug mode

#version specified, build into source file
if (POTHOS_MODULE_UTIL_VERSION)
message(STATUS "Module ${POTHOS_MODULE_UTIL_TARGET} configured with version: ${POTHOS_MODULE_UTIL_VERSION}")
set(version_file "${CMAKE_CURRENT_BINARY_DIR}/Version.cpp")
file(WRITE "${version_file}" "#include <Pothos/Plugin/Module.hpp>
static const Pothos::ModuleVersion register${MODULE_TARGET}Version(\"${POTHOS_MODULE_UTIL_VERSION}\");
")
list(APPEND POTHOS_MODULE_UTIL_SOURCES "${version_file}")
target_sources(${POTHOS_MODULE_UTIL_TARGET} PRIVATE "${version_file}")
endif()

#always enable docs if user specifies doc sources
if (POTHOS_MODULE_UTIL_DOC_SOURCES)
set(POTHOS_MODULE_UTIL_ENABLE_DOCS TRUE)
#otherwise doc sources come from the regular sources
else()
set(POTHOS_MODULE_UTIL_DOC_SOURCES ${POTHOS_MODULE_UTIL_SOURCES})
endif()

#setup json doc file generation and install
Expand All @@ -138,7 +140,8 @@ function(POTHOS_MODULE_UTIL)
DEPENDS ${POTHOS_MODULE_UTIL_DOC_SOURCES}
DEPENDS ${__POTHOS_UTIL_TARGET_NAME}
)
list(APPEND POTHOS_MODULE_UTIL_SOURCES ${cpp_doc_file})
target_sources(${POTHOS_MODULE_UTIL_TARGET} PRIVATE ${cpp_doc_file})
set_property(SOURCE ${cpp_doc_file} PROPERTY SKIP_AUTOMOC ON)
endif()

set(MODULE_DESTINATION ${CMAKE_INSTALL_LIBDIR}/Pothos/modules${POTHOS_ABI_VERSION}/${POTHOS_MODULE_UTIL_DESTINATION})
Expand All @@ -148,12 +151,6 @@ function(POTHOS_MODULE_UTIL)
set(MODULE_DESTINATION ${POTHOS_MODULE_UTIL_PREFIX}/${MODULE_DESTINATION})
endif()

#setup module build and install rules
include_directories(${Pothos_INCLUDE_DIRS})
add_library(${POTHOS_MODULE_UTIL_TARGET} MODULE ${POTHOS_MODULE_UTIL_SOURCES})
target_link_libraries(${POTHOS_MODULE_UTIL_TARGET} PRIVATE ${Pothos_LIBRARIES} ${POTHOS_MODULE_UTIL_LIBRARIES})
set_target_properties(${POTHOS_MODULE_UTIL_TARGET} PROPERTIES DEBUG_POSTFIX "") #same name in debug mode

if(CMAKE_COMPILER_IS_GNUCXX)
#force a compile-time error when symbols are missing
#otherwise modules will cause a runtime error on load
Expand Down
Loading

0 comments on commit 92a72b2

Please sign in to comment.