Skip to content

Commit

Permalink
Implement out-of-tree build and packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
nohal committed Nov 17, 2014
1 parent e679f10 commit 6d24e32
Show file tree
Hide file tree
Showing 15 changed files with 4,017 additions and 179 deletions.
215 changes: 41 additions & 174 deletions CMakeLists.txt
@@ -1,174 +1,41 @@
##---------------------------------------------------------------------------
## Author: nohal aka. Pavel Kalian
## Copyright:
## License: wxWidgets License
##---------------------------------------------------------------------------

# define minimum cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.2)
# This should be 2.8.0 to have FindGTK2 module
IF (COMMAND cmake_policy)
CMAKE_POLICY(SET CMP0003 OLD)
CMAKE_POLICY(SET CMP0005 OLD)
CMAKE_POLICY(SET CMP0011 OLD)
ENDIF (COMMAND cmake_policy)

PROJECT(aisradar_pi)

SET(PACKAGE_NAME aisradar_pi)
SET(PLUGIN_SOURCE_DIR .)
MESSAGE (STATUS "*** Building ${PACKAGE_NAME} ***")

#SET(CMAKE_BUILD_TYPE Debug)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

# require proper c++
#ADD_DEFINITIONS( "-Wall -ansi -pedantic -Wno-variadic-macros" )
#TODO: Should we use -fno-stack-protector
# IF NOT DEBUGGING CFLAGS="-O2 -march=native"
IF(NOT WIN32)
ADD_DEFINITIONS( "-Wall -g -fexceptions -fvisibility=hidden" )

IF(NOT APPLE)
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic")
ELSE(NOT APPLE)
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl -undefined dynamic_lookup")
ENDIF(NOT APPLE)

ENDIF(NOT WIN32)

# Add some definitions to satisfy MS
IF(WIN32)
ADD_DEFINITIONS(-D__MSVC__)
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE)
ENDIF(WIN32)

IF(UNIX AND NOT APPLE)
SET(PREFIX_PLUGINS /usr/lib/opencpn)
SET(PREFIX_DATA /usr/share)
ENDIF(UNIX AND NOT APPLE)

SET(wxWidgets_USE_LIBS base core net xml html adv)
SET(BUILD_SHARED_LIBS TRUE)
FIND_PACKAGE(wxWidgets REQUIRED)

INCLUDE(${wxWidgets_USE_FILE})

FIND_PACKAGE(Gettext REQUIRED)

# For convenience we define the sources as a variable. You can add
# header files and cpp/c files and CMake will sort them out


SET(SRC_AISRADAR
src/aisradar_pi.h
src/aisradar_pi.cpp
src/aisradar.h
src/aisradar.cpp
src/my_icons.h
src/my_icons.cpp
src/Canvas.h
src/Canvas.cpp
src/Target.h
src/Target.cpp
)
ADD_LIBRARY(${PACKAGE_NAME} SHARED ${SRC_AISRADAR})

IF(WIN32)
SET(OPENCPN_IMPORT_LIB "../../${CMAKE_CFG_INTDIR}/${PARENT}")
TARGET_LINK_LIBRARIES( ${PACKAGE_NAME} ${OPENCPN_IMPORT_LIB} )
ADD_DEPENDENCIES(${PACKAGE_NAME} ${PARENT})
ENDIF(WIN32)

TARGET_LINK_LIBRARIES( ${PACKAGE_NAME} ${wxWidgets_LIBRARIES} )

IF(APPLE)
FIND_PACKAGE(ZLIB REQUIRED)
TARGET_LINK_LIBRARIES( ${PACKAGE_NAME} ${ZLIB_LIBRARIES} )
ENDIF(APPLE)

IF(APPLE)
INSTALL(TARGETS ${PACKAGE_NAME} RUNTIME LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/OpenCPN.app/Contents/SharedSupport/plugins)
ENDIF(APPLE)

IF(UNIX AND NOT APPLE)
INSTALL(TARGETS ${PACKAGE_NAME} RUNTIME LIBRARY DESTINATION ${PREFIX_PLUGINS})
ENDIF(UNIX AND NOT APPLE)

IF(WIN32)
INSTALL(TARGETS ${PACKAGE_NAME} RUNTIME DESTINATION "plugins")
ENDIF(WIN32)

# find src/ -name \*.cpp -or -name \*.c -or -name \*.h -or -name \*.hpp >po/POTFILES.in
FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
IF (GETTEXT_XGETTEXT_EXECUTABLE)
ADD_CUSTOM_COMMAND(
OUTPUT po/${PACKAGE_NAME}.pot.dummy
COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} --force-po --package-name=${PACKAGE_NAME} --package-version="${PACKAGE_VERSION}" --output=po/${PACKAGE_NAME}.pot --keyword=_ --width=80 --files-from=${CMAKE_CURRENT_SOURCE_DIR}/po/POTFILES.in
DEPENDS po/POTFILES.in po/${PACKAGE_NAME}.pot
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "aisradar-pot-update [${PACKAGE_NAME}]: Generated pot file."
)
ADD_CUSTOM_TARGET(aisradar-pot-update COMMENT "aisradar-pot-update: Done." DEPENDS po/${PACKAGE_NAME}.pot.dummy)

ENDIF(GETTEXT_XGETTEXT_EXECUTABLE )

MACRO(GETTEXT_UPDATE_PO _potFile)
SET(_poFiles ${_potFile})
GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)

FOREACH (_currentPoFile ${ARGN})
GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
GET_FILENAME_COMPONENT(_poBasename ${_absFile} NAME_WE)

ADD_CUSTOM_COMMAND(
OUTPUT ${_absFile}.dummy
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --width=80 --strict --quiet --update --backup=none --no-location -s ${_absFile} ${_absPotFile}
DEPENDS ${_absPotFile} ${_absFile}
COMMENT "aisradar-po-update [${_poBasename}]: Updated po file."
)

SET(_poFiles ${_poFiles} ${_absFile}.dummy)

ENDFOREACH (_currentPoFile )

ADD_CUSTOM_TARGET(aisradar-po-update COMMENT "aisradar-po-update: Done." DEPENDS ${_poFiles})
ENDMACRO(GETTEXT_UPDATE_PO)

IF (GETTEXT_MSGMERGE_EXECUTABLE)
FILE(GLOB PACKAGE_PO_FILES po/*.po)
GETTEXT_UPDATE_PO(po/${PACKAGE_NAME}.pot ${PACKAGE_PO_FILES})
ENDIF(GETTEXT_MSGMERGE_EXECUTABLE)

SET(_gmoFiles)
MACRO(GETTEXT_BUILD_MO)
FOREACH (_poFile ${ARGN})
GET_FILENAME_COMPONENT(_absFile ${_poFile} ABSOLUTE)
GET_FILENAME_COMPONENT(_poBasename ${_absFile} NAME_WE)
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_poBasename}.mo)

ADD_CUSTOM_COMMAND(
OUTPUT ${_gmoFile}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_absFile}
DEPENDS ${_absFile}
COMMENT "aisradar-i18n [${_poBasename}]: Created mo file."
)

If(APPLE)
INSTALL(FILES ${_gmoFile} DESTINATION ${CMAKE_BINARY_DIR}/OpenCPN.app/Contents/Resources/${_poBasename}.lproj RENAME opencpn-${PACKAGE_NAME}.mo )
ELSE(APPLE)
INSTALL(FILES ${_gmoFile} DESTINATION ${PREFIX_DATA}/locale/${_poBasename}/LC_MESSAGES RENAME opencpn-${PACKAGE_NAME}.mo )
ENDIF(APPLE)
SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
ENDFOREACH (_poFile )
ENDMACRO(GETTEXT_BUILD_MO)

if(GETTEXT_MSGFMT_EXECUTABLE)
FILE(GLOB PACKAGE_PO_FILES po/*.po)
GETTEXT_BUILD_MO(${PACKAGE_PO_FILES})
ADD_CUSTOM_TARGET(aisradar-i18n COMMENT "aisradar-i18n: Done." DEPENDS ${_gmoFiles})
#ADD_DEPENDENCIES(aisradar-i18n ${PACKAGE_PO_FILES})
ADD_DEPENDENCIES(${PACKAGE_NAME} aisradar-i18n)
ENDIF(GETTEXT_MSGFMT_EXECUTABLE)

##---------------------------------------------------------------------------
## Author: nohal aka. Pavel Kalian
## Copyright:
## License: wxWidgets License
##---------------------------------------------------------------------------

# define minimum cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.2)

PROJECT(aisradar_pi)

SET(PACKAGE_NAME aisradar_pi)
SET(VERBOSE_NAME AISRadar)
SET(TITLE_NAME AISRadar)
SET(CPACK_PACKAGE_CONTACT "Johan Sman")

SET(VERSION_MAJOR "0")
SET(VERSION_MINOR "98")

#SET(CMAKE_BUILD_TYPE Debug)

INCLUDE("cmake/PluginConfigure.cmake")

SET(SRC_AISRADAR
src/aisradar_pi.h
src/aisradar_pi.cpp
src/aisradar.h
src/aisradar.cpp
src/my_icons.h
src/my_icons.cpp
src/Canvas.h
src/Canvas.cpp
src/Target.h
src/Target.cpp
)
ADD_LIBRARY(${PACKAGE_NAME} SHARED ${SRC_AISRADAR})

INCLUDE("cmake/PluginInstall.cmake")
INCLUDE("cmake/PluginCurl.cmake")
INCLUDE("cmake/PluginLocalization.cmake")
INCLUDE("cmake/PluginPackage.cmake")
76 changes: 76 additions & 0 deletions README.md
@@ -0,0 +1,76 @@
AIS Radar View plug-in for OpenCPN
==================================

Compiling
---------
* This plugin now builds out of the OpenCPN source tree
```
git clone https://github.com/Verezano/radar_pi.git
```

###Build:
```
mkdir radar_pi/build
cd radar_pi/build
cmake ..
cmake --build .
```
Windows note: You must place opencpn.lib into your build directory to be able to link the plugin DLL. You can get this file from your local OpenCPN build, or alternatively download from http://sourceforge.net/projects/opencpnplugins/files/opencpn_lib/

Debugging:
If you check out the plugin source into the plugins subdirectory of your OpenCPN source tree, you can build it as part of it.

Windows Specific Libraries
--------------------------

Under windows, you must find the file "opencpn.lib" (Visual Studio) or "libopencpn.dll.a" (mingw) which is built in the build directory after compiling opencp

###Creating a package
Linux
```
make package
```

Windows
```
cmake --build . --config release --target package
```

###Build on Mac OS X:
Tools: Can be installed either manually or from Homebrew (http://brew.sh)
```
#brew install git #If I remember well, it is already available on the system
brew install cmake
brew install gettext
ln -s /usr/local/Cellar/gettext/0.19.2/bin/msgmerge /usr/local/bin/msgmerge
ln -s /usr/local/Cellar/gettext/0.19.2/bin/msgfmt /usr/local/bin/msgfmt
```

To target older OS X versions than the one you are running, you need the respective SDKs installed. The easiest way to achieve that is using https://github.co

####Building wxWidgets
(do not use wxmac from Homebrew, it is not compatible with OpenCPN)
Get wxWidgets 3.0.x source from http://wxwidgets.org
Configure, build and install
```
cd wxWidgets-3.0.2
./configure --enable-unicode --with-osx-cocoa --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7
make
sudo make install
```

####Building the plugin
Before running cmake, you must set the deployment target to OS X 10.7 to be compatible with the libraries used by core OpenCPN
```
export MACOSX_DEPLOYMENT_TARGET=10.7
```

####Packaging on OS X
Get and install the Packages application from http://s.sudre.free.fr/Software/Packages/about.html
```
make create-pkg
```

License
-------
The plugin code is licensed under the terms of the GPL v2 or, at your convenience, later version.

0 comments on commit 6d24e32

Please sign in to comment.