Skip to content

Commit

Permalink
Merge pull request #623 from scratchcpp/cmake_install
Browse files Browse the repository at this point in the history
Configure CMake installation
  • Loading branch information
adazem009 authored Jan 28, 2025
2 parents e60f7c0 + 491aa7b commit 86b7b22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
33 changes: 19 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_library(scratchcpp SHARED)
add_subdirectory(src)
include_directories(src) # TODO: Remove this line
include_directories(include)
install(TARGETS scratchcpp DESTINATION lib)

target_sources(scratchcpp
PUBLIC
Expand Down Expand Up @@ -66,31 +67,28 @@ target_sources(scratchcpp
include/scratchcpp/test/scriptbuilder.h
)

if(LIBSCRATCHCPP_PRINT_LLVM_IR)
target_compile_definitions(scratchcpp PRIVATE PRINT_LLVM_IR)
endif()

include(FetchContent)
set(ZIP_SRC thirdparty/zip/src)
set(UTFCPP_SRC thirdparty/utfcpp/source)

add_library(zip SHARED
${ZIP_SRC}/zip.c
${ZIP_SRC}/zip.h
${ZIP_SRC}/miniz.h
)
target_include_directories(scratchcpp PUBLIC ${ZIP_SRC})
# zip
include(build/zip.cmake)
target_link_libraries(scratchcpp PRIVATE zip)

# utfcpp
set(UTFCPP_SRC thirdparty/utfcpp/source)
target_include_directories(scratchcpp PUBLIC ${UTFCPP_SRC})

# spimpl
include_directories(thirdparty/spimpl)

# JSON
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(json)

target_link_libraries(scratchcpp PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(scratchcpp PRIVATE zip)

# Audio
target_link_libraries(scratchcpp PRIVATE scratchcpp-audio)

# Network
if (LIBSCRATCHCPP_NETWORK_SUPPORT)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 225b7454877805f089b3895260438e929bd6d123) # 09-22-2024
Expand All @@ -99,16 +97,23 @@ if (LIBSCRATCHCPP_NETWORK_SUPPORT)
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_NETWORK_SUPPORT)
endif()

# LLVM
include(build/HunterPackages.cmake)
include(build/LLVM.cmake)
target_link_libraries(scratchcpp PRIVATE LLVM)

if(LIBSCRATCHCPP_PRINT_LLVM_IR)
target_compile_definitions(scratchcpp PRIVATE PRINT_LLVM_IR)
endif()

# Macros
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_LIBRARY)
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION="${PROJECT_VERSION}")
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_MINOR=${PROJECT_VERSION_MINOR})
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_PATCH=${PROJECT_VERSION_PATCH})

# Unit tests
if (LIBSCRATCHCPP_BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(test)
Expand Down
10 changes: 10 additions & 0 deletions build/zip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(ZIP_SRC ${PROJECT_SOURCE_DIR}/thirdparty/zip/src)

add_library(zip SHARED
${ZIP_SRC}/zip.c
${ZIP_SRC}/zip.h
${ZIP_SRC}/miniz.h
)

target_include_directories(zip PUBLIC ${ZIP_SRC})
install(TARGETS zip DESTINATION lib)

0 comments on commit 86b7b22

Please sign in to comment.