setup cmake

This commit is contained in:
Mans Ziesel 2024-04-28 19:04:57 +02:00
parent 59b14fd9c8
commit 4c8d755e49
7 changed files with 50 additions and 50 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.exe
passgen
.cache/
build*

18
CMakeLists.txt Normal file
View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.29)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_EXE_LINKER_FLAGS "-static")
project(Passgen
VERSION 1.0
DESCRIPTION "Passphrase generator"
LANGUAGES CXX)
add_executable(passgen
passgen.cpp
)
target_include_directories(passgen
PRIVATE
${CMAKE_SOURCE_DIR}/include/
)

View File

@ -1,45 +0,0 @@
TARGETS = passgen
BINARYOUT_TARGETS = passgen.o
CPPFLAGS += -I./include
CXXFLAGS += -O2
ifeq ($(OS),Windows_NT)
CC = x86_64-w64-mingw32-g++
LD = x86_64-w64-mingw32-g++
EXE_EXT = .exe
INSTALL_DIR = /usr/local/bin # Change this to your desired installation directory
else
CC = g++
LD = g++
EXE_EXT =
INSTALL_DIR = /usr/local/bin # Change this to your desired installation directory
endif
all: $(TARGETS)$(EXE_EXT)
run:
./passgen$(EXE_EXT)
clean:
rm -f *.o *.exe $(TARGETS) $(BINARYOUT_TARGETS)
passgen.exe: passgen.o
$(LD) -static-libgcc -static-libstdc++ passgen.o -o passgen.exe
passgen: passgen.o
$(LD) passgen.o -o passgen
passgen.o: passgen.cpp ./include/pcg_random.hpp \
./include/pcg_extras.hpp ./include/pcg_uint128.hpp
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o passgen.o passgen.cpp
install: $(TARGETS)$(EXE_EXT)
@mkdir -p $(INSTALL_DIR)
cp $(TARGETS)$(EXE_EXT) $(INSTALL_DIR)
@echo "Installed $(TARGETS)$(EXE_EXT) to $(INSTALL_DIR)"
uninstall:
rm -f $(INSTALL_DIR)/$(TARGETS)$(EXE_EXT)
@echo "Uninstalled $(TARGETS)$(EXE_EXT) from $(INSTALL_DIR)"

View File

@ -25,3 +25,14 @@ retrace-choice-litter-dreamt-zipping
```
This project uses the [EFF's Wordlists for Random Passphrases](https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases) and [PCG random](https://www.pcg-random.org/) to pick random words
Compiling:
Compile to linux:
```
mkdir build-linux && cd build-linux && cmake .. && make
```
Compile to Windows:
```
mkdir build-windows && cd build-windows && cmake -DCMAKE_TOOLCHAIN_FILE=../mingw-toolchain.cmake .. && make
```

8
compile_commands.json Normal file
View File

@ -0,0 +1,8 @@
[
{
"directory": "/home/mans/dev/passgen/build-windows",
"command": "/usr/bin/c++ -I/home/mans/dev/passgen/include -o CMakeFiles/passgen.dir/passgen.cpp.o -c /home/mans/dev/passgen/passgen.cpp",
"file": "/home/mans/dev/passgen/passgen.cpp",
"output": "CMakeFiles/passgen.dir/passgen.cpp.o"
}
]

7
mingw-toolchain.cmake Normal file
View File

@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -43,11 +43,11 @@ const std::unordered_map<std::string, NoArgHandle> NoArgs {
};
const std::unordered_map<std::string, OneArgHandle> OneArgs {
{"-p", [](PassgenOptions& s, const std::string& arg) {
{"-wl", [](PassgenOptions& s, const std::string& arg) {
s.wordlist_path = arg;
s.wordlist_type = WORDLIST_CUSTOM;
}},
{"--path", [](PassgenOptions& s, const std::string& arg) {
{"--wordlist", [](PassgenOptions& s, const std::string& arg) {
s.wordlist_path = arg;
s.wordlist_type = WORDLIST_CUSTOM;
}},
@ -92,7 +92,7 @@ std::vector<std::string> getWordlist(PassgenOptions opts)
if (opts.wordlist_type != WORDLIST_CUSTOM)
{
std::stringstream ss;
if (WORDLIST_EFF_SHORT) {
if (opts.wordlist_type == WORDLIST_EFF_SHORT) {
ss.write(reinterpret_cast<const char*>(eff_short_wordlist_1_txt), eff_short_wordlist_1_txt_len);
} else {
ss.write(reinterpret_cast<const char*>(eff_large_wordlist_txt), eff_large_wordlist_txt_len);
@ -133,7 +133,7 @@ Options:
-s, --short Use the short EFF wordlist (dfault)
-l, --large Use the large EFF wordlist
--camelcase, -cc Generate passphrase in CamelCase format
-p <path>, --path <path>
-wl <path>, --wordlist <path>
Use a custom wordlist file located at <path>
-wc <count>, --wordcount <count>
Amount of words to use for passphrase, default = 5
@ -145,7 +145,7 @@ Description:
Examples:
passgen -h
passgen --short 4
passgen -p /path/to/custom_wordlist.txt --wordcount 4
passgen -wl /path/to/custom_wordlist.txt --wordcount 4
)";
return 0;
}