Skip to content

Commit 8f8f259

Browse files
committed
Split build file for libbz2support and libbz2 for reuse
1 parent 2d3a94a commit 8f8f259

File tree

3 files changed

+86
-33
lines changed

3 files changed

+86
-33
lines changed

graalpython/python-libbz2/CMakeLists.txt

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,57 +29,32 @@
2929
cmake_minimum_required(VERSION 3.22)
3030
project(python-libbz2)
3131

32-
function(require_var var)
33-
if (NOT ${var})
34-
message(FATAL_ERROR "${var} needs to be set")
35-
endif()
36-
endfunction()
32+
include(libbz2.cmake)
3733

38-
require_var(BZIP2_SRC)
39-
40-
set(BZIP2_VERSION "${BZIP2_VERSION_MAJOR}.${BZIP2_VERSION_MINOR}.${BZIP2_VERSION_PATCH}")
41-
42-
message(VERBOSE "Building libbz2 version: ${BZIP2_VERSION}")
34+
if(NOT DEFINED TARGET_LIBBZ2)
35+
message(FATAL_ERROR "TARGET_LIBBZ2 needs to be set")
36+
endif()
4337

4438
set(PACKAGE_NAME "bzip2")
45-
set(TARGET_BZIP2 "bz2")
4639
set(TARGET_BZIP2SUPPORT "bz2support")
47-
set(SRC_DIR "${BZIP2_SRC}/${PACKAGE_NAME}-${BZIP2_VERSION}")
4840

49-
add_library(${TARGET_BZIP2} STATIC)
5041
add_library(${TARGET_BZIP2SUPPORT} SHARED)
5142

52-
# we want '-fPIC' even for the static lib
53-
set_target_properties(${TARGET_BZIP2} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
54-
5543
# preprocessor defines for all platforms
56-
target_compile_definitions(${TARGET_BZIP2} PRIVATE _FILE_OFFSET_BITS=64)
5744
target_compile_definitions(${TARGET_BZIP2SUPPORT} PRIVATE NDEBUG)
5845

5946
if(WIN32)
60-
target_compile_options(${TARGET_BZIP2} PRIVATE /Z7 /O2 /Wall)
6147
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE /Z7 /O2 /WX)
6248
else()
63-
target_compile_options(${TARGET_BZIP2} PRIVATE -Wall -Winline -O2 -g)
6449
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE -Wall -Werror -O3 -g)
6550
endif()
6651

6752
# don't install into the system but into the MX project's output dir
6853
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
6954

70-
# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob
71-
target_sources(${TARGET_BZIP2} PRIVATE
72-
"${SRC_DIR}/bzlib.h"
73-
"${SRC_DIR}/blocksort.c"
74-
"${SRC_DIR}/huffman.c"
75-
"${SRC_DIR}/crctable.c"
76-
"${SRC_DIR}/randtable.c"
77-
"${SRC_DIR}/compress.c"
78-
"${SRC_DIR}/decompress.c"
79-
"${SRC_DIR}/bzlib.c"
80-
)
8155
target_sources(${TARGET_BZIP2SUPPORT} PRIVATE "src/bz2.c")
82-
target_include_directories(${TARGET_BZIP2SUPPORT} PRIVATE ${SRC_DIR})
83-
target_link_libraries(${TARGET_BZIP2SUPPORT} PRIVATE ${TARGET_BZIP2})
56+
# variable 'BZIP2_SRC' is provided by file 'libbz2.cmake'
57+
target_include_directories(${TARGET_BZIP2SUPPORT} PRIVATE ${BZIP2_SRC})
58+
target_link_libraries(${TARGET_BZIP2SUPPORT} PRIVATE ${TARGET_LIBBZ2})
8459

8560
install(TARGETS ${TARGET_BZIP2SUPPORT} DESTINATION bin)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#
2+
# Copyright (c) 2023, Oracle and/or its affiliates.
3+
#
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are
7+
# permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this list of
10+
# conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
# conditions and the following disclaimer in the documentation and/or other materials provided
14+
# with the distribution.
15+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
16+
# endorse or promote products derived from this software without specific prior written
17+
# permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
20+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25+
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
# OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
cmake_minimum_required(VERSION 3.22)
30+
project(libbz2)
31+
32+
function(require_var var)
33+
if (NOT DEFINED ${var})
34+
message(FATAL_ERROR "${var} needs to be set; was '${var}'")
35+
endif()
36+
endfunction()
37+
38+
require_var(BZIP2_ROOT)
39+
require_var(BZIP2_VERSION_MAJOR)
40+
require_var(BZIP2_VERSION_MINOR)
41+
require_var(BZIP2_VERSION_PATCH)
42+
43+
set(BZIP2_VERSION "${BZIP2_VERSION_MAJOR}.${BZIP2_VERSION_MINOR}.${BZIP2_VERSION_PATCH}")
44+
45+
message(VERBOSE "Building libbz2 version: ${BZIP2_VERSION}")
46+
47+
set(PACKAGE_NAME "bzip2")
48+
set(TARGET_LIBBZ2 "bz2")
49+
set(BZIP2_SRC "${BZIP2_ROOT}/${PACKAGE_NAME}-${BZIP2_VERSION}")
50+
51+
add_library(${TARGET_LIBBZ2} STATIC)
52+
53+
# we want '-fPIC' even for the static lib
54+
set_target_properties(${TARGET_LIBBZ2} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
55+
56+
# preprocessor defines for all platforms
57+
target_compile_definitions(${TARGET_LIBBZ2} PRIVATE _FILE_OFFSET_BITS=64)
58+
59+
if(WIN32)
60+
target_compile_options(${TARGET_LIBBZ2} PRIVATE /Z7 /O2 /Wall)
61+
else()
62+
target_compile_options(${TARGET_LIBBZ2} PRIVATE -Wall -Winline -O2 -g)
63+
endif()
64+
65+
# don't install into the system but into the MX project's output dir
66+
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
67+
68+
# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob
69+
target_sources(${TARGET_LIBBZ2} PRIVATE
70+
"${BZIP2_SRC}/bzlib.h"
71+
"${BZIP2_SRC}/blocksort.c"
72+
"${BZIP2_SRC}/huffman.c"
73+
"${BZIP2_SRC}/crctable.c"
74+
"${BZIP2_SRC}/randtable.c"
75+
"${BZIP2_SRC}/compress.c"
76+
"${BZIP2_SRC}/decompress.c"
77+
"${BZIP2_SRC}/bzlib.c"
78+
)

mx.graalpython/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@
471471
"bin/<lib:bz2support>",
472472
],
473473
"cmakeConfig" : {
474-
"BZIP2_SRC": "<path:BZIP2>",
474+
"BZIP2_ROOT": "<path:BZIP2>",
475475
"BZIP2_VERSION_MAJOR": "1",
476476
"BZIP2_VERSION_MINOR": "0",
477477
"BZIP2_VERSION_PATCH": "8",

0 commit comments

Comments
 (0)