Skip to content

Commit 84658df

Browse files
committed
merged develop into master
2 parents 4bab8dc + 681da6b commit 84658df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+297
-202
lines changed

CMakeLists.txt

Lines changed: 223 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,231 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(GKlib C)
32

4-
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
3+
# ...
4+
project(GKlib
5+
VERSION 0.0.1
6+
LANGUAGES C)
57

6-
get_filename_component(abs "." ABSOLUTE)
7-
set(GKLIB_PATH ${abs})
8-
unset(abs)
9-
include(GKlibSystem.cmake)
8+
# include required CMake modules
9+
include(CheckCCompilerFlag)
10+
include(CheckCSourceCompiles)
11+
include(CheckFunctionExists)
12+
include(CheckIncludeFile)
13+
include(CMakePackageConfigHelpers)
14+
include(GNUInstallDirs)
1015

11-
include_directories(".")
12-
if(MSVC)
13-
include_directories("win32")
14-
file(GLOB win32_sources RELATIVE "win32" "*.c")
15-
else(MSVC)
16-
set(win32_sources, "")
17-
endif(MSVC)
16+
#-------------------------------------------------------------------------------
17+
# OPTIONS
18+
#-------------------------------------------------------------------------------
19+
option(ASSERT "turn asserts on" OFF)
20+
option(ASSERT2 "additional assertions" OFF)
21+
option(DEBUG "add debugging support" OFF)
22+
option(GPROF "add gprof support" OFF)
23+
option(GDB "add gdb support" OFF)
24+
option(GKRAND "enable GKRAND support" OFF)
25+
option(GKREGEX "enable GKREGEX support" OFF)
26+
option(OPENMP "enable OpenMP support" OFF)
27+
option(PCRE "enable PCRE support" OFF)
28+
option(VALGRID "enable valgrind support" OFF)
29+
option(NO_X86 "enable no-x86 support" OFF)
30+
option(SHARED "enable shared support" OFF)
1831

19-
add_library(GKlib ${GKlib_sources} ${win32_sources})
32+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
33+
option(GKLIB_BUILD_APPS "build the GKlib applications" ON)
34+
else()
35+
option(GKLIB_BUILD_APPS "build the GKlib applications" OFF)
36+
endif()
2037

21-
if(UNIX)
22-
target_link_libraries(GKlib m)
23-
endif(UNIX)
38+
# Configure libmetis library.
39+
if(SHARED)
40+
set(GKLIB_LIBRARY_TYPE SHARED)
41+
else()
42+
set(GKLIB_LIBRARY_TYPE STATIC)
43+
endif(SHARED)
2444

25-
include_directories("test")
26-
add_subdirectory("test")
45+
#-------------------------------------------------------------------------------
46+
# LIBRARY configuration
47+
#-------------------------------------------------------------------------------
48+
add_library(${PROJECT_NAME} ${GKLIB_LIBRARY_TYPE})
2749

28-
install(TARGETS GKlib
29-
ARCHIVE DESTINATION lib/${LINSTALL_PATH}
30-
LIBRARY DESTINATION lib/${LINSTALL_PATH})
31-
install(FILES ${GKlib_includes} DESTINATION include/${HINSTALL_PATH})
50+
target_sources(${PROJECT_NAME}
51+
PRIVATE src/b64.c src/blas.c src/cache.c src/csr.c src/error.c src/evaluate.c
52+
src/fkvkselect.c src/fs.c src/getopt.c src/gk_util.c src/gkregex.c
53+
src/graph.c src/htable.c src/io.c src/itemsets.c src/mcore.c
54+
src/memory.c src/pqueue.c src/random.c src/rw.c src/seq.c src/sort.c
55+
src/string.c src/timers.c src/tokenizer.c
56+
# these are only included below so that they appear when using IDEs
57+
include/GKlib.h include/gk_arch.h include/gk_defs.h
58+
include/gk_externs.h include/gk_getopt.h include/gk_macros.h
59+
include/gk_mkblas.h include/gk_mkmemory.h include/gk_mkpqueue.h
60+
include/gk_mkpqueue2.h include/gk_mkrandom.h include/gk_mksort.h
61+
include/gk_mkutils.h include/gk_proto.h include/gk_struct.h
62+
include/gk_types.h include/gkregex.h include/gk_ms_inttypes.h
63+
include/gk_ms_stat.h include/gk_ms_stdint.h
64+
# the following are shims for win32 systems
65+
$<$<PLATFORM_ID:Windows>:src/win32/adapt.c
66+
include/win32/adapt.h>)
67+
68+
target_compile_definitions(${PROJECT_NAME}
69+
PUBLIC $<$<PLATFORM_ID:Linux>:LINUX>)
70+
71+
target_include_directories(${PROJECT_NAME}
72+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
73+
$<INSTALL_INTERFACE:include>)
74+
75+
target_link_libraries(${PROJECT_NAME}
76+
PUBLIC $<$<NOT:$<C_COMPILER_ID:MSVC>>:m>)
77+
78+
set_target_properties(${PROJECT_NAME} PROPERTIES
79+
SOVERSION ${PROJECT_VERSION_MAJOR}
80+
VERSION ${PROJECT_VERSION})
81+
82+
add_library(GKlib::GKlib ALIAS ${PROJECT_NAME})
83+
84+
#-------------------------------------------------------------------------------
85+
# OPTIONS configuration
86+
#-------------------------------------------------------------------------------
87+
target_compile_definitions(${PROJECT_NAME}
88+
PUBLIC $<$<NOT:$<BOOL:${ASSERT}>>:NDEBUG>
89+
$<$<NOT:$<BOOL:${ASSERT2}>>:NDEBUG2>
90+
$<$<BOOL:${DEBUG}>:DEBUG>
91+
$<$<BOOL:${GKRAND}>:GKRAND>
92+
$<$<BOOL:${NO_X86}>:NO_X86>
93+
)
94+
95+
#-------------------------------------------------------------------------------
96+
# FEATURE AVAILABILITY checks
97+
#-------------------------------------------------------------------------------
98+
check_include_file(execinfo.h HAVE_EXECINFO_H)
99+
check_function_exists(getline HAVE_GETLINE)
100+
101+
# regular expressions
102+
if(PCRE)
103+
check_include_file(pcreposix.h HAVE_PCREPOSIX_H)
104+
if(NOT HAVE_PCREPOSIX_H)
105+
message(WARNING "PCRE was requested, but is not available")
106+
endif()
107+
endif()
108+
if(NOT HAVE_PCREPOSIX_H)
109+
check_include_file(regex.h HAVE_REGEX_H)
110+
if(NOT HAVE_REGEX_H)
111+
set(USE_GKREGEX ON)
112+
endif()
113+
endif()
114+
115+
# profiling support
116+
if(GPROF)
117+
check_c_compiler_flag("-pg" HAVE_GPROF_SUPPORT)
118+
if(NOT HAVE_GPROF_SUPPORT)
119+
message(WARNING "GPROF support was requested, but is not available")
120+
endif()
121+
endif()
122+
123+
# profiling support
124+
if(GDB|DEBUG)
125+
check_c_compiler_flag("-g" HAVE_GDB_SUPPORT)
126+
if(NOT HAVE_GDB_SUPPORT)
127+
message(WARNING "GDB support was requested, but is not available")
128+
endif()
129+
endif()
130+
131+
# openmp support
132+
if(OPENMP)
133+
find_package(OpenMP)
134+
if(NOT OpenMP_C_FOUND)
135+
message(WARNING "OpenMP was requested, but is not available")
136+
endif()
137+
endif()
138+
139+
# thread local storage
140+
if(NOT DEFINED HAVE_TLS)
141+
set(TLS_NAME "" CACHE INTERNAL "Thread local keyword")
142+
foreach(tls_name "__thread" "__declspec(thread)")
143+
unset(HAVE_TLS CACHE)
144+
check_c_source_compiles("${tls_name} int x; int main(void) { return 0; }"
145+
HAVE_TLS)
146+
if (HAVE_TLS)
147+
set(TLS_NAME ${tls_name} CACHE INTERNAL "Thread local keyword")
148+
break()
149+
else()
150+
endif()
151+
endforeach()
152+
endif()
153+
154+
target_compile_definitions(${PROJECT_NAME}
155+
PUBLIC $<$<BOOL:${HAVE_EXECINFO_H}>:HAVE_EXEC_INFO_H>
156+
$<$<BOOL:${PCRE}>:USE_PCRE>
157+
$<$<AND:$<BOOL:${PCRE}>,$<BOOL:${HAVE_PCREPOSIX_H}>>:HAVE_PCREPOSIX_H>
158+
$<$<BOOL:${HAVE_REGEX_H}>:HAVE_REGEX_H>
159+
$<$<BOOL:${USE_GKREGEX}>:USE_GKREGEX>
160+
$<$<BOOL:${HAVE_GETLINE}>:HAVE_GETLINE>
161+
__thread=${TLS_NAME})
162+
163+
target_compile_options(${PROJECT_NAME}
164+
PUBLIC $<$<AND:$<BOOL:${GPROF}>,$<BOOL:${HAVE_GPROF_SUPPORT}>>:-pg>)
165+
166+
target_compile_options(${PROJECT_NAME}
167+
PUBLIC $<$<AND:$<OR:$<BOOL:${DEBUG}>,$<BOOL:${GDB}>>,$<BOOL:${HAVE_GDB_SUPPORT}>>:-g>)
168+
169+
target_compile_options(${PROJECT_NAME}
170+
PUBLIC $<$<NOT:$<OR:$<BOOL:${DEBUG}>,$<BOOL:${GDB}>>>:-O3>)
171+
172+
target_link_libraries(${PROJECT_NAME}
173+
PUBLIC $<$<BOOL:${OpenMP_C_FOUND}>:OpenMP::OpenMP_C>)
174+
175+
#-------------------------------------------------------------------------------
176+
# APPS configuration
177+
#-------------------------------------------------------------------------------
178+
if(GKLIB_BUILD_APPS)
179+
add_subdirectory("apps")
180+
endif()
181+
182+
#-------------------------------------------------------------------------------
183+
# PACKAGE configuration
184+
#-------------------------------------------------------------------------------
185+
# generate files
186+
configure_package_config_file(GKlibConfig.cmake.in cmake/GKlibConfig.cmake
187+
INSTALL_DESTINATION lib/cmake/GKlib)
188+
189+
write_basic_package_version_file(cmake/GKlibConfigVersion.cmake
190+
VERSION ${PROJECT_VERSION}
191+
COMPATIBILITY SameMajorVersion)
192+
193+
# install library
194+
install(TARGETS ${PROJECT_NAME} EXPORT GKlibTargets
195+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
196+
COMPONENT GKlib_Runtime
197+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
198+
COMPONENT GKlib_Runtime
199+
NAMELINK_SKIP
200+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
201+
COMPONENT GKlib_Development
202+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
203+
204+
# The previous install() command is repeated here to distinguish installations
205+
# that include a namelink versus those that do not. Unfortunately, prior to
206+
# CMake 3.12, when the NAMELINK_COMPONENT property was introduced, this was
207+
# necessary to get the desired behavior.
208+
if(BUILD_SHARED_LIBS)
209+
install(TARGETS ${PROJECT_NAME}
210+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
211+
COMPONENT GKlib_Development
212+
NAMELINK_ONLY)
213+
endif()
214+
215+
# install header files
216+
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/"
217+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
218+
COMPONENT GKlib_Development)
219+
220+
# install files necessary to use find_package() with GKlib
221+
install(EXPORT GKlibTargets
222+
FILE GKlibTargets.cmake
223+
NAMESPACE GKlib::
224+
DESTINATION lib/cmake/GKlib
225+
COMPONENT GKlib_Development)
226+
227+
install(
228+
FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/GKlibConfig.cmake
229+
${CMAKE_CURRENT_BINARY_DIR}/cmake/GKlibConfigVersion.cmake
230+
DESTINATION lib/cmake/GKlib
231+
COMPONENT GKlib_Development)

GKlibConfig.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/GKlibTargets.cmake)

0 commit comments

Comments
 (0)