Skip to content

Commit 3fd92e8

Browse files
committed
I think the CMakeLists are correct, less sure about rest.
1 parent 8fe4158 commit 3fd92e8

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

CMakeLists.txt

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
cmake_minimum_required(VERSION 3.15)
2+
23
project(python_lzo)
34

45
# Set C/C++ standards
56
set(CMAKE_C_STANDARD 11)
6-
set(CMAKE_CXX_STANDARD 14)
7-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
87

98
# Option to use system liblzo instead of building from source
109
option(USE_SYSTEM_LZO "Use system-installed liblzo instead of building from source" OFF)
@@ -16,7 +15,6 @@ endif()
1615

1716
# Find Python for the extension
1817
find_package(Python COMPONENTS Interpreter Development REQUIRED)
19-
find_package(pybind11 CONFIG REQUIRED)
2018

2119
if(USE_SYSTEM_LZO)
2220
# Use system-installed liblzo
@@ -25,41 +23,41 @@ if(USE_SYSTEM_LZO)
2523
PATHS /usr/lib /usr/local/lib /opt/local/lib
2624
DOC "liblzo library"
2725
)
28-
26+
2927
find_path(LZO_INCLUDE_DIR
3028
NAMES lzo/lzo1x.h
3129
PATHS /usr/include /usr/local/include /opt/local/include
3230
DOC "liblzo include directory"
3331
)
34-
32+
3533
if(NOT LZO_LIBRARY OR NOT LZO_INCLUDE_DIR)
3634
message(FATAL_ERROR "System liblzo not found. Install liblzo-dev or disable USE_SYSTEM_LZO")
3735
endif()
38-
36+
3937
message(STATUS "Using system liblzo: ${LZO_LIBRARY}")
4038
message(STATUS "liblzo headers: ${LZO_INCLUDE_DIR}")
41-
39+
4240
# Create imported target for system liblzo
4341
add_library(lzo_lib SHARED IMPORTED)
4442
set_target_properties(lzo_lib PROPERTIES
4543
IMPORTED_LOCATION ${LZO_LIBRARY}
4644
INTERFACE_INCLUDE_DIRECTORIES ${LZO_INCLUDE_DIR}
4745
)
48-
46+
4947
else()
5048
# Build liblzo from source in lzo-2.10 subdirectory
5149
set(LZO_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lzo-2.10")
5250
set(LZO_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/lzo_build")
53-
51+
5452
# Determine build command based on platform
5553
if(WIN32)
5654
# Windows: Use MSBuild
57-
set(LZO_BUILD_COMMAND
58-
msbuild lzo_static_lib.vcxproj
55+
set(LZO_BUILD_COMMAND
56+
msbuild lzo_static_lib.vcxproj
5957
-p:Configuration=Release$<SEMICOLON>Platform=x64$<SEMICOLON>OutDir=..\\
6058
)
6159
set(LZO_STATIC_LIB "${LZO_BUILD_DIR}/lzo2.lib")
62-
set(LZO_CONFIGURE_COMMAND
60+
set(LZO_CONFIGURE_COMMAND
6361
${CMAKE_COMMAND} -S ${LZO_PROJECT_DIR} -B ${LZO_BUILD_DIR}
6462
-DCMAKE_BUILD_TYPE=Release
6563
-A x64
@@ -70,16 +68,16 @@ else()
7068
if(APPLE)
7169
set(LZO_STATIC_LIB "${LZO_BUILD_DIR}/src/.libs/liblzo2.a")
7270
else()
73-
set(LZO_STATIC_LIB "${LZO_BUILD_DIR}/src/.libs/liblzo2.a")
71+
set(LZO_STATIC_LIB "${LZO_BUILD_DIR}/liblzo2.a")
7472
endif()
75-
set(LZO_CONFIGURE_COMMAND
73+
set(LZO_CONFIGURE_COMMAND
7674
${CMAKE_COMMAND} -S ${LZO_PROJECT_DIR} -B ${LZO_BUILD_DIR}
7775
-DCMAKE_BUILD_TYPE=Release
7876
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
7977
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
8078
)
8179
endif()
82-
80+
8381
# Configure and build liblzo using ExternalProject
8482
include(ExternalProject)
8583
ExternalProject_Add(lzo_project
@@ -91,49 +89,45 @@ else()
9189
BUILD_BYPRODUCTS ${LZO_STATIC_LIB}
9290
BUILD_IN_SOURCE 0
9391
)
94-
92+
9593
# Create an imported target for the built liblzo static library
9694
add_library(lzo_lib STATIC IMPORTED)
9795
set_target_properties(lzo_lib PROPERTIES
9896
IMPORTED_LOCATION ${LZO_STATIC_LIB}
9997
INTERFACE_INCLUDE_DIRECTORIES ${LZO_PROJECT_DIR}/include
10098
)
101-
99+
102100
# Make sure liblzo is built before we try to use it
103101
add_dependencies(lzo_lib lzo_project)
104102
endif()
105103

106104
# Compile the lzomodule.c file into an object library
107-
add_library(lzomodule_objects OBJECT
105+
add_library(lzo_module SHARED
108106
lzomodule.c
109107
)
110108

111109
# Set properties for the object library
112-
target_include_directories(lzomodule_objects PRIVATE
110+
target_include_directories(lzo_module PRIVATE
113111
${Python_INCLUDE_DIRS}
114112
)
115113

116114
if(USE_SYSTEM_LZO)
117-
target_include_directories(lzomodule_objects PRIVATE ${LZO_INCLUDE_DIR})
115+
target_include_directories(lzo_module PRIVATE ${LZO_INCLUDE_DIR})
118116
else()
119-
target_include_directories(lzomodule_objects PRIVATE ${LZO_PROJECT_DIR}/include)
117+
target_include_directories(lzo_module PRIVATE ${LZO_PROJECT_DIR}/include)
120118
endif()
121119

122-
# Create the final Python extension module
123-
pybind11_add_module(lzo_module
124-
$<TARGET_OBJECTS:lzomodule_objects>
125-
)
126120

127121
# Link the lzo library (either system or built from source)
128-
target_link_libraries(lzo_module PRIVATE
122+
target_link_libraries(lzo_module PRIVATE
129123
lzo_lib
130124
${Python_LIBRARIES}
131125
)
132126

133127
# Set target properties
134128
set_target_properties(lzo_module PROPERTIES
135-
OUTPUT_NAME "lzo" # This will create lzo.so/.dll/.pyd
136-
CXX_VISIBILITY_PRESET "hidden"
129+
OUTPUT_NAME "lzo" # This will create lzo.so/.dll/.pyd
130+
PREFIX ""
137131
INTERPROCEDURAL_OPTIMIZATION TRUE
138132
)
139133

@@ -168,10 +162,10 @@ endif()
168162
if(CMAKE_BUILD_TYPE STREQUAL "Release")
169163
if(MSVC)
170164
target_compile_options(lzo_module PRIVATE /O2)
171-
target_compile_options(lzomodule_objects PRIVATE /O2)
165+
target_compile_options(lzo_modules PRIVATE /O2)
172166
else()
173167
target_compile_options(lzo_module PRIVATE -O3 -march=native)
174-
target_compile_options(lzomodule_objects PRIVATE -O3 -march=native)
168+
target_compile_options(lzo_modules PRIVATE -O3 -march=native)
175169
endif()
176170
endif()
177171

@@ -192,4 +186,4 @@ else()
192186
message(STATUS " Build tool: make")
193187
endif()
194188
endif()
195-
message(STATUS "")
189+
message(STATUS "")

lzo-2.10/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# All Rights Reserved.
99
#
1010

11-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
11+
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
1212

1313
#
1414
# simple usage example (Unix):

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66
from setuptools import setup, Extension
77
from setuptools.command.build_ext import build_ext
8-
import pybind11
98

109

1110
class CMakeExtension(Extension):
@@ -41,7 +40,6 @@ def build_extension(self, ext):
4140
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
4241
f"-DPYTHON_EXECUTABLE={sys.executable}",
4342
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
44-
f"-DPYBIND11_PYTHON_VERSION={sys.version_info.major}.{sys.version_info.minor}",
4543
f"-DUSE_SYSTEM_LZO={use_system_lzo}",
4644
]
4745

@@ -76,8 +74,6 @@ def build_extension(self, ext):
7674
if hasattr(self, "parallel") and self.parallel:
7775
build_args += [f"-j{self.parallel}"]
7876

79-
cmake_args += [f"-DPYBIND11_INCLUDE_DIR={pybind11.get_include()}"]
80-
8177
build_temp = os.path.join(self.build_temp, ext.name)
8278
if not os.path.exists(build_temp):
8379
os.makedirs(build_temp)

0 commit comments

Comments
 (0)