Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
language: c
compiler:
- gcc
# Change this to your needs
script: make
language: c

os:
- linux
- osx

compiler:
- gcc
- clang

env:
- BUILD_TYPE=Debug
- BUILD_TYPE=Release
- BUILD_TYPE=MinSizeRel

before_script:
- cd ${TRAVIS_BUILD_DIR}
- mkdir build && cd build
- cmake -DCMAKE_VERBOSE_MAKEFILE=FALSE -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/build/dist
..

script:
- cmake --build . --config ${BUILD_TYPE} --target install
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required( VERSION 2.8.5 )

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

project(lpc21isp LANGUAGES C)

if(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FREEBSD__")
elseif(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__APPLE__")
endif()

if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_definitions(-D_GNU_SOURCE)
elseif (CMAKE_C_COMPILER_ID MATCHES "MSVC")
add_definitions(-D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_WARNINGS)
endif()


add_executable(${PROJECT_NAME}
lpc21isp.c lpc21isp.h
adprog.c adprog.h
lpcprog.c lpcprog.h
lpcterm.c lpcterm.h
)

if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
target_link_libraries(${PROJECT_NAME} winmm.lib)
endif()

#install
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})

# uninstall
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake")
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ To compile with gcc (linux, cygwin, ...)
make -f Makefile.gnu clean all
- Run (if you want to use gmake and gcc)
gmake -f Makefile.gnu clean all

CMake Project Generator
- Place your build folder anywhere, passing CMake the path. Relative or absolute.
- Some examples using a build folder under the source tree root:
- Android : "cmake -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DANDROID_ABI=armeabi-v7a .. && make"
- Android Studio : Copy repo under your project's "app" folder, add "add_subdirectory(lpc21isp)" to your CMakeLists.txt file after "cmake_minimum_required()". Generating project will build Debug/Release for all supported EABI types. ie. arm64-v8a, armeabi-v7a, x86, x86_64.
- Raspberry Pi : "cmake -DCMAKE_TOOLCHAIN_FILE=~/rpi/tools/build/cmake/rpi.toolchain.cmake .. && make"
- Linux : "cmake -GNinja .. && ninja"
- Linux Eclipse Photon (Debug) : "CC=clang cmake -G"Eclipse CDT4 - Unix Makefiles" ../lpc21isp/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_VERSION=4.8.0"
- To override the base installation directory use: CMAKE_INSTALL_PREFIX, e.g.
"CC=clang cmake -DCMAKE_INSTALL_PREFIX=./out .. && make install"
19 changes: 19 additions & 0 deletions cmake/make_uninstall.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
endif()

file(READ "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt" files)
string(REGEX REPLACE "[\r\n]" ";" files "${files}")

foreach(file ${files})
message(STATUS "Uninstalling ${file}")
if(EXISTS "${file}")
file(REMOVE ${file})
if (EXISTS "${file}")
message(FATAL_ERROR "Problem when removing ${file}, please check your permissions")
endif()
else()
message(STATUS "File ${file} does not exist.")
endif()
endforeach()