11cmake_minimum_required (VERSION 3.15)
2+
23project (python_lzo)
34
45# Set C/C++ standards
56set (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
109option (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
1817find_package (Python COMPONENTS Interpreter Development REQUIRED)
19- find_package (pybind11 CONFIG REQUIRED)
2018
2119if (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+
4947else ()
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)
104102endif ()
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
116114if (USE_SYSTEM_LZO)
117- target_include_directories (lzomodule_objects PRIVATE ${LZO_INCLUDE_DIR} )
115+ target_include_directories (lzo_module PRIVATE ${LZO_INCLUDE_DIR} )
118116else ()
119- target_include_directories (lzomodule_objects PRIVATE ${LZO_PROJECT_DIR} /include )
117+ target_include_directories (lzo_module PRIVATE ${LZO_PROJECT_DIR} /include )
120118endif ()
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
134128set_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()
168162if (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 ()
176170endif ()
177171
@@ -192,4 +186,4 @@ else()
192186 message (STATUS " Build tool: make" )
193187 endif ()
194188endif ()
195- message (STATUS "" )
189+ message (STATUS "" )
0 commit comments