Skip to content

Commit

Permalink
Changes to better support shared building and installation
Browse files Browse the repository at this point in the history
(cherry picked from commit 1e6e3ed)
  • Loading branch information
louis-langholtz committed Feb 24, 2023
1 parent ad9f252 commit 3b8b108
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 127 deletions.
11 changes: 11 additions & 0 deletions Benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ mark_as_advanced(FORCE BENCHMARK_ENABLE_EXCEPTIONS)
mark_as_advanced(FORCE BENCHMARK_ENABLE_INSTALL)
mark_as_advanced(FORCE BENCHMARK_ENABLE_TESTING)
mark_as_advanced(FORCE BENCHMARK_ENABLE_LTO)
mark_as_advanced(FORCE BENCHMARK_ENABLE_DOXYGEN)
mark_as_advanced(FORCE BENCHMARK_USE_LIBCXX)
mark_as_advanced(FORCE BENCHMARK_INSTALL_DOCS)

set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library.")
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Enable installation of the benchmark library.")
set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "Enable installation of docs.")

# Add subdirectory to build.
# For cmd details, see: https://cmake.org/cmake/help/v3.1/command/add_subdirectory.html
Expand Down Expand Up @@ -40,3 +44,10 @@ if(${PLAYRHO_ENABLE_COVERAGE})
target_link_libraries(Benchmark -fprofile-arcs -ftest-coverage)
endif()
endif()

if(PLAYRHO_INSTALL)
include(GNUInstallDirs)
install(TARGETS Benchmark
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications)
endif()
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ endforeach()

# Set name for entire project. This establishes the project name in <PROJECT_NAME>_* variables.
# Details at: https://cmake.org/cmake/help/latest/command/project.html#command:project
project(PlayRho VERSION 1.1.1)
project(PlayRho
VERSION 1.1.1
DESCRIPTION "Real-time oriented physics engine and library that's currently best suited for 2D games."
HOMEPAGE_URL "https://louis-langholtz.github.io/PlayRho/"
)
# Now PlayRho_VERSION set to version above.
# PlayRho_VERSION_MAJOR set to first component.
# PlayRho_VERSION_MINOR set to second component.
Expand Down Expand Up @@ -65,10 +69,13 @@ else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()

string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)

# Provide options that user can optionally select.
# Include the install rules if the user wanted them (included by default when top-level)
# Details at: https://cmake.org/cmake/help/v3.1/command/option.html
option(PLAYRHO_BUILD_STATIC "Build PlayRho static libraries." ON)
option(PLAYRHO_BUILD_SHARED "Build PlayRho shared libraries." OFF)
option(PLAYRHO_BUILD_SHARED "Build PlayRho as shared library." "${BUILD_SHARED_LIBS}")
option(PLAYRHO_INSTALL "Enable installation of PlayRho libs, includes, and CMake scripts." "${is_top_level}")
option(PLAYRHO_INSTALL_DOC "Enable installation of PlayRho documentation." OFF)
option(PLAYRHO_BUILD_HELLOWORLD "Build PlayRho HelloWorld console application." OFF)
option(PLAYRHO_BUILD_UNIT_TESTS "Build PlayRho Unit Tests console application." OFF)
Expand Down Expand Up @@ -125,3 +132,8 @@ if(PLAYRHO_INSTALL_DOC)
add_subdirectory(Documentation)
endif()
endif(PLAYRHO_INSTALL_DOC)

if(PLAYRHO_INSTALL)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt)
include(CPack)
endif()
10 changes: 9 additions & 1 deletion HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Hello World examples
include_directories (${PlayRho_SOURCE_DIR})
add_executable(HelloWorld HelloWorld.cpp)
target_link_libraries (HelloWorld PlayRho)

target_link_libraries(HelloWorld PlayRho)

# link with coverage library
if(${PLAYRHO_ENABLE_COVERAGE})
Expand All @@ -11,3 +12,10 @@ if(${PLAYRHO_ENABLE_COVERAGE})
target_link_libraries(HelloWorld -fprofile-arcs -ftest-coverage)
endif()
endif()

if(PLAYRHO_INSTALL)
include(GNUInstallDirs)
install(TARGETS HelloWorld
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications)
endif()
205 changes: 83 additions & 122 deletions PlayRho/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

if(NOT PLAYRHO_REAL_TYPE)
set(PLAYRHO_REAL_TYPE float)
endif()
Expand Down Expand Up @@ -29,102 +26,55 @@ configure_file("Defines.hpp.in" "Defines.hpp" @ONLY)
# configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Common/Real.hpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/Common/Real.hpp")
configure_file("Common/Real.hpp.in" "Common/Real.hpp" @ONLY)

file(GLOB PLAYRHO_Collision_SRCS
"Collision/*.cpp"
)
file(GLOB PLAYRHO_Collision_HDRS
"Collision/*.hpp"
)
file(GLOB PLAYRHO_Shapes_SRCS
"Collision/Shapes/*.cpp"
)
file(GLOB PLAYRHO_Shapes_HDRS
"Collision/Shapes/*.hpp"
)
file(GLOB PLAYRHO_Common_SRCS
"Common/*.cpp"
)
file(GLOB PLAYRHO_Common_HDRS
"Common/*.hpp"
)
file(GLOB PLAYRHO_Dynamics_SRCS
"Dynamics/*.cpp"
)
file(GLOB PLAYRHO_Dynamics_HDRS
"Dynamics/*.hpp"
)
file(GLOB PLAYRHO_Contacts_SRCS
"Dynamics/Contacts/*.cpp"
)
file(GLOB PLAYRHO_Contacts_HDRS
"Dynamics/Contacts/*.hpp"
)
file(GLOB PLAYRHO_Joints_SRCS
"Dynamics/Joints/*.cpp"
)
file(GLOB PLAYRHO_Joints_HDRS
"Dynamics/Joints/*.hpp"
)
file(GLOB PLAYRHO_General_HDRS
"*.hpp"
)
file(GLOB PLAYRHO_Collision_SRCS "Collision/*.cpp")
file(GLOB PLAYRHO_Collision_HDRS "Collision/*.hpp")
file(GLOB PLAYRHO_Shapes_SRCS "Collision/Shapes/*.cpp")
file(GLOB PLAYRHO_Shapes_HDRS "Collision/Shapes/*.hpp")
file(GLOB PLAYRHO_Common_SRCS "Common/*.cpp")
file(GLOB PLAYRHO_Common_HDRS "Common/*.hpp")
file(GLOB PLAYRHO_Dynamics_SRCS "Dynamics/*.cpp")
file(GLOB PLAYRHO_Dynamics_HDRS "Dynamics/*.hpp")
file(GLOB PLAYRHO_Contacts_SRCS "Dynamics/Contacts/*.cpp")
file(GLOB PLAYRHO_Contacts_HDRS "Dynamics/Contacts/*.hpp")
file(GLOB PLAYRHO_Joints_SRCS "Dynamics/Joints/*.cpp")
file(GLOB PLAYRHO_Joints_HDRS "Dynamics/Joints/*.hpp")
file(GLOB PLAYRHO_General_HDRS "*.hpp")
include_directories( ../ )

if (${PLAYRHO_ENABLE_COVERAGE} AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "lib: Adding definitions for coverage analysis.")
add_definitions(--coverage)
endif()

if(PLAYRHO_BUILD_SHARED)
add_library(PlayRho_shared SHARED
${PLAYRHO_General_HDRS}
${PLAYRHO_Joints_SRCS}
${PLAYRHO_Joints_HDRS}
${PLAYRHO_Contacts_SRCS}
${PLAYRHO_Contacts_HDRS}
${PLAYRHO_Dynamics_SRCS}
${PLAYRHO_Dynamics_HDRS}
${PLAYRHO_Common_SRCS}
${PLAYRHO_Common_HDRS}
${PLAYRHO_Shapes_SRCS}
${PLAYRHO_Shapes_HDRS}
${PLAYRHO_Collision_SRCS}
${PLAYRHO_Collision_HDRS}
${PLAYRHO_Rope_SRCS}
${PLAYRHO_Rope_HDRS}
)
add_library(PlayRho::PlayRho_shared ALIAS PlayRho)
target_compile_features(PlayRho_shared PUBLIC cxx_std_17)
set_target_properties(PlayRho_shared PROPERTIES
OUTPUT_NAME "PlayRho"
VERSION ${PLAYRHO_VERSION}
)
endif()
set(libsrc
${PLAYRHO_General_HDRS}
${PLAYRHO_Joints_SRCS}
${PLAYRHO_Joints_HDRS}
${PLAYRHO_Contacts_SRCS}
${PLAYRHO_Contacts_HDRS}
${PLAYRHO_Dynamics_SRCS}
${PLAYRHO_Dynamics_HDRS}
${PLAYRHO_Common_SRCS}
${PLAYRHO_Common_HDRS}
${PLAYRHO_Shapes_SRCS}
${PLAYRHO_Shapes_HDRS}
${PLAYRHO_Collision_SRCS}
${PLAYRHO_Collision_HDRS}
${PLAYRHO_Rope_SRCS}
${PLAYRHO_Rope_HDRS}
)

if(PLAYRHO_BUILD_STATIC)
add_library(PlayRho STATIC
${PLAYRHO_General_HDRS}
${PLAYRHO_Joints_SRCS}
${PLAYRHO_Joints_HDRS}
${PLAYRHO_Contacts_SRCS}
${PLAYRHO_Contacts_HDRS}
${PLAYRHO_Dynamics_SRCS}
${PLAYRHO_Dynamics_HDRS}
${PLAYRHO_Common_SRCS}
${PLAYRHO_Common_HDRS}
${PLAYRHO_Shapes_SRCS}
${PLAYRHO_Shapes_HDRS}
${PLAYRHO_Collision_SRCS}
${PLAYRHO_Collision_HDRS}
${PLAYRHO_Rope_SRCS}
${PLAYRHO_Rope_HDRS}
)
add_library(PlayRho::PlayRho ALIAS PlayRho)
target_compile_features(PlayRho PUBLIC cxx_std_17)
set_target_properties(PlayRho PROPERTIES
VERSION ${PLAYRHO_VERSION}
)
if(PLAYRHO_BUILD_SHARED)
add_library(PlayRho SHARED ${libsrc})
else()
add_library(PlayRho STATIC ${libsrc})
endif()
add_library(PlayRho::PlayRho ALIAS PlayRho)
target_compile_features(PlayRho PUBLIC cxx_std_17)
set_target_properties(PlayRho PROPERTIES
OUTPUT_NAME "PlayRho"
VERSION ${PlayRho_VERSION}
SOVERSION ${PlayRho_VERSION_MAJOR})

# These are used to create visual studio folders.
source_group(Collision FILES ${PLAYRHO_Collision_SRCS} ${PLAYRHO_Collision_HDRS})
Expand All @@ -135,45 +85,56 @@ source_group(Dynamics\\Contacts FILES ${PLAYRHO_Contacts_SRCS} ${PLAYRHO_Contact
source_group(Dynamics\\Joints FILES ${PLAYRHO_Joints_SRCS} ${PLAYRHO_Joints_HDRS})
source_group(Include FILES ${PLAYRHO_General_HDRS})

# install headers
install(FILES ${PLAYRHO_General_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho)
install(FILES ${PLAYRHO_Collision_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Collision)
install(FILES ${PLAYRHO_Shapes_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Collision/Shapes)
install(FILES ${PLAYRHO_Common_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Common)
install(FILES ${PLAYRHO_Dynamics_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics)
install(FILES ${PLAYRHO_Contacts_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics/Contacts)
install(FILES ${PLAYRHO_Joints_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics/Joints)
if(PLAYRHO_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# install libraries
if(PLAYRHO_BUILD_SHARED)
install(TARGETS PlayRho_shared
EXPORT PlayRho-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
if(PLAYRHO_BUILD_STATIC)
# install headers
install(FILES ${PLAYRHO_General_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho
COMPONENT Library)
install(FILES ${PLAYRHO_Collision_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Collision
COMPONENT Library)
install(FILES ${PLAYRHO_Shapes_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Collision/Shapes
COMPONENT Library)
install(FILES ${PLAYRHO_Common_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Common
COMPONENT Library)
install(FILES ${PLAYRHO_Dynamics_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics
COMPONENT Library)
install(FILES ${PLAYRHO_Contacts_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics/Contacts
COMPONENT Library)
install(FILES ${PLAYRHO_Joints_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PlayRho/Dynamics/Joints
COMPONENT Library)

# install libraries
install(TARGETS PlayRho
EXPORT PlayRho-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Library
)
endif()

# install build system hooks for third-party apps
install(EXPORT PlayRho-targets
FILE PlayRho-targets.cmake
NAMESPACE PlayRho::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PlayRho)
# install build system hooks for third-party apps
install(EXPORT PlayRho-targets
FILE PlayRho-targets.cmake
NAMESPACE PlayRho::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PlayRho)

set(PLAYRHO_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(PLAYRHO_INCLUDE_DIRS ${PLAYRHO_INCLUDE_DIR} )
set(PLAYRHO_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR})
set(PLAYRHO_LIBRARY PlayRho)
set(PLAYRHO_LIBRARIES ${PLAYRHO_LIBRARY})
configure_package_config_file(PlayRhoConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PlayRhoConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/PlayRho/PlayRhoConfig.cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PlayRhoConfig.cmake DESTINATION ${LIB_INSTALL_DIR}/cmake/PlayRho)
set(PLAYRHO_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(PLAYRHO_INCLUDE_DIRS ${PLAYRHO_INCLUDE_DIR} )
set(PLAYRHO_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR})
set(PLAYRHO_LIBRARY PlayRho)
set(PLAYRHO_LIBRARIES ${PLAYRHO_LIBRARY})
configure_package_config_file(PlayRhoConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/PlayRhoConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/PlayRho/PlayRhoConfig.cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PlayRhoConfig.cmake DESTINATION ${LIB_INSTALL_DIR}/cmake/PlayRho)
endif()
9 changes: 8 additions & 1 deletion Testbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ include_directories(

message(STATUS "Setting link directories")

add_executable(Testbed MACOSX_BUNDLE
add_executable(Testbed
${Testbed_Framework_SRCS}
${Testbed_Tests_SRCS}
)
Expand All @@ -94,3 +94,10 @@ endif()


file(COPY Data DESTINATION ..)

if(PLAYRHO_INSTALL)
include(GNUInstallDirs)
install(TARGETS Testbed
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications)
endif()
10 changes: 10 additions & 0 deletions UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ endif()

# Adds UnitTests to be run when like "make test" is executed.
add_test(UnitTests UnitTests)

include(GoogleTest)
gtest_discover_tests(UnitTests)

if(PLAYRHO_INSTALL)
include(GNUInstallDirs)
install(TARGETS UnitTests
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Applications)
endif()

0 comments on commit 3b8b108

Please sign in to comment.