Skip to content

Commit 1fdd697

Browse files
authored
Refactor utils and external dependencies cmake setup (#58)
1 parent 3d11667 commit 1fdd697

File tree

29 files changed

+154
-11949
lines changed

29 files changed

+154
-11949
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ _deps
6262
.idea/
6363

6464
# Notebooks
65-
.ipynb_checkpoints
65+
.ipynb_checkpoints
66+
67+
# extern
68+
extern/*
69+
!extern/CMakeLists.txt

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ set_target_properties(${EXECUTABLE_NAME} PROPERTIES
3030
CXX_STANDARD_REQUIRED YES
3131
)
3232

33-
target_link_libraries(${EXECUTABLE_NAME} "${TORCH_LIBRARIES}")
33+
target_link_libraries(${EXECUTABLE_NAME} ${TORCH_LIBRARIES})
34+
35+
# External dependencies
36+
add_subdirectory("extern")
37+
38+
# Utils
39+
add_subdirectory("utils/image_io")
3440

3541
# Add tutorial sub-projects:
3642

@@ -48,12 +54,11 @@ add_subdirectory("tutorials/intermediate/bidirectional_recurrent_neural_network"
4854
add_subdirectory("tutorials/intermediate/language_model")
4955

5056
# Advanced
51-
add_subdirectory("tutorials/advanced/utils")
5257
add_subdirectory("tutorials/advanced/generative_adversarial_network")
5358
add_subdirectory("tutorials/advanced/variational_autoencoder")
5459
add_subdirectory("tutorials/advanced/neural_style_transfer")
5560

5661
if(MSVC)
5762
include(copy_torch_dlls)
5863
copy_torch_dlls(${EXECUTABLE_NAME})
59-
endif(MSVC)
64+
endif()

cmake/cpplint.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ execute_process(COMMAND ${CPPLINT_COMMAND}
2222
"--linelength=120"
2323
"--recursive"
2424
"--filter=-build/include_subdir,-build/include_what_you_use"
25-
"--exclude=tutorials/advanced/utils/include/external/*"
2625
"main.cpp"
2726
"tutorials"
27+
"utils"
2828
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/..")

extern/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
2+
3+
project(extern VERSION 1.0.0 LANGUAGES CXX)
4+
5+
include(FetchContent)
6+
7+
FetchContent_Declare(
8+
extern_cxxopts
9+
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
10+
GIT_TAG v2.2.0
11+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cxxopts
12+
)
13+
14+
set(CXXOPTS_CXX_STANDARD 14)
15+
set(CXXOPTS_BUILD_EXAMPLES OFF CACHE BOOL "Set to ON to build examples" FORCE)
16+
set(CXXOPTS_BUILD_TESTS OFF CACHE BOOL "Set to ON to build tests" FORCE)
17+
set(CXXOPTS_ENABLE_INSTALL OFF CACHE BOOL "Generate the install target" FORCE)
18+
19+
FetchContent_MakeAvailable(extern_cxxopts)
20+
21+
foreach(STB_IMAGE_LIB "stb_image" "stb_image_write" "stb_image_resize")
22+
FetchContent_Declare(
23+
extern_${STB_IMAGE_LIB}
24+
URL https://raw.githubusercontent.com/nothings/stb/master/${STB_IMAGE_LIB}.h
25+
DOWNLOAD_NO_EXTRACT ON
26+
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${STB_IMAGE_LIB}
27+
)
28+
FetchContent_MakeAvailable(extern_${STB_IMAGE_LIB})
29+
30+
string(REPLACE "_" "-" LIB_NAME ${STB_IMAGE_LIB})
31+
32+
add_library(${LIB_NAME} INTERFACE)
33+
target_sources(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${STB_IMAGE_LIB}/${STB_IMAGE_LIB}.h)
34+
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${STB_IMAGE_LIB})
35+
endforeach()

tutorials/advanced/generative_adversarial_network/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set(EXECUTABLE_NAME generative-adversarial-network)
1212
add_executable(${EXECUTABLE_NAME})
1313
target_sources(${EXECUTABLE_NAME} PRIVATE main.cpp)
1414

15-
target_link_libraries(${EXECUTABLE_NAME} "${TORCH_LIBRARIES}" save-image)
15+
target_link_libraries(${EXECUTABLE_NAME} ${TORCH_LIBRARIES} image-io)
1616

1717
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
1818
CXX_STANDARD 14

tutorials/advanced/generative_adversarial_network/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <torch/torch.h>
33
#include <iostream>
44
#include <iomanip>
5-
#include "save_image.h"
5+
#include "image_io.h"
66

7-
using image_utils::save_image;
7+
using image_io::save_image;
88

99
int main() {
1010
std::cout << "Generative Adversarial Network\n\n";

tutorials/advanced/neural_style_transfer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target_sources(${EXECUTABLE_NAME} PRIVATE src/main.cpp
1616
)
1717
target_include_directories(${EXECUTABLE_NAME} PRIVATE include)
1818

19-
target_link_libraries(${EXECUTABLE_NAME} "${TORCH_LIBRARIES}" save-image load-image)
19+
target_link_libraries(${EXECUTABLE_NAME} ${TORCH_LIBRARIES} image-io)
2020

2121
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
2222
CXX_STANDARD 14

tutorials/advanced/neural_style_transfer/src/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#include <iomanip>
55
#include <fstream>
66
#include "vggnet.h"
7-
#include "load_image.h"
8-
#include "save_image.h"
7+
#include "image_io.h"
98

10-
using image_utils::load_image;
11-
using image_utils::save_image;
9+
using image_io::load_image;
10+
using image_io::save_image;
1211

1312
void print_sizes(torch::Tensor);
1413

tutorials/advanced/utils/CMakeLists.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)