Skip to content

build: introduce CMake based build #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[[
This source file is part of the DocC open source project

Copyright (c) 2024 Apple Inc. and the DocC project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

cmake_minimum_required(VERSION 3.24)

project(LMDB
LANGUAGES C)

# Set the build artifact directories to ensure that the generated products are
# colocated and findable for wiring up into the test suites across repositories.
# This pattern is applied to all Swift and LLVM repositories.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use GNUInstallDirs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly laziness, but that's easy to adopt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why would we use GNUInstallDirs here? This is the build tree, not the install tree.

Copy link
Member

@etcwilde etcwilde Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, fair enough. Do these need to go in special directories then? The build directory locations should all be set in the LMDB config file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no need to go into special directories. We don't really have any install rules for this module (I can add them if you feel like they are important).

The build directory locations should be handled by CMake - we don't define the imported locations, that is generated by CMake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel a tad weird about projects poking directly into another project's build directory (unless they're using the *Config.cmake file to get the appropriate locations and layouts), but I'll accept it for now since the rest of the Swift ecosystem does this.

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
16 changes: 16 additions & 0 deletions Sources/CLMDB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[[
This source file is part of the DocC open source project

Copyright (c) 2024 Apple Inc. and the DocC project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(CLMDB
mdb.c
midl.c)
target_include_directories(CLMDB PUBLIC
include)

set_property(GLOBAL APPEND PROPERTY LMDB_EXPORTS CLMDB)
4 changes: 4 additions & 0 deletions Sources/CLMDB/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

module CLMDB {
header "lmdb.h"
}
10 changes: 10 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[[
This source file is part of the DocC open source project

Copyright (c) 2024 Apple Inc. and the DocC project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_subdirectory(CLMDB)
19 changes: 19 additions & 0 deletions cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[[
This source file is part of the DocC open source project

Copyright (c) 2024 Apple Inc. and the DocC project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

set(LMDB_EXPORTS_FILE
${CMAKE_CURRENT_BINARY_DIR}/LMDBExports.cmake)
configure_file(LMDBConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LMDBConfig.cmake)

get_property(LMDB_EXPORTS GLOBAL PROPERTY LMDB_EXPORTS)
export(TARGETS ${LMDB_EXPORTS}
NAMESPACE LMDB::
FILE ${LMDB_EXPORTS_FILE}
EXPORT_LINK_INTERFACE_LIBRARIES)
12 changes: 12 additions & 0 deletions cmake/modules/LMDBConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[[
This source file is part of the DocC open source project

Copyright (c) 2024 Apple Inc. and the DocC project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

if(NOT TARGET LMDB::CLMDB)
include("@LMDB_EXPORTS_FILE@")
endif()