Skip to content

Cmake fixes #47

Closed
wants to merge 4 commits into from
View
4 .gitignore
@@ -1,3 +1,7 @@
.DS_Store
Makefile
/build/
+CMakeCache.txt
+CMakeFiles
+cmake_install.cmake
+install_manifest.txt
View
19 CMakeLists.txt
@@ -28,6 +28,19 @@ ENDIF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
+OPTION(BUILD_STATIC_LIBS "Build static libraries" ON)
+
+IF (NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
+ MESSAGE(FATAL_ERROR "Either static or shared libraries has to be built")
+ENDIF (NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
+
+IF (BUILD_STATIC_LIBS)
+ SET (LINK_TARGET "yajl_s")
+ELSE (BUILD_STATIC_LIBS)
+ SET (LINK_TARGET "yajl")
+ENDIF (BUILD_STATIC_LIBS)
+
IF (WIN32)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
ADD_DEFINITIONS(-DWIN32)
@@ -64,7 +77,7 @@ ENDIF (WIN32)
ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(test EXCLUDE_FROM_ALL)
ADD_SUBDIRECTORY(reformatter)
ADD_SUBDIRECTORY(verify)
ADD_SUBDIRECTORY(example)
@@ -75,5 +88,7 @@ INCLUDE(YAJLDoc.cmake)
# a test target
ADD_CUSTOM_TARGET(test
./run_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/test/yajl_test
+ DEPENDS yajl_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
-
+ADD_CUSTOM_TARGET(check)
+ADD_DEPENDENCIES(check test)
View
2 example/CMakeLists.txt
@@ -20,4 +20,4 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(parse_config ${SRCS})
-TARGET_LINK_LIBRARIES(parse_config yajl_s)
+TARGET_LINK_LIBRARIES(parse_config ${LINK_TARGET})
View
2 perf/CMakeLists.txt
@@ -20,4 +20,4 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(perftest ${SRCS})
-TARGET_LINK_LIBRARIES(perftest yajl_s)
+TARGET_LINK_LIBRARIES(perftest ${LINK_TARGET})
View
2 reformatter/CMakeLists.txt
@@ -26,7 +26,7 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(json_reformat ${SRCS})
-TARGET_LINK_LIBRARIES(json_reformat yajl_s)
+TARGET_LINK_LIBRARIES(json_reformat ${LINK_TARGET})
# copy the binary into the output directory
GET_TARGET_PROPERTY(binPath json_reformat LOCATION)
View
31 src/CMakeLists.txt
@@ -35,15 +35,22 @@ SET (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig)
# set the output path for libraries
SET(LIBRARY_OUTPUT_PATH ${libDir})
-ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
-ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
+IF (BUILD_STATIC_LIBS)
+ ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
+ENDIF (BUILD_STATIC_LIBS)
+
+IF (BUILD_SHARED_LIBS)
+ ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
+ENDIF (BUILD_SHARED_LIBS)
#### setup shared library version number
-SET_TARGET_PROPERTIES(yajl PROPERTIES
- DEFINE_SYMBOL YAJL_SHARED
- SOVERSION ${YAJL_MAJOR}
- VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
+IF (BUILD_SHARED_LIBS)
+ SET_TARGET_PROPERTIES(yajl PROPERTIES
+ DEFINE_SYMBOL YAJL_SHARED
+ SOVERSION ${YAJL_MAJOR}
+ VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
+ENDIF (BUILD_SHARED_LIBS)
#### ensure a .dylib has correct absolute installation paths upon installation
IF(APPLE)
@@ -69,17 +76,23 @@ FOREACH (header ${PUB_HDRS})
EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})
- ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
+ IF (BUILD_STATIC_LIBS)
+ ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
+ ENDIF (BUILD_STATIC_LIBS)
ENDFOREACH (header ${PUB_HDRS})
INCLUDE_DIRECTORIES(${incDir}/..)
IF(NOT WIN32)
# at build time you may specify the cmake variable LIB_SUFFIX to handle
# 64-bit systems which use 'lib64'
- INSTALL(TARGETS yajl LIBRARY DESTINATION lib${LIB_SUFFIX})
- INSTALL(TARGETS yajl_s ARCHIVE DESTINATION lib${LIB_SUFFIX})
+ IF (BUILD_SHARED_LIBS)
+ INSTALL(TARGETS yajl LIBRARY DESTINATION lib${LIB_SUFFIX})
+ ENDIF (BUILD_SHARED_LIBS)
+ IF (BUILD_STATIC_LIBS)
+ INSTALL(TARGETS yajl_s ARCHIVE DESTINATION lib${LIB_SUFFIX})
+ ENDIF (BUILD_STATIC_LIBS)
INSTALL(FILES ${PUB_HDRS} DESTINATION include/yajl)
INSTALL(FILES ${incDir}/yajl_version.h DESTINATION include/yajl)
INSTALL(FILES ${shareDir}/yajl.pc DESTINATION share/pkgconfig)
View
2 test/CMakeLists.txt
@@ -20,4 +20,4 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(yajl_test ${SRCS})
-TARGET_LINK_LIBRARIES(yajl_test yajl_s)
+TARGET_LINK_LIBRARIES(yajl_test ${LINK_TARGET})
View
2 verify/CMakeLists.txt
@@ -26,7 +26,7 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
ADD_EXECUTABLE(json_verify ${SRCS})
-TARGET_LINK_LIBRARIES(json_verify yajl_s)
+TARGET_LINK_LIBRARIES(json_verify ${LINK_TARGET})
# copy in the binary
GET_TARGET_PROPERTY(binPath json_verify LOCATION)
Something went wrong with that request. Please try again.