diff --git a/.travis.yml b/.travis.yml index 7576bd0..a0e9f5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2a7b290 --- /dev/null +++ b/CMakeLists.txt @@ -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") diff --git a/README b/README index a1a8cc3..f7a8cff 100644 --- a/README +++ b/README @@ -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" \ No newline at end of file diff --git a/cmake/make_uninstall.cmake b/cmake/make_uninstall.cmake new file mode 100644 index 0000000..451614e --- /dev/null +++ b/cmake/make_uninstall.cmake @@ -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()