Skip to content

Commit

Permalink
🤏 Rename open_link as open
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Feb 26, 2024
1 parent 881827f commit 1c631ef
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
cmake_minimum_required(VERSION 3.8)

set(WARNINGS_AS_ERRORS_FOR_OPEN_LINK OFF CACHE BOOL "ON iff you want to treat warnings as errors")
set(WARNINGS_AS_ERRORS_FOR_OPEN OFF CACHE BOOL "ON iff you want to treat warnings as errors")

add_library(open_link)
add_library(open_link::open_link ALIAS open_link)
target_compile_features(open_link PUBLIC cxx_std_11)
add_library(open)
add_library(Cool::open ALIAS open)
target_compile_features(open PUBLIC cxx_std_11)

# ---Add source files---
if(WARNINGS_AS_ERRORS_FOR_OPEN_LINK)
target_include_directories(open_link PUBLIC include)
if(WARNINGS_AS_ERRORS_FOR_OPEN)
target_include_directories(open PUBLIC include)
else()
target_include_directories(open_link SYSTEM PUBLIC include)
target_include_directories(open SYSTEM PUBLIC include)
endif()
target_sources(open_link PRIVATE
src/open_link.cpp

target_sources(open PRIVATE
src/open.cpp
)

# Set warning level
if(MSVC)
target_compile_options(open_link PRIVATE /W4)
target_compile_options(open PRIVATE /W4)
else()
target_compile_options(open_link PRIVATE -Wall -Wextra -Wpedantic -pedantic-errors -Wconversion -Wsign-conversion -Wno-unused-result)
target_compile_options(open PRIVATE -Wall -Wextra -Wpedantic -pedantic-errors -Wconversion -Wsign-conversion -Wno-unused-result)
endif()

# Maybe enable warnings as errors
if(WARNINGS_AS_ERRORS_FOR_OPEN_LINK)
if(WARNINGS_AS_ERRORS_FOR_OPEN)
if(MSVC)
target_compile_options(open_link PRIVATE /WX)
target_compile_options(open PRIVATE /WX)
else()
target_compile_options(open_link PRIVATE -Werror)
target_compile_options(open PRIVATE -Werror)
endif()
endif()
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# open_link
# open

Open any link, folder or file. Cross-platform.

## Including

To add this library to your project, simply add these two lines to your _CMakeLists.txt_:

```cmake
add_subdirectory(path/to/open_link)
target_link_libraries(${PROJECT_NAME} PRIVATE open_link::open_link)
add_subdirectory(path/to/open)
target_link_libraries(${PROJECT_NAME} PRIVATE Cool::open)
```

Then include it as:

```cpp
#include <open_link/open_link.hpp>
#include <open/open.hpp>
```

## Example

```cpp
Cool::open_link("https://github.com/CoolLibs/open_link");
Cool::open("https://github.com/CoolLibs/open");
```
## Running the tests
Expand Down
8 changes: 8 additions & 0 deletions include/open/open.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace Cool {

/// Opens the link in the user's default web browser, or the folder in the folder explorer, or the file in the default configured software.
void open(const char* link);

} // namespace Cool
8 changes: 0 additions & 8 deletions include/open_link/open_link.hpp

This file was deleted.

8 changes: 4 additions & 4 deletions src/open_link.cpp → src/open.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <open_link/open_link.hpp>
#include <open/open.hpp>

// Thanks to https://stackoverflow.com/questions/17347950/how-do-i-open-a-url-from-c

Expand All @@ -9,7 +9,7 @@
#include <shellapi.h>

namespace Cool {
void open_link(const char* link)
void open(const char* link)
{
ShellExecuteA(nullptr, nullptr, link, nullptr, nullptr, SW_SHOW);
}
Expand All @@ -22,7 +22,7 @@ void open_link(const char* link)
#include <string>

namespace Cool {
void open_link(const char* link)
void open(const char* link)
{
system((std::string{"xdg-open "} + link).c_str());
}
Expand All @@ -35,7 +35,7 @@ void open_link(const char* link)
#include <string>

namespace Cool {
void open_link(const char* link)
void open(const char* link)
{
system((std::string{"open "} + link).c_str());
}
Expand Down
11 changes: 6 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(open_link-tests)
project(open-tests)

add_executable(${PROJECT_NAME} tests.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
Expand All @@ -12,14 +12,15 @@ else()
endif()

# Maybe enable warnings as errors
set(WARNINGS_AS_ERRORS_FOR_OPEN_LINK OFF CACHE BOOL "ON iff you want to treat warnings as errors")
if(WARNINGS_AS_ERRORS_FOR_OPEN_LINK)
set(WARNINGS_AS_ERRORS_FOR_OPEN OFF CACHE BOOL "ON iff you want to treat warnings as errors")

if(WARNINGS_AS_ERRORS_FOR_OPEN)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /WX)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
endif()
endif()

add_subdirectory(.. ${CMAKE_CURRENT_SOURCE_DIR}/build/open_link)
target_link_libraries(${PROJECT_NAME} PRIVATE open_link::open_link)
add_subdirectory(.. ${CMAKE_CURRENT_SOURCE_DIR}/build/open)
target_link_libraries(${PROJECT_NAME} PRIVATE Cool::open)
6 changes: 3 additions & 3 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <open_link/open_link.hpp>
#include <open/open.hpp>

// This should open the GitHub page of open_link.
// This should open the GitHub page of open.
auto main() -> int
{
Cool::open_link("https://github.com/CoolLibs/open_link");
Cool::open("https://github.com/CoolLibs/open");
}

0 comments on commit 1c631ef

Please sign in to comment.