Skip to content

Commit 586ce9b

Browse files
committed
build: duktape CMake scripts
1 parent 313abfb commit 586ce9b

File tree

3 files changed

+126
-6
lines changed

3 files changed

+126
-6
lines changed

CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,17 @@ llvm_map_components_to_libnames(llvm_libs all)
9999
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
100100
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
101101

102+
# fmt
103+
find_package(fmt REQUIRED CONFIG)
104+
102105
# Duktape
103-
set(DUKTAPE_PACKAGE_NAME duktape)
104-
if (WIN32)
105-
set(DUKTAPE_PACKAGE_NAME Duktape)
106+
find_package(duktape CONFIG)
107+
if (NOT DUKTAPE_FOUND)
108+
# Duktape doesn't nativelly support CMake.
109+
# Some config script patches use the capitalized version.
110+
find_package(Duktape REQUIRED CONFIG)
106111
endif()
107-
find_package(${DUKTAPE_PACKAGE_NAME} REQUIRED)
108112

109-
# fmt
110-
find_package(fmt REQUIRED CONFIG)
111113
unset(CMAKE_FOLDER)
112114

113115
#-------------------------------------------------

third-party/duktape/CMakeLists.txt

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
# Copyright (c) 2024 Alan de Freitas ([email protected])
7+
#
8+
# Official repository: https://github.com/cppalliance/mrdocs
9+
#
10+
#
11+
12+
#
13+
# This file is derived from the CMakeLists.txt file in the Microsoft vcpkg repository:
14+
# https://github.com/microsoft/vcpkg/blob/master/ports/duktape/CMakeLists.txt
15+
#
16+
17+
cmake_minimum_required(VERSION 3.13)
18+
19+
set(duktape_MAJOR_VERSION 2)
20+
set(duktape_MINOR_VERSION 7)
21+
set(duktape_PATCH_VERSION 0)
22+
set(duktape_VERSION ${duktape_MAJOR_VERSION}.${duktape_MINOR_VERSION}.${duktape_PATCH_VERSION})
23+
24+
option(CMAKE_VERBOSE_MAKEFILE "Create verbose makefile" OFF)
25+
option(BUILD_SHARED_LIBS "Create duktape as a shared library" OFF)
26+
27+
project(duktape VERSION ${duktape_VERSION})
28+
29+
file(GLOB_RECURSE DUKTAPE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/*.c")
30+
file(GLOB_RECURSE DUKTAPE_HEADERS "${CMAKE_CURRENT_LIST_DIR}/src/*.h")
31+
32+
add_library(duktape ${DUKTAPE_SOURCES} ${DUKTAPE_HEADERS})
33+
target_include_directories(duktape PRIVATE "${CMAKE_CURRENT_LIST_DIR}/src")
34+
set_target_properties(duktape PROPERTIES PUBLIC_HEADER "${DUKTAPE_HEADERS}")
35+
set_target_properties(duktape PROPERTIES VERSION ${duktape_VERSION})
36+
set_target_properties(duktape PROPERTIES SOVERSION ${duktape_MAJOR_VERSION})
37+
38+
if (BUILD_SHARED_LIBS)
39+
target_compile_definitions(duktape PRIVATE -DDUK_F_DLL_BUILD)
40+
endif ()
41+
42+
install(TARGETS duktape
43+
EXPORT duktapeTargets
44+
ARCHIVE DESTINATION "lib"
45+
LIBRARY DESTINATION "lib"
46+
RUNTIME DESTINATION "bin"
47+
PUBLIC_HEADER DESTINATION "include"
48+
COMPONENT dev
49+
)
50+
51+
install(EXPORT duktapeTargets
52+
FILE duktapeTargets.cmake
53+
NAMESPACE duktape::
54+
DESTINATION "share/duktape"
55+
)
56+
57+
export(PACKAGE duktape)
58+
59+
include(CMakePackageConfigHelpers)
60+
write_basic_package_version_file("${PROJECT_BINARY_DIR}/duktapeConfigVersion.cmake"
61+
COMPATIBILITY SameMajorVersion
62+
)
63+
64+
configure_file(duktapeConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/duktapeConfig.cmake" @ONLY)
65+
66+
install(FILES
67+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/duktapeConfig.cmake"
68+
"${PROJECT_BINARY_DIR}/duktapeConfigVersion.cmake"
69+
DESTINATION "share/duktape"
70+
)
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
# Copyright (c) 2024 Alan de Freitas ([email protected])
7+
#
8+
# Official repository: https://github.com/cppalliance/mrdocs
9+
#
10+
#
11+
12+
#
13+
# This file is derived from the CMakeLists.txt file in the Microsoft vcpkg repository:
14+
# https://github.com/microsoft/vcpkg/blob/master/ports/duktape/CMakeLists.txt
15+
#
16+
17+
# - Try to find duktape
18+
# Once done this will define
19+
#
20+
# DUKTAPE_FOUND - system has Duktape
21+
# DUKTAPE_INCLUDE_DIRS - the Duktape include directory
22+
# DUKTAPE_LIBRARIES - Link these to use DUKTAPE
23+
# DUKTAPE_DEFINITIONS - Compiler switches required for using Duktape
24+
#
25+
26+
find_package(PkgConfig QUIET)
27+
pkg_check_modules(PC_DUK QUIET duktape libduktape)
28+
29+
find_path(DUKTAPE_INCLUDE_DIR duktape.h
30+
HINTS ${duktape_ROOT}/include ${PC_DUK_INCLUDEDIR} ${PC_DUK_INCLUDE_DIRS}
31+
PATH_SUFFIXES duktape)
32+
33+
find_library(DUKTAPE_LIBRARY
34+
NAMES duktape libduktape
35+
HINTS ${duktape_ROOT}/lib ${duktape_ROOT}/bin ${PC_DUK_LIBDIR} ${PC_DUK_LIBRARY_DIRS})
36+
37+
include(FindPackageHandleStandardArgs)
38+
find_package_handle_standard_args(duktape REQUIRED_VARS DUKTAPE_LIBRARY DUKTAPE_INCLUDE_DIR)
39+
40+
if (DUKTAPE_FOUND)
41+
set(DUKTAPE_LIBRARIES ${DUKTAPE_LIBRARY})
42+
set(DUKTAPE_INCLUDE_DIRS ${DUKTAPE_INCLUDE_DIR})
43+
endif ()
44+
45+
MARK_AS_ADVANCED(
46+
DUKTAPE_INCLUDE_DIR
47+
DUKTAPE_LIBRARY
48+
)

0 commit comments

Comments
 (0)