Skip to content

Commit

Permalink
improve cmake conf
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed May 18, 2020
1 parent 9915abd commit 28544d7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
63 changes: 32 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.8.2)
project(json VERSION 0.1.4 LANGUAGES C)
project(json VERSION 0.1.5 LANGUAGES C)

set(C_STANDARD 11)
set(C_STANDARD_REQUIRED YES)
set(CMAKE_C_STANDARD 11)
set(DEFAULT_BUILD_TYPE "Release")

set(JSON_BUILD)
option(JSON_SHARED "Shared build" ON)
Expand All @@ -16,49 +16,50 @@ else(JSON_STATIC)
endif()

if(JSON_USE_C99)
set(C_STANDARD 99)
set(CMAKE_C_STANDARD 99)
endif()

if(MSVC)
add_definitions(-D_WINDOWS -D_USRDLL -DJSON_EXPORTS -DJSON_DLL)
add_compile_options("/W3" "/Ox" "/Gy" "/Oi" "/TC" "/analyze")
add_compile_options(/W3 /Ox /Gy /Oi /TC)
else()
add_compile_options("-Wall" "-Werror" "-std=gnu11" "-O3")
add_compile_options(-Wall -Werror -O3 -fstrict-aliasing)
endif()

add_library(json
${JSON_BUILD}
src/json.c
)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

set_target_properties(json PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
include(GNUInstallDirs)

target_include_directories(json PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

install(
TARGETS json
EXPORT json
ARCHIVE DESTINATION lib/ COMPONENT development
LIBRARY DESTINATION lib/ COMPONENT runtime
RUNTIME DESTINATION ${CMAKE_INSTALL_NAME_DIR} COMPONENT runtime
)
# Target Start
add_library(json ${JSON_BUILD} src/json.c)

if(JSON_SHARED)
install(
TARGETS json
EXPORT json
LIBRARY DESTINATION include/ COMPONENT development
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})

target_include_directories(${PROJECT_NAME} PRIVATE include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# Install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

INSTALL(DIRECTORY include/ DESTINATION include)
install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN ".*" EXCLUDE)

# Test Configuration
if(JSON_USE_TEST)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#*****************************************************************************

AC_PREREQ([2.69])
AC_INIT([json], [0.1.4], [info@recp.me])
AC_INIT([json], [0.1.5], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])

AC_CONFIG_MACRO_DIR([m4])
Expand Down
2 changes: 1 addition & 1 deletion include/json/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

#define JSON_VERSION_MAJOR 0
#define JSON_VERSION_MINOR 1
#define JSON_VERSION_PATCH 4
#define JSON_VERSION_PATCH 5

#endif /* json_version_h */

0 comments on commit 28544d7

Please sign in to comment.