Skip to content

Commit 4f2c1ba

Browse files
authored
Merge pull request #58 from compnerd/cmake
build: add CMake build system
2 parents 6fc21c0 + 21fd4ea commit 4f2c1ba

File tree

14 files changed

+267
-1
lines changed

14 files changed

+267
-1
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.15.1)
2+
3+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
4+
5+
project(IndexStoreDB
6+
LANGUAGES C CXX Swift)
7+
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
10+
set(CMAKE_CXX_EXTENSIONS NO)
11+
12+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
13+
14+
find_package(dispatch CONFIG)
15+
find_package(Foundation CONFIG)
16+
17+
include(SwiftSupport)
18+
19+
add_subdirectory(lib)
20+
add_subdirectory(Sources)
21+
add_subdirectory(cmake/modules)

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IndexStoreDB)

Sources/IndexStoreDB/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if(CMAKE_VERSION VERSION_LESS 3.16)
2+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
3+
set(CMAKE_LINK_LIBRARY_FLAG "-l")
4+
set(CMAKE_LINK_LIBRARY_SUFFIX "")
5+
endif()
6+
endif()
7+
8+
add_library(IndexStoreDB
9+
IndexStoreDB.swift
10+
SymbolLocation.swift
11+
SymbolOccurrence.swift
12+
SymbolRole.swift
13+
Symbol.swift)
14+
set_target_properties(IndexStoreDB PROPERTIES
15+
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
16+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
17+
target_link_libraries(IndexStoreDB PRIVATE
18+
Foundation
19+
CIndexStoreDB)
20+
21+
get_swift_host_arch(swift_arch)
22+
install(TARGETS IndexStoreDB
23+
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
24+
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
25+
RUNTIME DESTINATION bin)
26+
install(FILES
27+
${CMAKE_BINARY_DIR}/swift/IndexStoreDB.swiftdoc
28+
${CMAKE_BINARY_DIR}/swift/IndexStoreDB.swiftmodule
29+
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
30+
set_property(GLOBAL APPEND PROPERTY IndexStoreDB_EXPORTS IndexStoreDB)

cmake/modules/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
set(IndexStoreDB_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/IndexStoreDBExports.cmake)
3+
configure_file(IndexStoreDBConfig.cmake.in
4+
${CMAKE_CURRENT_BINARY_DIR}/IndexStoreDBConfig.cmake)
5+
6+
get_property(IndexStoreDB_EXPORTS GLOBAL PROPERTY IndexStoreDB_EXPORTS)
7+
export(TARGETS ${IndexStoreDB_EXPORTS} FILE ${IndexStoreDB_EXPORTS_FILE})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if(NOT TARGET IndexStoreDB)
2+
include(@IndexStoreDB_EXPORTS_FILE@)
3+
endif()

cmake/modules/SwiftSupport.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# Returns the current architecture name in a variable
3+
#
4+
# Usage:
5+
# get_swift_host_arch(result_var_name)
6+
#
7+
# If the current architecture is supported by Swift, sets ${result_var_name}
8+
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
9+
function(get_swift_host_arch result_var_name)
10+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
11+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
12+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
13+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
14+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
15+
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
16+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
17+
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
18+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
19+
set("${result_var_name}" "s390x" PARENT_SCOPE)
20+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
21+
set("${result_var_name}" "armv6" PARENT_SCOPE)
22+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
23+
set("${result_var_name}" "armv7" PARENT_SCOPE)
24+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
25+
set("${result_var_name}" "armv7" PARENT_SCOPE)
26+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
27+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
28+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
29+
set("${result_var_name}" "itanium" PARENT_SCOPE)
30+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
31+
set("${result_var_name}" "i686" PARENT_SCOPE)
32+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
33+
set("${result_var_name}" "i686" PARENT_SCOPE)
34+
else()
35+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
36+
endif()
37+
endfunction()

include/CIndexStoreDB/CIndexStoreDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727

2828
#ifndef INDEXSTOREDB_PUBLIC
29-
# if defined(_WIN32) && defined(_DLL)
29+
# if defined(_WIN32) && defined(_WINDLL)
3030
# if defined(CIndexStoreDB_EXPORTS)
3131
# define INDEXSTOREDB_PUBLIC __declspec(dllexport)
3232
# else

lib/CIndexStoreDB/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_library(CIndexStoreDB STATIC
2+
CIndexStoreDB.cpp)
3+
target_compile_options(CIndexStoreDB PRIVATE
4+
-fblocks)
5+
target_include_directories(CIndexStoreDB PUBLIC
6+
include)
7+
target_link_libraries(CIndexStoreDB PRIVATE
8+
dispatch
9+
Index
10+
LLVMSupport)
11+
12+
if(NOT BUILD_SHARED_LIBS)
13+
set_property(GLOBAL APPEND PROPERTY IndexStoreDB_EXPORTS CIndexStoreDB)
14+
endif()

lib/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_subdirectory(LLVMSupport)
2+
add_subdirectory(Support)
3+
add_subdirectory(Core)
4+
add_subdirectory(Database)
5+
add_subdirectory(Index)
6+
add_subdirectory(CIndexStoreDB)

lib/Core/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
add_library(Core STATIC
2+
Symbol.cpp)
3+
target_include_directories(Core PRIVATE
4+
include)
5+
target_link_libraries(Core PRIVATE
6+
Support
7+
LLVMSupport)
8+
9+
if(NOT BUILD_SHARED_LIBS)
10+
set_property(GLOBAL APPEND PROPERTY IndexStoreDB_EXPORTS Core)
11+
endif()

0 commit comments

Comments
 (0)