-
Notifications
You must be signed in to change notification settings - Fork 447
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 build and test. #303
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
245dbc0
CMake build and test.
spencels 0307522
Fixed CMake issue where GLOBAL_OUTPUT_PATH was a bool.
spencels 8d68af2
Added CMake build and test to Travis.
spencels 001d585
Ignore .DS_Store
spencels f72cbdd
Use CMake 2.8.7 as the minimum version.
spencels eee81af
Fix googletest. CMake stdlib build.
spencels 678aa52
Added header files to targets.
spencels 93bf9c8
Added regression test CMake target.
spencels 9de0bd1
Merge
spencels 330e02f
Fix cmake build errors.
spencels f4a0b59
Merge branch 'master' into cmake
spencels 41a895a
Add some documentation to the CMake scripts.
spencels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Travis CI runs CMake 2.8.7 so we are pinned to that verison. | ||
cmake_minimum_required(VERSION 2.8.7) | ||
include(ExternalProject) | ||
|
||
# User-configurable options. | ||
option(BUILD_JSONNET "Build jsonnet command-line tool." ON) | ||
option(BUILD_TESTS "Build and run jsonnet tests." ON) | ||
set(GLOBAL_OUTPUT_PATH_SUFFIX "bin" CACHE STRING | ||
"Output artifacts directory.") | ||
|
||
project(jsonnet) | ||
|
||
# Discourage in-source builds because they overwrite the hand-written Makefile. | ||
# Use `cmake . -B<dir>` or the CMake GUI to do an out-of-source build. | ||
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} AND | ||
${CMAKE_GENERATOR} MATCHES "Makefile") | ||
message(WARNING "In-source builds with the a makefile generator overwrite the handwritten Makefile. Out-of-source builds are recommended for this project.") | ||
endif() | ||
|
||
|
||
# Disable CMake >3.0 warnings. | ||
set(CMAKE_MACOSX_RPATH 1) | ||
|
||
# Set output paths. | ||
set(GLOBAL_OUTPUT_PATH "${PROJECT_BINARY_DIR}/${GLOBAL_OUTPUT_PATH_SUFFIX}") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) | ||
|
||
# Include external googletest project. | ||
if (BUILD_TESTS) | ||
enable_testing() | ||
|
||
# TODO: Support manual googletest path. | ||
# Download googletest library source. | ||
set(GOOGLETEST_OUTPUT_DIR ${GLOBAL_OUTPUT_PATH}/googletest) | ||
ExternalProject_Add( | ||
googletest | ||
|
||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG "release-1.8.0" | ||
|
||
UPDATE_COMMAND "" | ||
PATCH_COMMAND "" | ||
TEST_COMMAND "" | ||
|
||
PREFIX ${PROJECT_SOURCE_DIR}/external/googletest | ||
CMAKE_ARGS -DBUILD_GTEST=ON -DBUILD_GMOCK=OFF | ||
-DCMAKE_INSTALL_PREFIX=${GOOGLETEST_OUTPUT_DIR} | ||
) | ||
|
||
# Copy googletest build outputs to global output path. | ||
ExternalProject_Add_Step( | ||
googletest copy_to_bin | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
${GOOGLETEST_OUTPUT_DIR}/lib ${GLOBAL_OUTPUT_PATH} | ||
DEPENDEES install | ||
) | ||
|
||
include_directories(${GOOGLETEST_OUTPUT_DIR}/include) | ||
set( | ||
GTEST_LIBRARY | ||
${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} | ||
) | ||
set( | ||
GTEST_MAIN_LIBRARY | ||
${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX} | ||
) | ||
endif() | ||
|
||
# Compiler flags. | ||
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR | ||
${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -std=c99") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC") | ||
else() | ||
# TODO: Windows support. | ||
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported") | ||
endif() | ||
|
||
# Look for libraries in global output path. | ||
link_directories(${GLOBAL_OUTPUT_PATH}) | ||
|
||
# Targets | ||
|
||
include_directories( | ||
include | ||
third_party/md5 | ||
core) | ||
|
||
install(DIRECTORY include DESTINATION include) | ||
|
||
add_subdirectory(third_party/md5) | ||
add_subdirectory(core) | ||
add_subdirectory(cmd) | ||
|
||
if (BUILD_TESTS) | ||
# |run_tests| target builds and runs all tests. The cmake-generated |test| | ||
# target runs tests without building them. | ||
add_custom_target(run_tests COMMAND ${CMAKE_CTEST_COMMAND} | ||
DEPENDS libjsonnet_test libjsonnet_test_file libjsonnet_test_snippet | ||
jsonnet parser_test lexer_test | ||
) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Jsonnet command-line tool. | ||
|
||
if (BUILD_JSONNET OR BUILD_TESTS) | ||
add_executable(jsonnet ${LIBJSONNET_SOURCE} jsonnet.cpp) | ||
add_dependencies(jsonnet libjsonnet_static) | ||
target_link_libraries(jsonnet libjsonnet_static) | ||
|
||
install(TARGETS jsonnet DESTINATION bin) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# libjsonnet | ||
|
||
# Remember to update Bazel and Makefile builds when updating this list! | ||
set(LIBJSONNET_SOURCE | ||
desugarer.cpp | ||
formatter.cpp | ||
lexer.cpp | ||
libjsonnet.cpp | ||
parser.cpp | ||
pass.cpp | ||
static_analysis.cpp | ||
string_utils.cpp | ||
vm.cpp) | ||
|
||
add_library(libjsonnet SHARED ${LIBJSONNET_SOURCE}) | ||
add_dependencies(libjsonnet md5) | ||
target_link_libraries(libjsonnet md5) | ||
|
||
# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without | ||
# this step the output would be |liblibjsonnet|. | ||
set_target_properties(libjsonnet PROPERTIES OUTPUT_NAME jsonnet) | ||
install(TARGETS libjsonnet DESTINATION lib) | ||
|
||
# Static library for jsonnet command-line tool. | ||
add_library(libjsonnet_static STATIC ${LIBJSONNET_SOURCE}) | ||
add_dependencies(libjsonnet_static md5) | ||
target_link_libraries(libjsonnet_static md5) | ||
set_target_properties(libjsonnet_static PROPERTIES OUTPUT_NAME jsonnet) | ||
|
||
# Tests | ||
|
||
function(add_test_executable test_name) | ||
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/${test_name}.cpp) | ||
set(TEST_EXT cpp) | ||
else() | ||
set(TEST_EXT c) | ||
endif() | ||
add_executable(${test_name} ${test_name}.${TEST_EXT}) | ||
|
||
add_dependencies(${test_name} libjsonnet_static googletest) | ||
target_link_libraries( | ||
${test_name} ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY} libjsonnet_static) | ||
endfunction() | ||
|
||
if (BUILD_TESTS) | ||
add_test_executable(lexer_test) | ||
add_test(lexer_test ${GLOBAL_OUTPUT_PATH}/lexer_test) | ||
|
||
add_test_executable(parser_test) | ||
add_test(parser_test ${GLOBAL_OUTPUT_PATH}/parser_test) | ||
|
||
add_test_executable(libjsonnet_test) | ||
add_test(libjsonnet_test ${GLOBAL_OUTPUT_PATH}/libjsonnet_test) | ||
|
||
add_test_executable(libjsonnet_test_file) | ||
add_test(libjsonnet_test_file | ||
${GLOBAL_OUTPUT_PATH}/libjsonnet_test_file | ||
${CMAKE_SOURCE_DIR}/test_suite/object.jsonnet) | ||
|
||
set(TEST_SNIPPET "std.assertEqual(({ x: 1, y: self.x } { x: 2 }).y, 2)") | ||
add_test_executable(libjsonnet_test_snippet) | ||
add_test(libjsonnet_test_snippet | ||
${GLOBAL_OUTPUT_PATH}/libjsonnet_test_snippet ${TEST_SNIPPET}) | ||
|
||
add_test(jsonnet_test_snippet | ||
${GLOBAL_OUTPUT_PATH}/jsonnet -e ${TEST_SNIPPET}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set(LIB_HEADER | ||
${LIB_HEADER} | ||
${CMAKE_CURRENT_SOURCE_DIR}/libjsonnet.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/libjsonnet++.h | ||
PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_library(md5 STATIC md5.cpp) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and MANIFEST.in and setup.py :(