1 # Top Level CMake file for libcody.
3 cmake_minimum_required(VERSION 3.4.3)
5 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6 message(STATUS "No build type selected, default to MinSizeRel")
7 set(CMAKE_BUILD_TYPE MinSizeRel)
8 set(LIBCODY_ENABLE_ASSERTIONS 1)
10 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
12 set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
14 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
15 message(FATAL_ERROR "In-source builds are not allowed. ")
18 # message(STATUS "SRC ${CMAKE_SOURCE_DIR} CSRC : ${CMAKE_CURRENT_SOURCE_DIR} ")
20 # Add path for custom modules
23 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
24 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
26 # If we are building stand-alone, set up the names and versions.
27 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR
28 OR LIBCODY_STANDALONE_BUILD)
32 set(PACKAGE_NAME codylib)
33 set(LIBCODY_VERSION_MAJOR 0)
34 set(LIBCODY_VERSION_MINOR 0)
35 set(LIBCODY_VERSION_PATCH 1)
36 set(LIBCODY_VERSION_SUFFIX git)
37 set(LIBCODY_VERSION "${LIBCODY_VERSION_MAJOR}.${LIBCODY_VERSION_MINOR}.${LIBCODY_VERSION_PATCH}")
38 set(PACKAGE_VERSION "${LIBCODY_VERSION}-${LIBCODY_VERSION_SUFFIX}")
39 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
40 set(PACKAGE_URL "https://github.com/urnathan/libcody")
41 set(PACKAGE_BUGREPORT "https://github.com/urnathan/libcody/issues")
43 set (GIT_REV "git" "-C" "${CMAKE_CURRENT_SOURCE_DIR}" "rev-parse" "--short=12" "HEAD")
46 RESULT_VARIABLE HAD_ERROR
47 OUTPUT_VARIABLE CODY_REVISION
50 string(REGEX REPLACE "\n$" "" CODY_REVISION "${CODY_REVISION}")
51 set (GIT_CHANGES "git" "-C" "${CMAKE_CURRENT_SOURCE_DIR}" "diff-index" "--quiet" "HEAD" "--")
53 COMMAND ${GIT_CHANGES}
54 RESULT_VARIABLE MOD_ERROR
55 OUTPUT_VARIABLE MOD_OUTPUT
58 set (CODY_REVISION "${CODY_REVISION}-modified")
61 set(CODY_REVISION, "unknown")
63 set(LIBCODY_STANDALONE YES)
65 set(LIBCODY_STANDALONE NO)
69 set (CMAKE_CXX_STANDARD 11)
71 message(STATUS "git revision ${CODY_REVISION} ")
72 option(CODY_CHECKING "Enable checking" ON)
73 # Address github issue #10
74 option(CODY_WITHEXCEPTIONS "Enable exceptions" OFF)
76 if (LIBCODY_STANDALONE)
80 include(libcody-config-ix)
83 -DPACKAGE_URL="${PACKAGE_URL}"
84 -DBUGURL="${PACKAGE_BUGREPORT}"
85 -DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}"
86 -DPACKAGE_NAME="${PACKAGE_NAME}"
87 -DPACKAGE_STRING="${PACKAGE_STRING}"
88 -DPACKAGE_VERSION="${LIBCODY_VERSION}"
89 -DREVISION="${CODY_REVISION}"
92 add_definitions(-DNMS_CHECKING=1)
94 add_definitions(-DNMS_CHECKING=0)
107 if(LIBCODY_STANDALONE)
108 add_library(cody STATIC ${LIBCODY_SOURCES})
110 message(STATUS "Configured for in-tree build of libcody as LLVMcody")
111 add_llvm_component_library(LLVMcody ${LIBCODY_SOURCES})
114 if (LIBCODY_STANDALONE)
116 set_target_properties(cody PROPERTIES PUBLIC_HEADER "cody.hh")
118 LIBRARY DESTINATION lib
119 PUBLIC_HEADER DESTINATION include