Skip to content

Commit

Permalink
cmake : update to 3.19 (ggerganov#351)
Browse files Browse the repository at this point in the history
- update from 3.0 (from 2014) to 3.19 (from 2020)
- move some global setting onto the targets (through a cmake include)
  • Loading branch information
asmaloney authored Jan 5, 2023
1 parent dd6d582 commit 84c6b42
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 9 deletions.
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.19)

project(whisper.cpp VERSION 1.0.4)

set(CMAKE_EXPORT_COMPILE_COMMANDS "on")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Add path to modules
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(WHISPER_STANDALONE ON)
include(cmake/GitVars.cmake)
include(cmake/BuildTypes.cmake)
include(GitVars)
include(BuildTypes)

# configure project version
if (EXISTS "${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl")
Expand Down Expand Up @@ -82,9 +81,6 @@ endif()

# dependencies

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)

find_package(Threads REQUIRED)

# on APPLE - include Accelerate framework
Expand Down Expand Up @@ -190,6 +186,8 @@ add_library(${TARGET}
whisper.cpp
)

include(DefaultTargetOptions)

target_include_directories(${TARGET} PUBLIC
.
)
Expand Down
17 changes: 17 additions & 0 deletions cmake/DefaultTargetOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set the default compile features and properties for a target.

if (NOT TARGET)
message(FATAL_ERROR "TARGET not set before including DefaultTargetOptions")
endif()

target_compile_features(${TARGET}
PRIVATE
cxx_std_11
)

set_target_properties(${TARGET}
PROPERTIES
EXPORT_COMPILE_COMMANDS ON
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)
2 changes: 2 additions & 0 deletions examples/bench.wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_executable(${TARGET}
emscripten.cpp
)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE
whisper
)
Expand Down
3 changes: 3 additions & 0 deletions examples/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set(TARGET bench)
add_executable(${TARGET} bench.cpp)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE whisper ${CMAKE_THREAD_LIBS_INIT})
2 changes: 2 additions & 0 deletions examples/command.wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_executable(${TARGET}
emscripten.cpp
)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE
whisper
)
Expand Down
3 changes: 3 additions & 0 deletions examples/command/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ if (WHISPER_SUPPORT_SDL2)
# command
set(TARGET command)
add_executable(${TARGET} command.cpp)

include(DefaultTargetOptions)

target_include_directories(${TARGET} PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(${TARGET} PRIVATE whisper ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif ()
3 changes: 3 additions & 0 deletions examples/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set(TARGET main)
add_executable(${TARGET} main.cpp)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE whisper ${CMAKE_THREAD_LIBS_INIT})
2 changes: 2 additions & 0 deletions examples/stream.wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_executable(${TARGET}
emscripten.cpp
)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE
whisper
)
Expand Down
3 changes: 3 additions & 0 deletions examples/stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ if (WHISPER_SUPPORT_SDL2)
# stream
set(TARGET stream)
add_executable(${TARGET} stream.cpp)

include(DefaultTargetOptions)

target_include_directories(${TARGET} PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(${TARGET} PRIVATE whisper ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif ()
2 changes: 2 additions & 0 deletions examples/talk.wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ add_executable(${TARGET}
gpt-2.cpp
)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE
whisper
)
Expand Down
3 changes: 3 additions & 0 deletions examples/talk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if (WHISPER_SUPPORT_SDL2)
# TODO: this is temporary
# need to export ggml symbols for MSVC, but too lazy ..
add_executable(${TARGET} talk.cpp gpt-2.cpp ../../ggml.c ../../whisper.cpp)

include(DefaultTargetOptions)

target_include_directories(${TARGET} PRIVATE ${SDL2_INCLUDE_DIRS} ../../)
target_link_libraries(${TARGET} PRIVATE ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif ()
2 changes: 2 additions & 0 deletions examples/whisper.wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_executable(${TARGET}
emscripten.cpp
)

include(DefaultTargetOptions)

target_link_libraries(${TARGET} PRIVATE
whisper
)
Expand Down

0 comments on commit 84c6b42

Please sign in to comment.