Skip to content

Commit

Permalink
refactor(rake): link libs from BUILD_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Nov 26, 2024
1 parent e617643 commit f3eb643
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Install Dependencies
shell: bash
run: rake libs:install --trace
run: rake libs --trace

- name: Build
shell: bash
Expand Down
8 changes: 5 additions & 3 deletions rake/_cmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
)

def tasks_for_cmake_target( target )
build_dir = "#{BUILD_DIR}/#{target.path}"
build_dir = "#{BUILD_DIR}/#{target.name}"
install_dir = "#{INSTALL_DIR}/#{target.name}"

task :rebuild => [:clean, :build]

Expand All @@ -24,13 +25,14 @@ def tasks_for_cmake_target( target )
else
config = "Debug"
end
FileUtils.mkdir_p build_dir # ensure folder exists
directory build_dir # ensure folder exists
sh "cmake -S #{target.path} -B #{build_dir}" # configure
sh "cmake --build #{build_dir} --config #{config}"
end

task :install => :build do
cmd = "cmake --install #{build_dir}"
directory install_dir # ensure folder exists
cmd = "cmake --install #{build_dir} --prefix #{install_dir}"
if BUILD_OS_LINUX or BUILD_OS_MACOS
sh "sudo #{cmd}"
else
Expand Down
29 changes: 24 additions & 5 deletions rake/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
def new_target_from_base(name, type)

target = new_empty_target(name, type)

target.includes |= FileList[
"src",
"src/ndbl",
"src/tools",
"src/tools"
]

target.includes |= FileList[
"libs",
"libs/whereami/src",
"libs/imgui",
Expand All @@ -17,14 +21,31 @@ def new_target_from_base(name, type)
"libs/gl3w",
"libs/IconFontCppHeaders",
"/usr/include/X11/mesa/GL",
"libs/cpptrace/include",
"libs/freetype/include",
"libs/googletest/include",
"libs/nativefiledialog-extended/include",
"libs/SDL/include",
"libs/freetype/include"
]

target.linker_flags |= [
"-L#{BUILD_DIR}/cpptrace",
"-L#{BUILD_DIR}/cpptrace/_deps/libdwarf-build/src/lib/libdwarf",
"-L#{BUILD_DIR}/cpptrace/_deps/zstd-build/lib",
"-L#{BUILD_DIR}/freetype",
"-L#{BUILD_DIR}/googletest/lib",
"-L#{BUILD_DIR}/nfd/src",
"-L#{BUILD_DIR}/sdl",
]

target.cxx_flags |= [
"--std=c++20",
"-fno-char8_t"
]

target.linker_flags |= [
"-lfreetype -lbz2 -lpng16 -lz -lharfbuzz -lbrotlidec",
"-lSDL2 -lSDL2main",
]

if BUILD_OS_WINDOWS
Expand All @@ -37,8 +58,6 @@ def new_target_from_base(name, type)
else
target.linker_flags |= [
"-lGL", # OpenGL
"`pkg-config freetype2 --cflags --libs`",
"`pkg-config sdl2 --cflags --libs` -lSDL2main",
"-lcpptrace -ldwarf -lz -lzstd -ldl", # see https://github.com/jeremy-rifkin/cpptrace?tab=readme-ov-file#use-without-cmake
"-lnfd",
]
Expand All @@ -61,7 +80,7 @@ def new_target_from_base(name, type)
"IMGUI_USER_CONFIG=\\\"tools/gui/ImGuiExConfig.h\\\"",
"NDBL_APP_ASSETS_DIR=\\\"#{target.asset_folder_path}\\\"",
"NDBL_APP_NAME=\\\"#{target.name}\\\"",
"NDBL_BUILD_REF=\\\"local\\\"",
"NDBL_BUILD_REF=\\\"local\\\""
]

if BUILD_OS_WINDOWS
Expand Down
12 changes: 6 additions & 6 deletions rake/libs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
require_relative "_utils"
require_relative "_cmake"

task :libs => 'libs:install'
task :libs => 'libs:build'
namespace :libs do

task :install => [
task :build => [
'install_system_deps',
# compile .a/.lib first
'freetype:install',
'googletest:install',
'freetype:build',
'googletest:build',
'nfd:install',
'cpptrace:install',
'sdl:install',
'cpptrace:build',
'sdl:build',
# then .o
'whereami:build',
'gl3w:build',
Expand Down

0 comments on commit f3eb643

Please sign in to comment.