Skip to content

Commit e3660f1

Browse files
committed
Add conan support
1 parent 92c5822 commit e3660f1

File tree

1 file changed

+84
-45
lines changed

1 file changed

+84
-45
lines changed

CMakeLists.txt

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
project(myproject CXX)
4+
5+
# Download automatically, you can also just copy the conan.cmake file
6+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
7+
message(
8+
STATUS
9+
"Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
10+
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake"
11+
"${CMAKE_BINARY_DIR}/conan.cmake")
12+
endif()
13+
14+
include(${CMAKE_BINARY_DIR}/conan.cmake)
15+
16+
add_executable(main main.cpp)
17+
target_link_libraries(main ${CONAN_LIBS})
218

319
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
420
option(CPP_STARTER_USE_QT "Enable compilation of QT sample" OFF)
@@ -7,6 +23,30 @@ option(CPP_STARTER_USE_GTKMM "Enable compilation of GTKMM sample" OFF)
723
option(CPP_STARTER_USE_IMGUI "Enable compilation of ImGui sample" OFF)
824
option(CPP_STARTER_USE_NANA "Enable compilation of Nana GUI sample" OFF)
925

26+
if(CPP_STARTER_USE_IMGUI)
27+
set(CONAN_EXTRA_REQUIRES sfml/2.5.1@bincrafters/stable)
28+
set(CONAN_EXTRA_OPTIONS sfml:shared=False sfml:graphics=True sfml:audio=False
29+
sfml:window=True libalsa:disable_python=True)
30+
endif()
31+
32+
conan_add_remote(NAME bincrafters URL
33+
https://api.bintray.com/conan/bincrafters/public-conan)
34+
35+
conan_cmake_run(
36+
REQUIRES
37+
${CONAN_EXTRA_REQUIRES}
38+
sfml/2.5.1@bincrafters/stable
39+
catch2/2.4.0@bincrafters/stable
40+
clara/1.1.4@bincrafters/stable
41+
spdlog/1.1.0@bincrafters/stable
42+
fmt/5.2.0@bincrafters/stable
43+
OPTIONS
44+
${CONAN_EXTRA_OPTIONS}
45+
BASIC_SETUP
46+
CMAKE_TARGETS
47+
BUILD
48+
missing)
49+
1050
# Link this 'library' to use the following warnings
1151
add_library(project_warnings INTERFACE)
1252

@@ -21,35 +61,37 @@ endif()
2161
if(MSVC)
2262
target_compile_options(project_warnings INTERFACE /W4)
2363
else()
24-
target_compile_options(project_warnings
25-
INTERFACE
26-
-Wall
27-
-Wextra # reasonable and standard
28-
-Wshadow # warn the user if a variable declaration shadows one from a
29-
# parent context
30-
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
31-
# non-virtual destructor. This helps catch hard to
32-
# track down memory errors
33-
-Wold-style-cast # warn for c-style casts
34-
-Wcast-align # warn for potential performance problem casts
35-
-Wunused # warn on anything being unused
36-
-Woverloaded-virtual # warn if you overload (not override) a virtual
37-
# function
38-
-Wpedantic # warn if non-standard C++ is used
39-
-Wconversion # warn on type conversions that may lose data
40-
-Wsign-conversion # warn on sign conversions
41-
-Wmisleading-indentation # warn if identation implies blocks where blocks
42-
# do not exist
43-
-Wduplicated-cond # warn if if / else chain has duplicated conditions
44-
-Wduplicated-branches # warn if if / else branches have duplicated code
45-
-Wlogical-op # warn about logical operations being used where bitwise were
46-
# probably wanted
47-
-Wnull-dereference # warn if a null dereference is detected
48-
-Wuseless-cast # warn if you perform a cast to the same type
49-
-Wdouble-promotion # warn if float is implicit promoted to double
50-
-Wformat=2 # warn on security issues around functions that format output
51-
# (ie printf)
52-
)
64+
target_compile_options(
65+
project_warnings
66+
INTERFACE -Wall
67+
-Wextra # reasonable and standard
68+
-Wshadow # warn the user if a variable declaration shadows one
69+
# from a parent context
70+
-Wnon-virtual-dtor # warn the user if a class with virtual
71+
# functions has a non-virtual destructor. This
72+
# helps catch hard to track down memory errors
73+
-Wold-style-cast # warn for c-style casts
74+
-Wcast-align # warn for potential performance problem casts
75+
-Wunused # warn on anything being unused
76+
-Woverloaded-virtual # warn if you overload (not override) a
77+
# virtual function
78+
-Wpedantic # warn if non-standard C++ is used
79+
-Wconversion # warn on type conversions that may lose data
80+
-Wsign-conversion # warn on sign conversions
81+
-Wmisleading-indentation # warn if identation implies blocks where
82+
# blocks do not exist
83+
-Wduplicated-cond # warn if if / else chain has duplicated
84+
# conditions
85+
-Wduplicated-branches # warn if if / else branches have duplicated
86+
# code
87+
-Wlogical-op # warn about logical operations being used where
88+
# bitwise were probably wanted
89+
-Wnull-dereference # warn if a null dereference is detected
90+
-Wuseless-cast # warn if you perform a cast to the same type
91+
-Wdouble-promotion # warn if float is implicit promoted to double
92+
-Wformat=2 # warn on security issues around functions that format
93+
# output (ie printf)
94+
)
5395
endif()
5496

5597
add_executable(intro main.cpp)
@@ -86,35 +128,32 @@ endif()
86128

87129
# imgui example
88130
if(CPP_STARTER_USE_IMGUI)
89-
find_package(SFML COMPONENTS graphics window system)
90131
find_package(OpenGL)
91132

92133
# imgui + sfml built as a lib, intentionally not using full warning flags
93-
add_library(imgui imgui/lib/imgui.cpp imgui/lib/imgui_draw.cpp imgui/lib/imgui-SFML.cpp)
94-
target_link_libraries(imgui INTERFACE ${SFML_LIBRARIES} ${OPENGL_gl_LIBRARY})
134+
add_library(imgui imgui/lib/imgui.cpp imgui/lib/imgui_draw.cpp
135+
imgui/lib/imgui-SFML.cpp)
136+
target_link_libraries(imgui PUBLIC CONAN_PKG::sfml ${OPENGL_gl_LIBRARY})
95137

96138
# imgui test executable, with full warnings enabled
97139
add_executable(test_imgui imgui/test.cpp)
98140
target_link_libraries(test_imgui PRIVATE project_warnings imgui)
99-
target_include_directories(test_imgui PRIVATE ${SFML_INCLUDE_DIR})
100141
endif()
101142

102143
# Nana
103144
if(CPP_STARTER_USE_NANA)
104145
include(ExternalProject)
105-
externalproject_add(Nana
106-
GIT_REPOSITORY
107-
https://github.com/cnjinhao/nana.git
108-
GIT_TAG
109-
v1.5.6
110-
CMAKE_CACHE_ARGS
111-
"-DNANA_CMAKE_SHARED_LIB"
112-
INSTALL_COMMAND
113-
"")
146+
ExternalProject_Add(
147+
Nana
148+
GIT_REPOSITORY https://github.com/cnjinhao/nana.git
149+
GIT_TAG v1.5.6
150+
CMAKE_CACHE_ARGS "-DNANA_CMAKE_SHARED_LIB"
151+
INSTALL_COMMAND "")
114152

115153
# ExternalProject_Get_Property(Nana NANA_INCLUDE_DIR)
116-
externalproject_get_property(Nana SOURCE_DIR BINARY_DIR)
154+
ExternalProject_Get_Property(Nana SOURCE_DIR BINARY_DIR)
117155
add_executable(test_nana nana/main.cpp)
118156
target_include_directories(test_nana PRIVATE ${SOURCE_DIR}/include)
119-
target_link_libraries(test_nana PRIVATE ${BINARY_DIR}/libnana.so ${NANA_LINKS})
157+
target_link_libraries(test_nana PRIVATE ${BINARY_DIR}/libnana.so
158+
${NANA_LINKS})
120159
endif()

0 commit comments

Comments
 (0)