Skip to content

Commit a31ef0e

Browse files
authored
CI/CD: Enhance the build system (#22)
* User space * Fix install on cluster
1 parent 83922a0 commit a31ef0e

File tree

2 files changed

+611
-21
lines changed

2 files changed

+611
-21
lines changed

CMakeLists.txt

Lines changed: 113 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ set(CMAKE_CXX_STANDARD 17)
2121
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2222
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2323

24+
# ============================================================================
25+
set(USER_PREFIX "$ENV{HOME}/local")
26+
27+
list(APPEND CMAKE_PREFIX_PATH "${USER_PREFIX}")
28+
list(APPEND CMAKE_LIBRARY_PATH "${USER_PREFIX}/lib")
29+
list(APPEND CMAKE_INCLUDE_PATH "${USER_PREFIX}/include")
30+
31+
include_directories("${USER_PREFIX}/include")
32+
link_directories("${USER_PREFIX}/lib")
33+
2434
# =============================================================================
2535
# Compiler Flags Configuration
2636
# =============================================================================
@@ -31,7 +41,7 @@ set(BASE_CXX_FLAGS "-fPIC -fno-strict-overflow -fno-strict-aliasing")
3141

3242
# Compiler-specific flags
3343
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
34-
set(COMPILER_SPECIFIC_FLAGS "-Wno-cast-user-defined -Wno-array-bounds")
44+
set(COMPILER_SPECIFIC_FLAGS "-Wno-cast-user-defined -Wno-array-bounds -Wno-type-limits")
3545
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
3646
set(COMPILER_SPECIFIC_FLAGS "-Wno-array-bounds")
3747
else()
@@ -155,8 +165,20 @@ configure_logging()
155165
# Dependency Management
156166
# =============================================================================
157167

168+
# Add user-installed dependencies to search paths
169+
if(DEFINED ENV{CMAKE_PREFIX_PATH})
170+
list(PREPEND CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
171+
endif()
172+
173+
# Add common user installation paths
174+
set(USER_PREFIX_PATHS
175+
"$ENV{HOME}/local"
176+
"$ENV{HOME}/.local"
177+
"/usr/local"
178+
)
179+
158180
# Find required packages
159-
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
181+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
160182
find_package(pybind11 CONFIG REQUIRED)
161183
find_package(PkgConfig REQUIRED)
162184

@@ -170,23 +192,85 @@ include_directories(${GLib_INCLUDE_DIRS})
170192
link_directories(${GLib_LIBRARY_DIRS})
171193
list(APPEND required_libs ${GLib_LIBRARIES})
172194

173-
# ZSTD dependency
174-
find_package(ZSTD REQUIRED)
175-
message(STATUS "ZSTD_INCLUDE_DIR: ${ZSTD_INCLUDE_DIR}, ZSTD_LIBRARIES: ${ZSTD_LIBRARIES}")
176-
if("${ZSTD_LIBRARIES}" STREQUAL "")
177-
message(FATAL_ERROR "zstd not found")
195+
# ZSTD dependency - try multiple find methods
196+
find_package(ZSTD QUIET)
197+
if(NOT ZSTD_FOUND)
198+
# Try pkg-config
199+
pkg_check_modules(ZSTD_PC QUIET libzstd)
200+
if(ZSTD_PC_FOUND)
201+
set(ZSTD_FOUND TRUE)
202+
set(ZSTD_INCLUDE_DIR ${ZSTD_PC_INCLUDE_DIRS})
203+
set(ZSTD_LIBRARIES ${ZSTD_PC_LIBRARIES})
204+
set(ZSTD_LIBRARY_DIRS ${ZSTD_PC_LIBRARY_DIRS})
205+
else()
206+
# Try manual find
207+
find_path(ZSTD_INCLUDE_DIR zstd.h
208+
PATHS ${CMAKE_INCLUDE_PATH}
209+
PATH_SUFFIXES zstd
210+
)
211+
find_library(ZSTD_LIBRARIES zstd
212+
PATHS ${CMAKE_LIBRARY_PATH}
213+
)
214+
if(ZSTD_INCLUDE_DIR AND ZSTD_LIBRARIES)
215+
set(ZSTD_FOUND TRUE)
216+
endif()
217+
endif()
218+
endif()
219+
220+
if(NOT ZSTD_FOUND)
221+
message(FATAL_ERROR "ZSTD not found. Please install zstd or set CMAKE_PREFIX_PATH to point to user installation.")
178222
endif()
223+
224+
message(STATUS "ZSTD_INCLUDE_DIR: ${ZSTD_INCLUDE_DIR}, ZSTD_LIBRARIES: ${ZSTD_LIBRARIES}")
179225
include_directories(${ZSTD_INCLUDE_DIR})
180-
link_directories(${ZSTD_LIBRARY_DIRS})
226+
if(ZSTD_LIBRARY_DIRS)
227+
link_directories(${ZSTD_LIBRARY_DIRS})
228+
endif()
181229
list(APPEND required_libs ${ZSTD_LIBRARIES})
182230

231+
# TCMalloc dependency (optional)
232+
find_library(TCMALLOC_LIBRARY tcmalloc
233+
PATHS ${CMAKE_LIBRARY_PATH}
234+
)
235+
if(TCMALLOC_LIBRARY)
236+
list(APPEND optional_libs ${TCMALLOC_LIBRARY})
237+
message(STATUS "TCMalloc found: ${TCMALLOC_LIBRARY}")
238+
add_compile_definitions(USE_TCMALLOC=1)
239+
else()
240+
message(STATUS "TCMalloc not found, using system malloc")
241+
endif()
242+
183243
# Optional dependencies based on features
184244
if(ENABLE_GLCACHE)
185-
find_package(xgboost REQUIRED)
186-
include_directories(${XGBOOST_INCLUDE_DIR})
187-
list(APPEND optional_libs xgboost::xgboost)
188-
add_compile_definitions(ENABLE_GLCACHE=1)
189-
message(STATUS "XGBOOST_INCLUDE_DIR: ${XGBOOST_INCLUDE_DIR}")
245+
# Try to find XGBoost
246+
find_package(xgboost QUIET)
247+
if(NOT xgboost_FOUND)
248+
# Try manual find for user installation
249+
find_path(XGBOOST_INCLUDE_DIR xgboost
250+
PATHS ${CMAKE_INCLUDE_PATH}
251+
)
252+
find_library(XGBOOST_LIBRARIES xgboost
253+
PATHS ${CMAKE_LIBRARY_PATH}
254+
)
255+
if(XGBOOST_INCLUDE_DIR AND XGBOOST_LIBRARIES)
256+
set(xgboost_FOUND TRUE)
257+
add_library(xgboost::xgboost UNKNOWN IMPORTED)
258+
set_target_properties(xgboost::xgboost PROPERTIES
259+
IMPORTED_LOCATION ${XGBOOST_LIBRARIES}
260+
INTERFACE_INCLUDE_DIRECTORIES ${XGBOOST_INCLUDE_DIR}
261+
)
262+
endif()
263+
endif()
264+
265+
if(xgboost_FOUND)
266+
include_directories(${XGBOOST_INCLUDE_DIR})
267+
list(APPEND optional_libs xgboost::xgboost)
268+
add_compile_definitions(ENABLE_GLCACHE=1)
269+
message(STATUS "XGBOOST_INCLUDE_DIR: ${XGBOOST_INCLUDE_DIR}")
270+
else()
271+
message(WARNING "XGBoost not found, disabling GLCACHE feature")
272+
set(ENABLE_GLCACHE OFF)
273+
endif()
190274
endif()
191275

192276
# LightGBM for LRB and 3L_CACHE
@@ -201,22 +285,30 @@ foreach(FEATURE ${LIGHTGBM_FEATURES})
201285
endforeach()
202286

203287
if(LIGHTGBM_NEEDED)
288+
# Try to find LightGBM
204289
if(NOT DEFINED LIGHTGBM_PATH)
205-
find_path(LIGHTGBM_PATH LightGBM)
206-
endif()
207-
if(NOT LIGHTGBM_PATH)
208-
message(FATAL_ERROR "LIGHTGBM_PATH not found")
290+
find_path(LIGHTGBM_PATH LightGBM
291+
PATHS ${CMAKE_INCLUDE_PATH}
292+
)
209293
endif()
210294

211295
if(NOT DEFINED LIGHTGBM_LIB)
212-
find_library(LIGHTGBM_LIB _lightgbm)
296+
find_library(LIGHTGBM_LIB _lightgbm
297+
PATHS ${CMAKE_LIBRARY_PATH}
298+
)
213299
endif()
300+
301+
if(NOT LIGHTGBM_PATH)
302+
message(FATAL_ERROR "LIGHTGBM_PATH not found. Please install LightGBM or set CMAKE_PREFIX_PATH.")
303+
endif()
304+
214305
if(NOT LIGHTGBM_LIB)
215-
message(FATAL_ERROR "LIGHTGBM_LIB not found")
306+
message(FATAL_ERROR "LIGHTGBM_LIB not found. Please install LightGBM or set CMAKE_PREFIX_PATH.")
216307
endif()
217308

218309
include_directories(${LIGHTGBM_PATH})
219310
list(APPEND optional_libs ${LIGHTGBM_LIB})
311+
message(STATUS "LightGBM found: ${LIGHTGBM_PATH}, ${LIGHTGBM_LIB}")
220312
endif()
221313

222314
# =============================================================================
@@ -263,7 +355,7 @@ set(PYTHON_MODULE_SOURCES
263355
)
264356

265357
# Create Python module
266-
python_add_library(libcachesim_python MODULE ${PYTHON_MODULE_SOURCES} WITH_SOABI)
358+
pybind11_add_module(libcachesim_python ${PYTHON_MODULE_SOURCES} WITH_SOABI)
267359

268360
# Configure target properties
269361
set_target_properties(libcachesim_python PROPERTIES
@@ -319,4 +411,4 @@ configure_platform_specific_linking(libcachesim_python)
319411
# Installation
320412
# =============================================================================
321413

322-
install(TARGETS libcachesim_python LIBRARY DESTINATION libcachesim)
414+
install(TARGETS libcachesim_python LIBRARY DESTINATION libcachesim)

0 commit comments

Comments
 (0)