Skip to content

Commit 150b4c4

Browse files
committed
STY: Format CMake files
1 parent 47396a6 commit 150b4c4

File tree

3 files changed

+38
-57
lines changed

3 files changed

+38
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
target_include_directories(_sparse_dot_topn_core PUBLIC ${SDTN_INCLUDE_DIR})
22
if(OpenMP_CXX_FOUND)
3-
target_link_libraries(_sparse_dot_topn_core PUBLIC OpenMP::OpenMP_CXX)
4-
target_compile_definitions(_sparse_dot_topn_core PRIVATE SDTN_OMP_ENABLED=TRUE)
3+
target_link_libraries(_sparse_dot_topn_core PUBLIC OpenMP::OpenMP_CXX)
4+
target_compile_definitions(_sparse_dot_topn_core PRIVATE SDTN_OMP_ENABLED=TRUE)
55
if(APPLE)
6+
# Modified implementation from LightGBM written by JamesLamb
7+
# see https://github.com/microsoft/LightGBM/pull/6391
68
# store path to libomp found at build time in a variable
79
get_target_property(
810
OpenMP_LIBRARY_LOCATION
@@ -22,27 +24,6 @@ if(OpenMP_CXX_FOUND)
2224
${OpenMP_LIBRARY_LOCATION}
2325
DIRECTORY
2426
)
25-
# get exact name of the library in a variable
26-
get_target_property(
27-
__LIB_SDTN_OUTPUT_NAME
28-
_sparse_dot_topn_core
29-
OUTPUT_NAME
30-
)
31-
if(NOT __LIB_SDTN_OUTPUT_NAME)
32-
set(__LIB_SDTN_OUTPUT_NAME "_sparse_dot_topn_core")
33-
endif()
34-
35-
if(CMAKE_SHARED_LIBRARY_SUFFIX_CXX)
36-
set(
37-
__LIB_SDTN_FILENAME "${__LIB_SDTN_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_CXX}"
38-
CACHE INTERNAL "sparse-dot-topn shared library filename"
39-
)
40-
else()
41-
set(
42-
__LIB_SDTN_FILENAME "${__LIB_SDTN_OUTPUT_NAME}.dylib"
43-
CACHE INTERNAL "sparse-dot-topn shared library filename"
44-
)
45-
endif()
4627

4728
# Override the absolute path to OpenMP with a relative one using @rpath.
4829
#
@@ -55,7 +36,7 @@ if(OpenMP_CXX_FOUND)
5536
-change
5637
${OpenMP_LIBRARY_LOCATION}
5738
"@rpath/${OpenMP_LIBRARY_NAME}"
58-
"${__LIB_SDTN_FILENAME}"
39+
$<TARGET_FILE:_sparse_dot_topn_core>
5940
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6041
COMMENT "Replacing hard-coded OpenMP install_name with '@rpath/${OpenMP_LIBRARY_NAME}'..."
6142
)
@@ -78,7 +59,7 @@ target_compile_definitions(_sparse_dot_topn_core PRIVATE VERSION_INFO=${SKBUILD_
7859

7960
# -- Optional
8061
if(SDTN_ENABLE_DEVMODE)
81-
target_compile_options(_sparse_dot_topn_core PRIVATE ${SDTN_DEVMODE_OPTIONS})
62+
target_compile_options(_sparse_dot_topn_core PRIVATE ${SDTN_DEVMODE_OPTIONS})
8263
endif()
8364

8465
# -- Options & Properties
@@ -89,41 +70,41 @@ set_property(TARGET _sparse_dot_topn_core PROPERTY POSITION_INDEPENDENT_CODE ON)
8970
include(CheckCXXCompilerFlag)
9071

9172
function(check_cxx_support FLAG DEST)
92-
string(SUBSTRING ${FLAG} 1 -1 STRIPPED_FLAG)
93-
string(REGEX REPLACE "=" "_" STRIPPED_FLAG ${STRIPPED_FLAG})
94-
string(TOUPPER ${STRIPPED_FLAG} STRIPPED_FLAG)
95-
set(RES_VAR "${STRIPPED_FLAG}_SUPPORTED")
96-
check_cxx_compiler_flag("${FLAG}" ${RES_VAR})
97-
if(${RES_VAR})
98-
set(${DEST} "${${DEST}} ${FLAG}" PARENT_SCOPE)
99-
endif()
73+
string(SUBSTRING ${FLAG} 1 -1 STRIPPED_FLAG)
74+
string(REGEX REPLACE "=" "_" STRIPPED_FLAG ${STRIPPED_FLAG})
75+
string(TOUPPER ${STRIPPED_FLAG} STRIPPED_FLAG)
76+
set(RES_VAR "${STRIPPED_FLAG}_SUPPORTED")
77+
check_cxx_compiler_flag("${FLAG}" ${RES_VAR})
78+
if(${RES_VAR})
79+
set(${DEST} "${${DEST}} ${FLAG}" PARENT_SCOPE)
80+
endif()
10081
endfunction()
10182

10283
# -- Compiler Flags
10384
if (SDTN_ENABLE_ARCH_FLAGS AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
104-
set(SDTN_ARCHITECTURE_FLAGS "")
105-
if (APPLE AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64"))
106-
# see https://github.com/google/highway/issues/745
107-
check_cxx_support("-march=native" SDTN_ARCHITECTURE_FLAGS)
108-
else()
109-
include(FindSse)
110-
include(FindAvx)
111-
SDTN_CHECK_FOR_SSE()
112-
add_definitions(${SSE_DEFINITIONS})
113-
SDTN_CHECK_FOR_AVX()
114-
string(APPEND SDTN_ARCHITECTURE_FLAGS "${SSE_FLAGS} ${AVX_FLAGS}")
115-
endif()
85+
set(SDTN_ARCHITECTURE_FLAGS "")
86+
if (APPLE AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64"))
87+
# see https://github.com/google/highway/issues/745
88+
check_cxx_support("-march=native" SDTN_ARCHITECTURE_FLAGS)
89+
else()
90+
include(FindSse)
91+
include(FindAvx)
92+
SDTN_CHECK_FOR_SSE()
93+
add_definitions(${SSE_DEFINITIONS})
94+
SDTN_CHECK_FOR_AVX()
95+
string(APPEND SDTN_ARCHITECTURE_FLAGS "${SSE_FLAGS} ${AVX_FLAGS}")
96+
endif()
11697

117-
if (NOT ${SDTN_ARCHITECTURE_FLAGS} STREQUAL "")
118-
string(STRIP ${SDTN_ARCHITECTURE_FLAGS} SDTN_ARCHITECTURE_FLAGS)
119-
message(STATUS "sparse-dot-topn | Enabled arch flags: ${SDTN_ARCHITECTURE_FLAGS}")
120-
if (MSVC)
121-
separate_arguments(SDTN_ARCHITECTURE_FLAGS WINDOWS_COMMAND "${SDTN_ARCHITECTURE_FLAGS}")
122-
else()
123-
separate_arguments(SDTN_ARCHITECTURE_FLAGS UNIX_COMMAND "${SDTN_ARCHITECTURE_FLAGS}")
124-
endif()
125-
target_compile_options(_sparse_dot_topn_core PRIVATE $<$<CONFIG:RELEASE>:${SDTN_ARCHITECTURE_FLAGS}>)
98+
if (NOT ${SDTN_ARCHITECTURE_FLAGS} STREQUAL "")
99+
string(STRIP ${SDTN_ARCHITECTURE_FLAGS} SDTN_ARCHITECTURE_FLAGS)
100+
message(STATUS "sparse-dot-topn | Enabled arch flags: ${SDTN_ARCHITECTURE_FLAGS}")
101+
if (MSVC)
102+
separate_arguments(SDTN_ARCHITECTURE_FLAGS WINDOWS_COMMAND "${SDTN_ARCHITECTURE_FLAGS}")
126103
else()
127-
message(STATUS "sparse-dot-topn | Architecture flags enabled but no valid flags were found")
104+
separate_arguments(SDTN_ARCHITECTURE_FLAGS UNIX_COMMAND "${SDTN_ARCHITECTURE_FLAGS}")
128105
endif()
106+
target_compile_options(_sparse_dot_topn_core PRIVATE $<$<CONFIG:RELEASE>:${SDTN_ARCHITECTURE_FLAGS}>)
107+
else()
108+
message(STATUS "sparse-dot-topn | Architecture flags enabled but no valid flags were found")
109+
endif()
129110
endif()

src/sparse_dot_topn_core/cmake/FindAvx.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###############################################################################
1+
# ##############################################################################
22
# Check for the presence of AVX and figure out the flags to use for it.
33
# This routine is a modified version of `PCL_CHECK_FOR_AVX`
44
# Reference: https://github.com/PointCloudLibrary/pcl/blob/master/cmake/pcl_find_avx.cmake

src/sparse_dot_topn_core/cmake/FindSse.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###############################################################################
1+
# ##############################################################################
22
# Check for the presence of SSE and figure out the flags to use for it.
33
# This routine is a modified version of `PCL_CHECK_FOR_SSE`
44
# https://github.com/PointCloudLibrary/pcl/blob/master/cmake/pcl_find_sse.cmake

0 commit comments

Comments
 (0)