From 71227c16b0874d0dd9ba9dc988bbbcd96c7752db Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Fri, 10 Jul 2015 16:24:09 -0400 Subject: [PATCH] Start using CMake for building --- CMakeLists.txt | 108 +++++++++++++++++++++++++++++++++++++ Makefile | 114 +++++----------------------------------- cmake.sh | 13 +++++ cmake/FindLibSSH2.cmake | 37 +++++++++++++ 4 files changed, 172 insertions(+), 100 deletions(-) create mode 100644 CMakeLists.txt create mode 100755 cmake.sh create mode 100644 cmake/FindLibSSH2.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c371925 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,108 @@ +################################################################################ +# Setup +################################################################################ +cmake_minimum_required (VERSION 3.0.2) + +project(Tyro) +include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include) + +# C++11, please +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +else() + message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") +endif() + +# wxwidgets stuff +find_package(wxWidgets COMPONENTS core base aui stc adv REQUIRED) +include("${wxWidgets_USE_FILE}") +set(wxWidgets_CONFIG_OPTIONS --static) + +#libssh2 +set(CMAKE_MODULE_PATH ${Tyro_SOURCE_DIR}/cmake) +find_package(LibSSH2 REQUIRED) +if (LIBSSH2_FOUND) + set (INCLUDE_DIRS ${INCLUDE_DIRS} ${LIBSSH2_INCLUDE_DIR}) +else (LIBSSH2_FOUND) + message ( FATAL_ERROR "Could not find LibSSH2" ) +endif (LIBSSH2_FOUND) + + +include_directories(${INCLUDE_DIRS}) + +# set some platform-specific flags +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS} -stdlib=libc++") + add_definitions(-D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_ -D__WXMAC__) +endif() + +################################################################################ +# Build +################################################################################ + +# json library +add_library(JsonLib STATIC + include/jsoncpp.cpp) + +# Build json conversion script +add_executable(json2c config/json2c.c) +add_custom_command( + TARGET JsonLib PRE_BUILD + COMMAND json2c ../config/languages.json ../config/languages_json.h languages_json + DEPENDS json2c +) +add_custom_command( + TARGET JsonLib PRE_BUILD + COMMAND json2c ../config/themes.json ../config/themes_json.h themes_json + DEPENDS json2c +) + +# base library +add_library(BaseLib STATIC + src/base/SFTP.cpp + src/settings/Config.cpp) + +# widget library +file(GLOB widget_SRC + "src/settings/*.cpp" + "src/widgets/*.cpp" +) +add_library(WidgetLib STATIC ${widget_SRC}) +#add_dependencies(WidgetLib BaseLib JsonLib) +target_link_libraries(WidgetLib JsonLib) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(MACOSX_BUNDLE_ICON_FILE, ${PROJECT_SOURCE_DIR}/resources/platform/osx/tyro.icns) + set(MACOSX_BUNDLE_INFO_PLIST, ${PROJECT_SOURCE_DIR}/resources/platform/osx/Info.plist) + add_executable(Tyro MACOSX_BUNDLE + src/TyroApp.cpp) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + add_executable(Tyro WIN32 + resources/platform/msw/resource.rc + src/TyroApp.cpp) +else() + add_executable(Tyro + src/TyroApp.cpp) +endif() + +#link it all +target_link_libraries(Tyro JsonLib BaseLib WidgetLib "${wxWidgets_LIBRARIES}" "${Libssh2_LIBRARIES}") + +################################################################################ +# Tests +################################################################################ +enable_testing(true) + +file(GLOB test_SRC + "tests/main.cpp" + "tests/*Test.cpp" +) +add_executable(test_runner ${test_SRC}) + +target_link_libraries(test_runner BaseLib WidgetLib "${wxWidgets_LIBRARIES}" "${Libssh2_LIBRARIES}") + diff --git a/Makefile b/Makefile index da0cc07..294adc5 100644 --- a/Makefile +++ b/Makefile @@ -1,104 +1,22 @@ -SOURCES = $(wildcard include/**/*.cpp include/*.cpp src/base/*.cpp) -OBJECTS = $(patsubst %.cpp,%.o, $(SOURCES)) -BASE_LIB = build/base.a - -JSON_FILES = $(patsubst config/%.json,%.json, $(wildcard config/*.json)) - -PROGRAM_SRC = $(wildcard src/*.cpp) PROGRAM = build/Tyro -CONFIG_SRC = $(wildcard src/settings/*.cpp) -CONFIG_OBJ = $(patsubst %.cpp,%.o, $(CONFIG_SRC)) -CONFIG_LIB = build/config.a - -WIDGET_SRC = $(wildcard src/settings/*.cpp src/widgets/*.cpp src/base/widget/*.cpp) -WIDGET_OBJ = $(patsubst %.cpp,%.o, $(WIDGET_SRC)) -WIDGET_LIB = build/widget.a - WX_RES = $(shell wx-config --rescomp) WX_CXXFLAGS = $(shell wx-config --cxxflags) -INC_FLAGS = -Iinclude -I. -I/usr/local/include -DEV_CXXFLAGS = -O0 -g -Wall -Wextra -pipe -DDEBUG $(INC_FLAGS) -CXXFLAGS += -Os -pipe -DNDEBUG $(INC_FLAGS) - -TEST_SRC = $(wildcard tests/*Test.cpp) -TESTS = $(patsubst %.cpp,%.o,$(TEST_SRC)) -TEST_RUNNER = tests/runner - -LDLIBS = +TEST_RUNNER = build/test_runner OS ?= $(shell uname -s) -# Get static version of libs to link to on platforms that support it -ifneq ($(OS),Linux) - WX_LDLIBS = $(shell wx-config --static --libs base core aui stc adv) -else - WX_LDLIBS = $(shell wx-config --libs base core aui stc adv) -endif -# Platform compiler flags -ifeq ($(OS),Darwin) - CXX = $(shell wx-config --cxx) -D__WXMAC__ -D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_ -std=gnu++11 - LDLIBS += $(shell pkg-config libssh2 --libs) -else - LDLIBS += -lssh2 -endif +all: + ./cmake.sh Tyro -ifeq ($(OS),Windows_NT) - CXXFLAGS += -static - CXX += -std=gnu++11 -Wno-unknown-pragmas -Wno-missing-field-initializers -I/include -DWIN32 - LDLIBS += -L/lib -lws2_32 -lssh2 -endif -ifeq ($(OS),Linux) - CXX += -std=c++11 -Wno-unknown-pragmas -Wno-missing-field-initializers -endif - -ifdef $(DEV) -all: CXXFLAGS = $(DEV_CXXFLAGS) -endif -all: build json_wrapper $(BASE_LIB) $(WIDGET_LIB) $(PROGRAM) -ifeq ($(OS),Darwin) -all: Tyro.app -endif - -dev: DEV = true -dev: CXXFLAGS += $(DEV_CXXFLAGS) dev: all - -json_wrapper: json_wrapper_build - $(foreach var, $(JSON_FILES), config/json2c config/$(var) $(patsubst %.json,config/%_json.h,$(var)) $(patsubst %.json,%_json,$(var));) - -json_wrapper_build: - $(CC) config/json2c.c -o config/json2c build: @mkdir -p build -$(BASE_LIB): build $(OBJECTS) - ar rcs $@ $(OBJECTS) - ranlib $@ - - -$(CONFIG_LIB): build - $(foreach var, $(CONFIG_SRC), $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) -c -o $(patsubst %.cpp,%.o,$(var)) $(var);) - ar rcs $@ $(CONFIG_OBJ) - ranlib $@ - - -$(WIDGET_LIB): build $(CONFIG_LIB) - $(foreach var, $(WIDGET_SRC), $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) -c -o $(patsubst %.cpp,%.o,$(var)) $(var);) - ar rcs $@ $(WIDGET_OBJ) - ranlib $@ - - -$(PROGRAM): $(WIDGET_LIB) - $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) $(PROGRAM_SRC) $(WIDGET_LIB) $(CONFIG_LIB) $(BASE_LIB) $(WX_LDLIBS) $(LDLIBS) -o $(PROGRAM) - - -lib: $(OBJECTS) $(BASE_LIB) $(CONFIG_LIB) $(WIDGET_LIB) - run: ifneq ($(OS),Darwin) ./$(PROGRAM) @@ -116,7 +34,6 @@ run-grind: valgrind $(PROGRAM) # Make optimized and striped executable -release: DEV= ifeq ($(OS),Darwin) release: all endif @@ -154,26 +71,23 @@ endif cp resources/platform/osx/tyro.icns build/Tyro.app/Contents/Resources/ -$(TESTS): - $(foreach var, $(TEST_SRC), $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) -c -o $(patsubst %.cpp,%.o,$(var)) $(var);) - -.PHONY: tests -tests: $(TESTS) json_wrapper $(BASE_LIB) $(WIDGET_LIB) - $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) tests/main.cpp $(TESTS) $(WIDGET_LIB) $(BASE_LIB) $(LDLIBS) $(WX_LDLIBS) -o tests/runner - +$(TEST_RUNNER): + ./cmake.sh test_runner run-tests: tests - ./tests/runner + +tests: $(TEST_RUNNER) + ./build/test_runner + + + +tests-verbose: $(TEST_RUNNER) + ./build/test_runner -s clean: rm -f *.res rm -f config/json2c rm -f config/json2c.exe rm -f config/*_json.h - rm -rf *.o - rm -rf build - rm -rf $(OBJECTS) $(TESTS) - rm -f tests/runner - find . -name "*.gc*" -exec rm {} \; - rm -rf `find . -name "*.dSYM" -print` + rm -rf build/* mkdir -p build diff --git a/cmake.sh b/cmake.sh new file mode 100755 index 0000000..ba61685 --- /dev/null +++ b/cmake.sh @@ -0,0 +1,13 @@ +#!/bin/sh +mkdir -p build + +unset MACOSX_DEPLOYMENT_TARGET +unset CMAKE_OSX_SYSROOT + +export MACOSX_DEPLOYMENT_TARGET="10.7" +export CMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" + +cd build +cmake .. +make "$@" +cd .. \ No newline at end of file diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake new file mode 100644 index 0000000..c6467c0 --- /dev/null +++ b/cmake/FindLibSSH2.cmake @@ -0,0 +1,37 @@ +# - Try to find the libssh2 library +# Once done this will define +# +# LIBSSH2_FOUND - system has the libssh2 library +# LIBSSH2_INCLUDE_DIR - the libssh2 include directory +# LIBSSH2_LIBRARY - the libssh2 library name + +if (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY) + set(LibSSH2_FIND_QUIETLY TRUE) +endif (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY) + +FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h +) + +FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 +) + +if (LIBSSH2_INCLUDE_DIR) + file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" libssh2_version_str REGEX "^#define[\t ]+LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9][0-9][0-9].*") + + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MAJOR "${libssh2_version_str}") + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MINOR "${libssh2_version_str}") + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_PATCH "${libssh2_version_str}") + + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MAJOR "${LIBSSH2_VERSION_MAJOR}") + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MINOR "${LIBSSH2_VERSION_MINOR}") + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_PATCH "${LIBSSH2_VERSION_PATCH}") + + set(LIBSSH2_VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}") +endif (LIBSSH2_INCLUDE_DIR) + +MESSAGE(STATUS "Found LibSSH2 ${LIBSSH2_VERSION}: ${LIBSSH2_LIBRARY}") + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSSH2 DEFAULT_MSG LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY ) + +MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH LIBSSH2_VERSION) \ No newline at end of file