Skip to content

Commit

Permalink
Build with conan2
Browse files Browse the repository at this point in the history
  • Loading branch information
fpotier committed Jun 27, 2024
1 parent 21a0cda commit c51d919
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 20 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
cmake_minimum_required(VERSION 3.20)

project("Chip-8" VERSION 0.1 LANGUAGES CXX C)
project("Chip-8" VERSION 0.1 LANGUAGES CXX)

option(BUILD_SHARED_LIBS "Build shared libs" ON)
option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export Windows symbols" ON)

if (MSVC)
message(WARNING "BUILD_SHARED_LIBS can't be used with MSVC")
set(BUILD_SHARED_LIBS OFF)
endif()
find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(fmt REQUIRED)
find_package(doctest REQUIRED)
find_package(cxxopts REQUIRED)
find_package(yaml-cpp REQUIRED)

include(cmake/dependencies.cmake)
include(cmake/copy_dll.cmake)
include(cmake/compiler_flags.cmake)
include(cmake/copy_dll.cmake)
enable_testing() # needed to create the target lib/test
add_subdirectory(lib)
add_subdirectory(chip-8-sdl)
Expand Down
6 changes: 3 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Requirements:
- Cmake v3.20 or later

```console
cmake -B build
cmake --build build
```
conan install . --build=missing # on Linux, you might need to add these options -c tools.system.package_manager:mode=install -c tools.system.package_manager:sudo=True
conan build .
```
2 changes: 1 addition & 1 deletion chip-8-disassembler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ project("Chip-8 Disassembler" VERSION 0.1 LANGUAGES CXX)
add_executable(chip-8-disassembler disas.cpp)
target_include_directories(chip-8-disassembler PRIVATE ${CHIP8_INCLUDE_DIRS})
target_link_libraries(chip-8-disassembler PRIVATE chip-8 fmt::fmt)
copy_dll(chip-8-disassembler chip-8)
enable_warnings(chip-8-disassembler)
copy_dll(chip-8-disassembler "chip-8;fmt")
17 changes: 10 additions & 7 deletions chip-8-sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ add_executable(chip-8-sdl
widget/widget.cpp
)

if (WIN32)
set_target_properties(chip-8-sdl PROPERTIES WIN32_EXECUTABLE TRUE)
target_link_libraries(chip-8-sdl PRIVATE SDL2main)
endif()
target_include_directories(chip-8-sdl PRIVATE ${CHIP8_INCLUDE_DIRS} ".")
target_include_directories(chip-8-sdl SYSTEM PRIVATE "${cxxopts_SOURCE_DIR}/include")
target_link_libraries(chip-8-sdl PRIVATE chip-8 "$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,SDL2,SDL2-static>" SDL2_ttf yaml-cpp fmt::fmt)
target_link_libraries(chip-8-sdl PRIVATE
chip-8
SDL2::SDL2main
SDL2::SDL2-static
SDL2_ttf::SDL2_ttf-static
yaml-cpp
fmt::fmt
cxxopts::cxxopts
)
copy_dll(chip-8-sdl chip-8)
enable_warnings(chip-8-sdl)
copy_dll(chip-8-sdl "SDL2;SDL2_ttf;chip-8;fmt;yaml-cpp")

get_filename_component(SOUND_FILE_PATH "res/audio/beep-02.wav" ABSOLUTE)
get_filename_component(FONT_FILE_PATH "res/fonts/PressStart2P-Regular.ttf" ABSOLUTE)
configure_file(configuration.yaml.in configuration.yaml)
47 changes: 47 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps

class Chip8Recipe(ConanFile):
name = "chip-8"
version = "0.1"

author = "fpotier"
url = "https://github.com/fpotier/chip-8"
description = "Chip 8 emulator"
topics = ("chip-8", "emulator")

settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": True, "fPIC": True}

exports_sources = "CMakeLists.txt", "lib/*", "chip-8-sdl/*", "chip-8-disassembler", "cmake/*"

def requirements(self):
self.requires("sdl/2.28.3")
self.requires("sdl_ttf/2.20.2")
self.requires("fmt/10.2.1")
self.requires("doctest/2.4.11")
self.requires("yaml-cpp/0.8.0")
self.requires("cxxopts/3.0.0")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()
3 changes: 1 addition & 2 deletions lib/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ function(chip_8_test test_name)
chip8_test.cpp
)
target_include_directories(${test_name} PRIVATE ${CHIP8_INCLUDE_DIRS})
target_link_libraries(${test_name} PRIVATE chip-8 doctest)
target_link_libraries(${test_name} PRIVATE chip-8 doctest::doctest)
enable_warnings(${test_name})
copy_dll(${test_name} "chip-8;fmt")
add_test(NAME ${test_name} COMMAND ${test_name})
endfunction()

Expand Down

0 comments on commit c51d919

Please sign in to comment.