Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 240 additions & 236 deletions CMakeLists.txt

Large diffs are not rendered by default.

155 changes: 25 additions & 130 deletions cmake/BITPITConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,112 +1,9 @@
# BITPITConfig.cmake - bitpit CMake configuration file for external projects.
# -----------
#
# This file is configured by bitpit and used by the UseBITPIT.cmake module
# to load bitpit's settings for an external project.

# Compute the installation prefix from this BITPITConfig.cmake file location.
@BITPIT_INSTALL_PREFIX_CODE@

# If a different UseBITPIT.cmake was previoulsy loaded a reconfiguration
# is needed
if(NOT ("${BITPIT_INSTALL_PREFIX}/@BITPIT_INSTALL_CMAKEDIR@" STREQUAL BITPIT_INSTALL_CMAKEDIR_PREVIOUS))
set(BITPIT_RECONFIGURE 1)
set(BITPIT_INSTALL_CMAKEDIR_PREVIOUS "${BITPIT_INSTALL_PREFIX}/@BITPIT_INSTALL_CMAKEDIR@" CACHE INTERNAL "Defines the previous bitpit CMake configuration file loaded")
endif()

# The C and C++ flags added by bitpit to the cmake-configured flags.
SET(BITPIT_REQUIRED_C_FLAGS "")
SET(BITPIT_REQUIRED_CXX_FLAGS "")
SET(BITPIT_REQUIRED_EXE_LINKER_FLAGS "")
SET(BITPIT_REQUIRED_SHARED_LINKER_FLAGS "")
SET(BITPIT_REQUIRED_MODULE_LINKER_FLAGS "")

# The bitpit version number
SET(BITPIT_MAJOR_VERSION "@BITPIT_MAJOR_VERSION@")
SET(BITPIT_MINOR_VERSION "@BITPIT_MINOR_VERSION@")
SET(BITPIT_PATCH_VERSION "@BITPIT_PATCH_VERSION@")
SET(BITPIT_VERSION "@BITPIT_VERSION@")

# The location of the UseBITPIT.cmake file.
SET(BITPIT_CMAKE_DIR "${BITPIT_INSTALL_PREFIX}/@BITPIT_INSTALL_CMAKEDIR@")
SET(BITPIT_USE_FILE "${BITPIT_CMAKE_DIR}/UseBITPIT.cmake")

# Flag for shared build
SET(BITPIT_SHARED "@BUILD_SHARED_LIBS@")

# Include macros for finding packages
list(APPEND CMAKE_MODULE_PATH ${BITPIT_CMAKE_DIR})
include(LibFindMacros)
include(FindPackageHandleStandardArgs)
@PACKAGE_INIT@

#-----------------------------------------------------------------------------
# Find bitpit libraries and headers
# Modules
#-----------------------------------------------------------------------------

# Headers
if(BITPIT_RECONFIGURE)
unset(BITPIT_INCLUDE_DIR CACHE)
endif()

find_path(BITPIT_INCLUDE_DIR "@PROJECT_NAME@.hpp"
HINTS "${BITPIT_INSTALL_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@/")

mark_as_advanced(BITPIT_INCLUDE_DIR)

# Library
if(BITPIT_RECONFIGURE)
unset(BITPIT_LIBRARY_RELEASE CACHE)
unset(BITPIT_LIBRARY_DEBUG CACHE)
endif()

find_library(BITPIT_LIBRARY_RELEASE
NAMES @PROJECT_NAME@@BITPIT_RELEASE_POSTFIX@ @PROJECT_NAME@
HINTS "${BITPIT_INSTALL_PREFIX}/@CMAKE_INSTALL_LIBDIR@")

find_library(BITPIT_LIBRARY_DEBUG
NAMES @PROJECT_NAME@@BITPIT_DEBUG_POSTFIX@ @PROJECT_NAME@
HINTS "${BITPIT_INSTALL_PREFIX}/@CMAKE_INSTALL_LIBDIR@")

mark_as_advanced(BITPIT_LIBRARY_RELEASE)
mark_as_advanced(BITPIT_LIBRARY_DEBUG)

# Choose good values for BITPIT_LIBRARY, BITPIT_LIBRARIES,
# BITPIT_LIBRARY_DEBUG, and BITPIT_LIBRARY_RELEASE depending on what
# has been found and set. If only BITPIT_LIBRARY_RELEASE is defined,
# BITPIT_LIBRARY will be set to the release value, and
# BITPIT_LIBRARY_DEBUG will be set to BITPIT_LIBRARY_DEBUG-NOTFOUND.
# If only BITPIT_LIBRARY_DEBUG is defined, then BITPIT_LIBRARY will
# take the debug value, and BITPIT_LIBRARY_RELEASE will be set to
# BITPIT_LIBRARY_RELEASE-NOTFOUND.
#
# If the generator supports configuration types, then BITPIT_LIBRARY
# and BITPIT_LIBRARIES will be set with debug and optimized flags
# specifying the library to be used for the given configuration. If no
# build type has been set or the generator in use does not support
# configuration types, then BITPIT_LIBRARY and BITPIT_LIBRARIES will
# take only the release value, or the debug value if the release one is
# not set.
if (BITPIT_LIBRARY_DEBUG AND BITPIT_LIBRARY_RELEASE AND
NOT BITPIT_LIBRARY_DEBUG STREQUAL BITPIT_LIBRARY_RELEASE AND
(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE))
set( BITPIT_LIBRARY "" )
foreach( _libname IN LISTS BITPIT_LIBRARY_RELEASE )
list( APPEND BITPIT_LIBRARY optimized "${_libname}" )
endforeach()
foreach( _libname IN LISTS BITPIT_LIBRARY_DEBUG )
list( APPEND BITPIT_LIBRARY debug "${_libname}" )
endforeach()
elseif (BITPIT_LIBRARY_RELEASE)
set (BITPIT_LIBRARY ${BITPIT_LIBRARY_RELEASE})
elseif (BITPIT_LIBRARY_DEBUG)
set (BITPIT_LIBRARY ${BITPIT_LIBRARY_DEBUG})
else ()
set( BITPIT_LIBRARY "BITPIT_LIBRARY-NOTFOUND")
endif ()

# bitpit Definitions
set(BITPIT_DEFINITIONS "@BITPIT_INTERFACE_COMPILE_DEFINITIONS@")

# List of currently enabled bitpit modules
set(BITPIT_ENABLED_MODULE_LIST "@BITPIT_ENABLED_MODULE_LIST@")

Expand Down Expand Up @@ -143,18 +40,24 @@ if(BITPIT_FIND_OPTIONAL_COMPONENTS)
endforeach()
endif()

# Unset the unneeded variables
if(BITPIT_RECONFIGURE)
unset(BITPIT_RECONFIGURE)
endif()
#-----------------------------------------------------------------------------
# Location of UseBITPIT.cmake file.
#-----------------------------------------------------------------------------

SET(BITPIT_USE_FILE "@CMAKE_INSTALL_PREFIX@/@BITPIT_INSTALL_CMAKEDIR@/UseBITPIT.cmake")

#-----------------------------------------------------------------------------
# Programming languages
#-----------------------------------------------------------------------------

# Let libfind_process initialize the appropriate variables
libfind_process(BITPIT)
set(BITPIT_LANGUAGES "@BITPIT_LANGUAGES@")

#-----------------------------------------------------------------------------
# Find bitpit external dependencies
#-----------------------------------------------------------------------------

list(APPEND CMAKE_MODULE_PATH "@CMAKE_INSTALL_PREFIX@/@BITPIT_INSTALL_CMAKEDIR@")

# Set external dependencies information
set(_EXTERNAL_DEPENDENCIES "@BITPIT_EXTERNAL_DEPENDENCIES@")
set(_EXTERNAL_VARIABLES_LIBRARIES "@BITPIT_EXTERNAL_VARIABLES_LIBRARIES@")
Expand Down Expand Up @@ -199,29 +102,21 @@ foreach (VARIABLE_NAME IN LISTS _EXTERNAL_VARIABLES_INCLUDE_DIRS)
endforeach ()

#-----------------------------------------------------------------------------
# Set programming languages
# Include targets
#-----------------------------------------------------------------------------
set(BITPIT_LANGUAGES "@BITPIT_LANGUAGES@")
include ( "${CMAKE_CURRENT_LIST_DIR}/@BITPIT_CMAKE_TARGETS_FILE@" )

#-----------------------------------------------------------------------------
# Create imported target
# Backwards compatibility
#-----------------------------------------------------------------------------
if(BITPIT_SHARED)
set(LIBRARY_TYPE SHARED)
else()
set(LIBRARY_TYPE STATIC)
endif()

if(NOT TARGET bitpit::bitpit)
add_library(bitpit::bitpit ${LIBRARY_TYPE} IMPORTED GLOBAL)
# Definitions
get_target_property(BITPIT_DEFINITIONS @BITPIT_LIBRARY@::@BITPIT_LIBRARY@ INTERFACE_COMPILE_DEFINITIONS)

set_target_properties(bitpit::bitpit
PROPERTIES
IMPORTED_LOCATION "${BITPIT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${BITPIT_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${BITPIT_DEFINITIONS}")
# Include directories
get_target_property(BITPIT_INCLUDE_DIRS @BITPIT_LIBRARY@::@BITPIT_LIBRARY@ INTERFACE_INCLUDE_DIRECTORIES)

# The property INTERFACE_LINK_LIBRARIES is set using target_link_libraries so that the debug
# and optimized keywords work.
target_link_libraries(bitpit::bitpit INTERFACE ${BITPIT_LIBRARIES})
endif()
# Include libraries
get_target_property(BITPIT_LIBRARY @BITPIT_LIBRARY@::@BITPIT_LIBRARY@ LOCATION)
get_target_property(BITPIT_LINK_LIBRARIES @BITPIT_LIBRARY@::@BITPIT_LIBRARY@ INTERFACE_LINK_LIBRARIES)
set(BITPIT_LIBRARIES "${BITPIT_LINK_LIBRARIES};${BITPIT_LIBRARY}")
47 changes: 0 additions & 47 deletions cmake/BITPITConfigVersion.cmake.in

This file was deleted.

86 changes: 47 additions & 39 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,23 @@
#
#---------------------------------------------------------------------------*/

include(CMakePackageConfigHelpers)

string(TOUPPER ${BITPIT_LIBRARY} UPPER_BITPIT_LIBRARY_NAME)

#------------------------------------------------------------------------------------#
# Generate BITPITConfig.cmake
# CMake configuration file
#------------------------------------------------------------------------------------#
set(BITPIT_INSTALL_PREFIX_CODE
"set(_bitpit_installed_prefix \"${CMAKE_INSTALL_PREFIX}/${BITPIT_INSTALL_CMAKEDIR}\")
set(_bitpit_requested_prefix \"\${CMAKE_CURRENT_LIST_DIR}\")
get_filename_component(_bitpit_installed_prefix_full \"\${_bitpit_installed_prefix}\" REALPATH)
get_filename_component(_bitpit_requested_prefix_full \"\${_bitpit_requested_prefix}\" REALPATH)
if (_bitpit_installed_prefix_full STREQUAL _bitpit_requested_prefix_full)
set(BITPIT_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")
else ()
set(BITPIT_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_DIR}\")")

# Construct the proper number of get_filename_component(... PATH)
# calls to compute the installation prefix.
string(REGEX REPLACE "/" ";" _count "${BITPIT_INSTALL_CMAKEDIR}")
foreach(p ${_count})
set(BITPIT_INSTALL_PREFIX_CODE "${BITPIT_INSTALL_PREFIX_CODE}
get_filename_component(BITPIT_INSTALL_PREFIX \"\${BITPIT_INSTALL_PREFIX}\" PATH)")
endforeach()

set(BITPIT_INSTALL_PREFIX_CODE "${BITPIT_INSTALL_PREFIX_CODE}
endif ()")
set (BITPIT_CMAKE_TARGETS_FILE "${UPPER_BITPIT_LIBRARY_NAME}Targets.cmake")

get_target_property(BITPIT_DEBUG_POSTFIX ${BITPIT_LIBRARY} DEBUG_POSTFIX)
get_target_property(BITPIT_RELEASE_POSTFIX ${BITPIT_LIBRARY} RELEASE_POSTFIX)
get_target_property(BITPIT_INTERFACE_COMPILE_DEFINITIONS ${BITPIT_LIBRARY} INTERFACE_COMPILE_DEFINITIONS)
install(TARGETS ${BITPIT_LIBRARY} EXPORT ${BITPIT_LIBRARY}Targets)

install(EXPORT ${BITPIT_LIBRARY}Targets
FILE ${BITPIT_CMAKE_TARGETS_FILE}
NAMESPACE ${BITPIT_LIBRARY}::
DESTINATION ${BITPIT_INSTALL_CMAKEDIR}
)

set(BITPIT_ENABLED_MODULE_LIST "")
foreach(MODULE_NAME IN LISTS BITPIT_MODULE_LIST)
Expand All @@ -58,32 +48,50 @@ foreach(MODULE_NAME IN LISTS BITPIT_MODULE_LIST)
endif()
endforeach()

configure_file("BITPITConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/BITPITConfig.cmake" @ONLY)
set (BITPIT_CMAKE_PACKAGE_FILE "${UPPER_BITPIT_LIBRARY_NAME}Config.cmake")
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${BITPIT_CMAKE_PACKAGE_FILE}.in
"${CMAKE_CURRENT_BINARY_DIR}/${BITPIT_CMAKE_PACKAGE_FILE}"
INSTALL_DESTINATION "${BITPIT_INSTALL_CMAKEDIR}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

unset(BITPIT_ENABLED_MODULE_LIST)
unset(BITPIT_INTERFACE_COMPILE_DEFINITIONS)
unset(BITPIT_RELEASE_POSTFIX)
unset(BITPIT_DEBUG_POSTFIX)
unset(BITPIT_INSTALL_PREFIX_CODE)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${BITPIT_CMAKE_PACKAGE_FILE}
DESTINATION "${BITPIT_INSTALL_CMAKEDIR}"
)

#------------------------------------------------------------------------------------#
# Generate BITPITConfigVersion.cmake.in
# CMake version file
#------------------------------------------------------------------------------------#

get_target_property(BITPIT_INTERFACE_COMPILE_DEFINITIONS ${BITPIT_LIBRARY} INTERFACE_COMPILE_DEFINITIONS)
set (BITPIT_CMAKE_CONFIG_VERSION_FILE "${UPPER_BITPIT_LIBRARY_NAME}ConfigVersion.cmake")
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${BITPIT_CMAKE_CONFIG_VERSION_FILE}
VERSION ${BITPIT_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_file("BITPITConfigVersion.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/BITPITConfigVersion.cmake" @ONLY)

unset(BITPIT_INTERFACE_COMPILE_DEFINITIONS)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${BITPIT_CMAKE_CONFIG_VERSION_FILE}
DESTINATION "${BITPIT_INSTALL_CMAKEDIR}"
)

#------------------------------------------------------------------------------------#
# CMake targets
# CMake find package file
#------------------------------------------------------------------------------------#
add_custom_target(clean-cmake COMMAND ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/BITPITConfig.cmake" DESTINATION "${BITPIT_INSTALL_CMAKEDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/BITPITConfigVersion.cmake" DESTINATION "${BITPIT_INSTALL_CMAKEDIR}")

install(FILES "FindBITPIT.cmake" DESTINATION "${BITPIT_INSTALL_CMAKEDIR}")

#------------------------------------------------------------------------------------#
# CMake use package file
#------------------------------------------------------------------------------------#

install(FILES "UseBITPIT.cmake" DESTINATION "${BITPIT_INSTALL_CMAKEDIR}")
install(FILES "LibFindMacros.cmake" DESTINATION "${BITPIT_INSTALL_CMAKEDIR}")

#------------------------------------------------------------------------------------#
# CMake targets
#------------------------------------------------------------------------------------#
add_custom_target(clean-cmake COMMAND ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
3 changes: 3 additions & 0 deletions cmake/FindBITPIT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
# Assume not found.
set(BITPIT_FOUND 0)

# Warn that the usage of this file is deprecated.
message(WARNING "FindBITPIT.cmake is deprecated and should not be used in new projects.")

# Use the Config mode of the find_package() command to find BITPITConfig.
# If this succeeds (possibly because BITPIT_DIR is already set), the
# command will have already loaded BITPITConfig.cmake and set BITPIT_FOUND.
Expand Down
Loading