Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Add Windows, MSVC, and MinGW support to build configuration.
Browse files Browse the repository at this point in the history
 - Set to use static or dynamic libraries at top level.
 - Compiler configuration for MSVC and MinGW.
 - Copy rather than create symlink for aliases on Windows.
  • Loading branch information
grp authored and onhachoe committed Jun 19, 2017
1 parent 183c087 commit 7a00183
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 38 deletions.
58 changes: 46 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,69 @@
project(xcbuild C CXX)

cmake_minimum_required(VERSION 3.0)
set(CMAKE_MACOSX_RPATH 1)
cmake_policy(SET CMP0054 NEW)

if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(BUILD_SHARED_LIBS True CACHE BOOL "Build shared libraries." FORCE)

# Platform options.
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
# Export all symbols to avoid needing a `.def` file or `__dllexport`.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS True)

if ("${CMAKE_CXX_PLATFORM_ID}" STREQUAL "MinGW")
# Use MinGW formatting rather than MSVCRT for C99 support.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__USE_MINGW_ANSI_STDIO=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__USE_MINGW_ANSI_STDIO=1")
endif ()
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(CMAKE_MACOSX_RPATH True)
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
else ()
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
endif ()

# Output into root build directory.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Language version.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
# C++ is by default. C99 is not supported.
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else ()
message(WARNING "Compiler not supported to enable C++11.")
endif ()

# Unused language features.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
else ()
message(WARNING "Compiler not supported to disable exceptions and RTTI.")
endif ()

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif ()

# Enable all warnings.
add_compile_options(-Wall -Werror)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wno-multichar -Wno-sign-compare)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
add_compile_options(/D_CRT_SECURE_NO_WARNINGS) # TODO: /Wall /WX
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wall -Werror)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wno-multichar -Wno-sign-compare)
endif ()
else ()
message(WARNING "Compiler not supported to enable warnings.")
endif ()

# Enable color diagnostics.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
add_compile_options(-fcolor-diagnostics)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER "5.0")
add_compile_options(-fdiagnostics-color)
Expand Down
2 changes: 1 addition & 1 deletion Libraries/acdriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(acdriver SHARED
add_library(acdriver
Sources/Options.cpp
Sources/Driver.cpp
Sources/Output.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(builtin SHARED
add_library(builtin
Sources/Driver.cpp
Sources/Registry.cpp
#
Expand Down
2 changes: 1 addition & 1 deletion Libraries/dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(dependency SHARED
add_library(dependency
Sources/DependencyInfo.cpp
Sources/DependencyInfoFormat.cpp
Sources/BinaryDependencyInfo.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(ext SHARED
add_library(ext
Sources/optional.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion Libraries/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(graphics SHARED
add_library(graphics
Sources/Image.cpp
Sources/PixelFormat.cpp
Sources/Format/PNG.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/libbom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(bom SHARED
add_library(bom
Sources/bom.c
Sources/bom_memory.c
Sources/bom_tree.c
Expand Down
2 changes: 1 addition & 1 deletion Libraries/libcar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(car SHARED
add_library(car
Sources/Reader.cpp
Sources/AttributeList.cpp
Sources/Facet.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(util SHARED
add_library(util
Sources/FSUtil.cpp
Sources/Filesystem.cpp
Sources/DefaultFilesystem.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/ninja/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(ninja SHARED
add_library(ninja
Sources/Writer.cpp
Sources/Value.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion Libraries/pbxbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(pbxbuild SHARED
add_library(pbxbuild
Sources/DirectedGraph.cpp
Sources/HeaderMap.cpp
Sources/DerivedDataHash.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/pbxproj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(pbxproj SHARED
add_library(pbxproj
Sources/Context.cpp
Sources/ISA.cpp
Sources/PlistHelpers.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/pbxsetting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(pbxsetting SHARED
add_library(pbxsetting
Sources/Condition.cpp
Sources/DefaultSettings.cpp
Sources/Environment.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/pbxspec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(pbxspec SHARED
add_library(pbxspec
Sources/Manager.cpp
Sources/SpecificationType.cpp
Sources/PBX/Architecture.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/plist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(plist SHARED
add_library(plist
Sources/ObjectType.cpp
Sources/Array.cpp
Sources/Boolean.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(process SHARED
add_library(process
Sources/Context.cpp
Sources/DefaultContext.cpp
Sources/MemoryContext.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcassets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcassets SHARED
add_library(xcassets
Sources/BrandAssetRole.cpp
Sources/Compression.cpp
Sources/CubeFace.cpp
Expand Down
17 changes: 12 additions & 5 deletions Libraries/xcdriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcdriver SHARED
add_library(xcdriver
Sources/Action.cpp
Sources/Driver.cpp
Sources/Options.cpp
Expand Down Expand Up @@ -39,10 +39,17 @@ add_executable(xcbuild Tools/xcbuild.cpp)
target_link_libraries(xcbuild xcdriver)
install(TARGETS xcbuild DESTINATION usr/bin)

add_custom_command(TARGET xcbuild
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE_NAME:xcbuild> $<TARGET_FILE_DIR:xcbuild>/xcodebuild
DEPENDS $<TARGET_FILE:xcbuild>)
install(FILES $<TARGET_FILE_DIR:xcbuild>/xcodebuild DESTINATION usr/bin)
set(ALIAS_PATH "$<TARGET_FILE_DIR:xcbuild>/xcodebuild${CMAKE_EXECUTABLE_SUFFIX}")
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
add_custom_command(TARGET xcbuild
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:xcbuild>" "${ALIAS_PATH}"
DEPENDS "$<TARGET_FILE:xcbuild>")
else ()
add_custom_command(TARGET xcbuild
COMMAND "${CMAKE_COMMAND}" -E create_symlink "$<TARGET_FILE_NAME:xcbuild>" "${ALIAS_PATH}"
DEPENDS "$<TARGET_FILE:xcbuild>")
endif ()
install(FILES "${ALIAS_PATH}" DESTINATION usr/bin)

if (BUILD_TESTING)
ADD_UNIT_GTEST(xcdriver Options Tests/test_Options.cpp)
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcexecution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#


add_library(xcexecution SHARED
add_library(xcexecution
Sources/Parameters.cpp
Sources/Executor.cpp
Sources/SimpleExecutor.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcformatter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcformatter SHARED
add_library(xcformatter
Sources/Formatter.cpp
Sources/DefaultFormatter.cpp
Sources/NullFormatter.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcscheme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcscheme SHARED
add_library(xcscheme
Sources/SchemeGroup.cpp
Sources/XC/Action.cpp
Sources/XC/ActionContent.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcsdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcsdk SHARED
add_library(xcsdk
Sources/Configuration.cpp
Sources/Environment.cpp
Sources/SDK/Manager.cpp
Expand Down
2 changes: 1 addition & 1 deletion Libraries/xcworkspace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
#

add_library(xcworkspace SHARED
add_library(xcworkspace
Sources/XC/Workspace.cpp
Sources/XC/FileRef.cpp
Sources/XC/Group.cpp
Expand Down

0 comments on commit 7a00183

Please sign in to comment.