Skip to content

Commit

Permalink
Cmake install step (#308)
Browse files Browse the repository at this point in the history
* Extend targets to support file sets

* Move core library to header file sets

* Move application library to header file sets

* Move gfx platform library to header file sets

* Move gfx api libraries to header file sets

* Add local install folder to ignored folders

* Remove unused files and make cpu visible

* Ensure cmake helpers support interface targets fully

* Defer executable creation to standardised target

* Ensure morpheus config is exported

* Specify the package info for Conan

* Ensure install is relocatable

* Correct export sources and remove cmake install files

* Package metal and direct x targets for Conan

* Update newly added files

* Clear up

* Ensure exported interface target

* Further libraries requiring exporting

* Clean up old target

* Seperate build and install interface for gfx dependne ies
  • Loading branch information
Twon authored Jul 1, 2024
1 parent 2a1beb5 commit e378aa1
Show file tree
Hide file tree
Showing 53 changed files with 375 additions and 330 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.vscode
.venv
[Bb]uild*
Install*
cmake-build-debug
env/*
[Oo]ut
Expand Down
12 changes: 7 additions & 5 deletions cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER I
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]

include(morpheus_add_library)
include(warnings)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
morpheus_add_library(
NAME MorpheusConfig
ALIAS morpheus::config
FOLDER "Libraries/Core"
INTERFACE
)

add_library(MorpheusConfig INTERFACE)
add_library(morpheus::config ALIAS MorpheusConfig)
target_link_libraries(MorpheusConfig
INTERFACE
$<$<PLATFORM_ID:Linux>:dl>
Expand Down
8 changes: 6 additions & 2 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ function(enable_code_coverage)
set(LCOV_HTML_PATH "${COVERAGE_REPORT_DIR}/html")

if (NOT TARGET CodeCoverage)
add_library(CodeCoverage INTERFACE)
add_library(coverage::coverage ALIAS CodeCoverage)

morpheus_add_library(
NAME CodeCoverage
ALIAS coverage::coverage
INTERFACE
)

foreach (FLAGS ${COVERAGE_SUPPORTED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${FLAGS}")
Expand Down
26 changes: 5 additions & 21 deletions cmake/morpheus_add_executable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,12 @@ function(morpheus_add_executable)
if (NOT MORPHEUS_NAME)
message(FATAL_ERROR "NAME parameter must be supplied")
endif()
add_executable(${MORPHEUS_NAME})
if (MORPHEUS_ALIAS)
add_executable(${MORPHEUS_ALIAS} ALIAS ${MORPHEUS_NAME})
endif()

set_target_properties(${MORPHEUS_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
morpheus_add_target(
TYPE executable
NAME ${MORPHEUS_NAME}
ALIAS ${MORPHEUS_ALIAS}
FOLDER ${MORPHEUS_FOLDER}
)

if (MORPHEUS_FOLDER)
set_target_properties(${MORPHEUS_NAME}
PROPERTIES
FOLDER ${MORPHEUS_FOLDER}
)
endif()

install(TARGETS ${MORPHEUS_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endfunction()
16 changes: 15 additions & 1 deletion cmake/morpheus_add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ and allows configuration for common optional settings
``FOLDER``
The ``FOLDER`` option provides a folder location for the target within an IDE.
``INTERFACE``
The ``INTERFACE`` option is only applicable for library targets and specifies
the library is an interface library.
#]=======================================================================]
function(morpheus_add_library)
set(options)
set(options INTERFACE)
set(oneValueArgs NAME ALIAS FOLDER)
set(multiValueArgs)
cmake_parse_arguments(MORPHEUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Expand All @@ -60,12 +64,22 @@ function(morpheus_add_library)
if (NOT MORPHEUS_ALIAS)
message(FATAL_ERROR "ALIAS parameter must be supplied")
endif()
if(${MORPHEUS_INTERFACE})
set(isInterface "INTERFACE")
endif()

morpheus_add_target(
TYPE library
NAME ${MORPHEUS_NAME}
ALIAS ${MORPHEUS_ALIAS}
FOLDER ${MORPHEUS_FOLDER}
${isInterface}
)

install(
EXPORT morpheus-export-set
NAMESPACE morpheus::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/morpheus"
)

endfunction()
30 changes: 24 additions & 6 deletions cmake/morpheus_add_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,26 @@ function(morpheus_add_target)
if (NOT MORPHEUS_INTERFACE AND NOT MORPHEUS_TYPE STREQUAL library)
message(FATAL_ERROR "INTERFACE parameter can only be used with library targets")
endif()
if(${MORPHEUS_INTERFACE})
set(isInterface "INTERFACE")
endif()

if (MORPHEUS_TYPE STREQUAL executable)
add_executable(${MORPHEUS_NAME})
if (MORPHEUS_ALIAS)
add_executable(${MORPHEUS_ALIAS} ALIAS ${MORPHEUS_NAME})
endif()
else()
if (NOT MORPHEUS_INFERFACE)
add_library(${MORPHEUS_NAME})
else()
add_library(${MORPHEUS_NAME} INTERFACE)
endif()
add_library(${MORPHEUS_NAME} ${isInterface})
add_library(${MORPHEUS_ALIAS} ALIAS ${MORPHEUS_NAME})
endif()

morpheus_add_target_properties(
NAME ${MORPHEUS_NAME}
FOLDER ${MORPHEUS_FOLDER}
${isInterface}
)

endfunction()

#[=======================================================================[.rst:
Expand Down Expand Up @@ -127,13 +128,24 @@ commonly associated attributes.
#]=======================================================================]
function(morpheus_add_target_properties)
set(options)
set(options INTERFACE)
set(oneValueArgs NAME FOLDER)
set(multiValueArgs)
cmake_parse_arguments(MORPHEUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(${MORPHEUS_INTERFACE})
set(scope "INTERFACE")
else()
set(scope "PUBLIC")
endif()

target_compile_features(${MORPHEUS_NAME} ${scope} cxx_std_23)

set_target_properties(${MORPHEUS_NAME}
PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
Expand All @@ -146,7 +158,13 @@ function(morpheus_add_target_properties)
)
endif()

# Create an empty header set here so that the subsequent install step finds it.
target_sources(${MORPHEUS_NAME} ${scope} FILE_SET HEADERS FILES)

install(TARGETS ${MORPHEUS_NAME}
EXPORT morpheus-export-set
FILE_SET HEADERS
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
72 changes: 55 additions & 17 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps, CMakeToolchain
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy
from conan.tools.scm import Version
from conan.tools.files import copy, rm
from conan.tools.scm import Git, Version
from conan.tools.files import load
from conan.tools.system.package_manager import Apt
import re, os.path
Expand Down Expand Up @@ -76,7 +76,6 @@ class Morpheus(ConanFile):
"with_rs_opengl": True,
"with_rs_vulkan": True
}
exports_sources = ["CMakeLists.txt", "LICENSE", "version.txt", "cmake/*", "examples/*" "libraries/*"]
requires = (
"boost/1.85.0",
"ctre/3.8.1",
Expand Down Expand Up @@ -180,10 +179,6 @@ def system_requirements(self):
apt = Apt(self)
apt.install(["libgl-dev", "libopengl-dev", "libglu1-mesa-dev"], update=True, check=True)

# @property
# def _source_subfolder(self):
# return "source_subfolder"

@property
def _minimum_cpp_standard(self):
return 20
Expand Down Expand Up @@ -234,19 +229,62 @@ def generate(self):
def layout(self):
cmake_layout(self)

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "LICENSE", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "version.txt", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "cmake/*", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "examples/*", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "libraries/*", src=self.recipe_folder, dst=self.export_sources_folder)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "*LICENSE*", dst="licenses", keep_path=False)
copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.configure()
cmake.install()

# def package_id(self):
# self.info.header_only()
rm(self, "*export-set*.cmake", os.path.join(self.package_folder, "lib", "cmake", "morpheus"))

def package_info(self):
pass
#self.cpp_info.names["cmake_find_package"] = "wg21_linear_algebra"
#self.cpp_info.names["cmake_find_package_multi"] = "wg21_linear_algebra"
#self.cpp_info.components["_wg21_linear_algebra"].names["cmake_find_package"] = "wg21_linear_algebra"
#self.cpp_info.components["_wg21_linear_algebra"].names["cmake_find_package_multi"] = "wg21_linear_algebra"
#self.cpp_info.components["_wg21_linear_algebra"].requires = ["mdspan::mdspan"]
self.cpp_info.components["core"].set_property("cmake_file_name", "MorpheusCore")
self.cpp_info.components["core"].set_property("cmake_target_name", "morpheus::core")
self.cpp_info.components["core"].defines = ["BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_NTDDI_WIN10"]
self.cpp_info.components["core"].requires = ["boost::headers", "boost::log", "ctre::ctre", "magic_enum::magic_enum", "ms-gsl::ms-gsl", "range-v3::range-v3", "rapidjson::rapidjson", "scnlib::scnlib"]
self.cpp_info.components["core"].builddirs.append(os.path.join("lib", "cmake", "morpheus"))

if self.useDate:
self.cpp_info.components["core"].requires.append("date::date")
self.cpp_info.components["core"].requires.append("date::date-tz")

if self.useExpected:
self.cpp_info.components["core"].requires.append("tl-expected::expected")

if self.useFMT:
self.cpp_info.components["core"].requires.append("fmt::fmt")

if self.options.get_safe("with_rs_direct_x12", False):
self.cpp_info.components["directx12"].set_property("cmake_file_name", "MorpheusGfxDirectX12")
self.cpp_info.components["directx12"].set_property("cmake_target_name", "morpheus::gfx::directx12")

if self.options.get_safe("with_rs_metal", False):
self.cpp_info.components["metal"].set_property("cmake_file_name", "MorpheusGfxMetal")
self.cpp_info.components["metal"].set_property("cmake_target_name", "morpheus::gfx::metal")

if self.options.get_safe("with_rs_opengl", False):
self.cpp_info.components["opengl"].set_property("cmake_file_name", "MorpheusGfxVulkan")
self.cpp_info.components["opengl"].set_property("cmake_target_name", "morpheus::gfx::vulkan")
self.cpp_info.components["opengl"].requires.append("glbinding::glbinding")
self.cpp_info.components["opengl"].requires.append("glew::glew")

if self.options.get_safe("with_rs_vulkan", False):
self.cpp_info.components["vulkan"].set_property("cmake_file_name", "MorpheusGfxVulkan")
self.cpp_info.components["vulkan"].set_property("cmake_target_name", "morpheus::gfx::vulkan")
self.cpp_info.components["vulkan"].requires.append("vulkan-headers::vulkan-headers")

if (self.settings.os in ["Macos", "iOS", "tvOS"]):
self.cpp_info.components["vulkan"].requires.append("moltenvk::moltenvk")

9 changes: 1 addition & 8 deletions libraries/application/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ morpheus_add_library(

target_include_directories(MorpheusApplication
PUBLIC
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

#target_include_directories(MorpheusApplication
# PUBLIC
# $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
#)

target_link_libraries(MorpheusApplication
PUBLIC
morpheus::core
Expand Down
8 changes: 5 additions & 3 deletions libraries/application/src/morpheus/application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
target_sources(MorpheusApplication
PUBLIC
application.hpp
try_catch.hpp
version.hpp
FILE_SET HEADERS
FILES
application.hpp
try_catch.hpp
version.hpp
PRIVATE
application.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
target_sources(MorpheusApplication
PUBLIC
config.hpp
options.hpp
FILE_SET HEADERS
FILES
config.hpp
options.hpp
PRIVATE
config.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ add_subdirectory(std)

target_sources(MorpheusApplication
PUBLIC
enums.hpp
FILE_SET HEADERS
FILES
enums.hpp
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
target_sources(MorpheusApplication
PUBLIC
asio.hpp
log.hpp
FILE_SET HEADERS
FILES
asio.hpp
log.hpp
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
target_sources(MorpheusApplication
PUBLIC
chrono.hpp
filesystem.hpp
optional.hpp
FILE_SET HEADERS
FILES
chrono.hpp
filesystem.hpp
optional.hpp
)
12 changes: 1 addition & 11 deletions libraries/core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ morpheus_add_library(

target_include_directories(MorpheusCore
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
Expand Down Expand Up @@ -47,16 +47,6 @@ install(TARGETS MorpheusCore
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/core
)

# Hierarchically copy headers to the install dir
install (
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/morpheus/core
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/morpheus/core
FILES_MATCHING PATTERN
"*.hpp"
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/morpheus/core/morpheuscore_export.h
Expand Down
Loading

0 comments on commit e378aa1

Please sign in to comment.