Skip to content

Commit 1dbbabd

Browse files
committed
Make OMR an installable library
This is the start of a series of changes intended to make OMR more easily consumable. This change is prototyped using the standalone AVL and omrsig libraries, although it should be trivial to add support for other libraries. Some of the ways we hope OMR can be consumed are as follows: 1. Installable OMR. By creating proper install targets for OMR using standard paths, it should be trivial to package OMR for any linux distribution. 2. CMake User Registry. With a little bit of care, we can support the CMake User Registry. This means that a user can build OMR anywhere on their system, and the build directory will be registered in `~/.cmake/packages/Omr`. This will allow users to consume OMR using `find_package(Omr)`, without having to install OMR. 3. As a subproject. Having OMR as a subdirectory is the most common way to consume OMR. We intend to continue to support and enhance this method of consumption. We also hope to add versioning support to OMR in the future. Signed-off-by: Andrew Young <[email protected]>
1 parent 483bf23 commit 1dbbabd

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

CMakeLists.txt

+30-13
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,15 @@ endif()
5252
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
5353

5454
###
55-
### Set up install path stuff
55+
### Set up install paths
5656
###
57-
# Note the paths are a bit odd compared to standard gnu install paths
58-
# This is because we arent expecting to actually be installing globally
59-
# since we don't have a good story for installing OMR system-wide
60-
set(CMAKE_INSTALL_BINDIR ".")
61-
set(CMAKE_INSTALL_LIBDIR ".")
62-
set(OMR_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Root path where to install OMR")
63-
set(CMAKE_INSTALL_PREFIX "${OMR_INSTALL_PREFIX}")
6457
include(GNUInstallDirs)
65-
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
66-
add_custom_target(omr_install_tooling
67-
COMMAND ${CMAKE_COMMAND} --build tools --target preinstall
68-
COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_COMPONENT=tooling -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
69-
)
58+
59+
set(OMR_INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
60+
set(OMR_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
61+
set(OMR_INSTALL_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
62+
set(OMR_INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for headers")
63+
set(OMR_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} CACHE PATH "Installation directory for data files")
7064

7165
###
7266
### Versions and stuff
@@ -161,3 +155,26 @@ endif(OMR_JITBUILDER)
161155
if(OMR_FVTEST)
162156
add_subdirectory(fvtest)
163157
endif()
158+
159+
160+
# Export CMake Module
161+
162+
# This file must be copied into the build directory so that
163+
# the cmake user package registry functions properly
164+
configure_file(OmrConfig.cmake
165+
"${CMAKE_CURRENT_BINARY_DIR}/OmrConfig.cmake"
166+
COPYONLY
167+
)
168+
169+
export(EXPORT OmrTargets FILE OmrTargets.cmake)
170+
171+
install(EXPORT OmrTargets
172+
FILE OmrTargets.cmake
173+
DESTINATION ${OMR_INSTALL_LIB_DIR}/cmake/Omr
174+
)
175+
176+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/OmrConfig.cmake"
177+
DESTINATION ${OMR_INSTALL_LIB_DIR}/cmake/Omr
178+
)
179+
180+
export(PACKAGE Omr)

OmrConfig.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include("${CMAKE_CURRENT_LIST_DIR}/OmrTargets.cmake")

omrsigcompat/CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ endif()
116116
#ifneq (,$(findstring osx,$(OMR_HOST_OS)))
117117
#MODULE_SHARED_LIBS += pthread
118118
#endif
119-
install(TARGETS omrsig
120-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
121-
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
119+
120+
install(
121+
TARGETS omrsig
122+
EXPORT OmrTargets
123+
PUBLIC_HEADER DESTINATION ${OMR_INSTALL_INC_DIR}/
124+
ARCHIVE DESTINATION ${OMR_INSTALL_ARCHIVE_DIR}/
125+
LIBRARY DESTINATION ${OMR_INSTALL_LIB_DIR}/
122126
)
127+

util/avl/CMakeLists.txt

+23-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,26 @@
2020
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
2121
###############################################################################
2222

23-
include_directories(${CMAKE_CURRENT_BINARY_DIR})
24-
2523
add_tracegen(avl.tdf)
2624

25+
set(j9avl_public_headers
26+
"${omr_SOURCE_DIR}/include_core/avl_api.h"
27+
)
28+
2729
add_library(j9avl STATIC
2830
avlsup.c
2931
ut_avl.c
3032
)
3133

34+
target_include_directories(j9avl
35+
PUBLIC
36+
$<BUILD_INTERFACE:${OMR_SOURCE_DIR}/include_core>
37+
$<INSTALL_INTERFACE:${OMR_INSTALL_INC_DIR}>
38+
PRIVATE
39+
.
40+
${CMAKE_CURRENT_BINARY_DIR}
41+
)
42+
3243
if(OMR_WARNINGS_AS_ERRORS)
3344
target_compile_options(j9avl PRIVATE ${OMR_WARNING_AS_ERROR_FLAG})
3445
endif()
@@ -37,9 +48,14 @@ if(OMR_ENHANCED_WARNINGS)
3748
target_compile_options(j9avl PRIVATE ${OMR_ENHANCED_WARNING_FLAG})
3849
endif()
3950

40-
target_include_directories(j9avl
41-
PUBLIC
42-
.
43-
)
44-
4551
set_property(TARGET j9avl PROPERTY FOLDER util)
52+
53+
set_target_properties(j9avl PROPERTIES PUBLIC_HEADER ${j9avl_public_headers})
54+
55+
install(
56+
TARGETS j9avl
57+
EXPORT OmrTargets
58+
PUBLIC_HEADER DESTINATION ${OMR_INSTALL_INC_DIR}/
59+
ARCHIVE DESTINATION ${OMR_INSTALL_ARCHIVE_DIR}/
60+
LIBRARY DESTINATION ${OMR_INSTALL_LIB_DIR}/
61+
)

0 commit comments

Comments
 (0)