Skip to content
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

Migrate to all-in-one CMake-based build configuration #20

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jj.ijs
*.sln*
*.vcxproj*
!*.template
.vs/

# mac
.DS_Store
Expand All @@ -58,6 +59,8 @@ release
/test/temp.ijs

# build folders
out/
build/
bin/
make2/
jlibrary/addons/
Expand Down
94 changes: 94 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
cmake_minimum_required(VERSION 3.17)

get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING
"Semicolon separated list of supported configuration types")
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
elseif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS)
message(WARNING "No CMAKE_BUILD_TYPE is selected")
endif()

project(j)
enable_language(C CXX ASM)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(CTest)
include(OptimizeForArchitecture)

if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(BUILD_SHARED_LIBS ON)
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

find_package(StandardMathLibrary REQUIRED)
find_package(OpenMP)
find_package(JNI)

set(TARGET_ARCHITECTURE "skylake" CACHE STRING "CPU architecture")
OptimizeForArchitecture()
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${Vc_ARCHITECTURE_FLAGS}>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${Vc_ARCHITECTURE_FLAGS}>")

add_compile_options($<$<COMPILE_LANGUAGE:C>:-fno-strict-aliasing>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Werror>)
if("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:strictStrings>)
else()
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wextra>)
endif()
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-unused-parameter>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-unused-value>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-unused-function>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-unused-variable>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-sign-compare>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-cast-function-type>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-clobbered>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-empty-body>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-parentheses>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-pointer-sign>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-format-overflow>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-implicit-fallthrough>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-missing-field-initializers>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-shift-negative-value>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wuninitialized>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-maybe-uninitialized>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-type-limits>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wuninitialized>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-sometimes-uninitialized>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wtautological-constant-out-of-range-compare>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-char-subscripts>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-consumed>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-implicit-float-conversion>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-implicit-int-float-conversion>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-int-in-bool-context>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-string-plus-int>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-missing-braces>)
add_compile_options($<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-unknown-pragmas>)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:-Wno-delete-non-abstract-non-virtual-dtor>)

add_subdirectory(jsrc)
add_subdirectory(sleef)
add_subdirectory(base64)
add_subdirectory(dllsrc)
add_subdirectory(jsrc/openssl/sha)

if(BUILD_SHARED_LIBS)
set_target_properties(j-openssl-sha j-sleef j-base64 PROPERTIES
POSITION_INDEPENDENT_CODE ON)
add_subdirectory(test)
endif()
target_link_libraries(j PRIVATE j-openssl-sha j-sleef j-base64)
if(WIN32)
target_link_libraries(j PRIVATE j-dll)
target_sources(j PRIVATE dllsrc/jdll.def dllsrc/jdll.rc dllsrc/jdll.tlb)
endif()
28 changes: 28 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"configurations": [
{
"name": "x64-Clang-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ],
"variables": []
},
{
"name": "x64-Clang-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ],
"variables": []
}
]
}
21 changes: 21 additions & 0 deletions base64/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_library(j-base64 OBJECT)
target_compile_definitions(j-base64 PRIVATE HAVE_AVX2=1)
target_sources(j-base64 PRIVATE
include/libbase64.h
lib/arch/avx/codec-avx.c
lib/arch/avx2/codec-avx2.c
lib/arch/generic/codec-generic.c
lib/arch/neon64/codec-neon64.c
lib/arch/sse41/codec-sse41.c
lib/arch/sse42/codec-sse42.c
lib/arch/ssse3/codec-ssse3.c
lib/codecs.h
lib/codec_choose.c
lib/config.h
lib/env.h
lib/lib.c
lib/tables/tables.c
lib/tables/tables.h
lib/tables/table_dec_32bit.h
lib/tables/table_enc_12bit.h
)
130 changes: 130 additions & 0 deletions cmake/AddCompilerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# - Add a given compiler flag to flags variables.
# AddCompilerFlag(<flag> [<var>])
# or
# AddCompilerFlag(<flag> [C_FLAGS <var>] [CXX_FLAGS <var>] [C_RESULT <var>]
# [CXX_RESULT <var>])

#=============================================================================
# Copyright 2010-2015 Matthias Kretz <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the names of contributing organizations nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

get_filename_component(_currentDir "${CMAKE_CURRENT_LIST_FILE}" PATH)
include("${_currentDir}/CheckCCompilerFlag.cmake")
include("${_currentDir}/CheckCXXCompilerFlag.cmake")

macro(AddCompilerFlag _flag)
string(REGEX REPLACE "[-.+/:= ]" "_" _flag_esc "${_flag}")

set(_c_flags "CMAKE_C_FLAGS")
set(_cxx_flags "CMAKE_CXX_FLAGS")
set(_c_result tmp)
set(_cxx_result tmp)
if(${ARGC} EQUAL 2)
message(WARNING "Deprecated use of the AddCompilerFlag macro.")
unset(_c_result)
set(_cxx_result ${ARGV1})
elseif(${ARGC} GREATER 2)
set(state 0)
unset(_c_flags)
unset(_cxx_flags)
unset(_c_result)
unset(_cxx_result)
foreach(_arg ${ARGN})
if("x${_arg}" STREQUAL "xC_FLAGS")
set(state 1)
if(NOT DEFINED _c_result)
set(_c_result tmp0)
endif()
elseif("x${_arg}" STREQUAL "xCXX_FLAGS")
set(state 2)
if(NOT DEFINED _cxx_result)
set(_cxx_result tmp1)
endif()
elseif("x${_arg}" STREQUAL "xC_RESULT")
set(state 3)
elseif("x${_arg}" STREQUAL "xCXX_RESULT")
set(state 4)
elseif(state EQUAL 1)
set(_c_flags "${_arg}")
elseif(state EQUAL 2)
set(_cxx_flags "${_arg}")
elseif(state EQUAL 3)
set(_c_result "${_arg}")
elseif(state EQUAL 4)
set(_cxx_result "${_arg}")
else()
message(FATAL_ERROR "Syntax error for AddCompilerFlag")
endif()
endforeach()
endif()

set(_c_code "int main() { return 0; }")
set(_cxx_code "int main() { return 0; }")
if("${_flag}" STREQUAL "-mfma")
# Compiling with FMA3 support may fail only at the assembler level.
# In that case we need to have such an instruction in the test code
set(_c_code "#include <immintrin.h>
__m128 foo(__m128 x) { return _mm_fmadd_ps(x, x, x); }
int main() { return 0; }")
set(_cxx_code "${_c_code}")
elseif("${_flag}" STREQUAL "-stdlib=libc++")
# Compiling with libc++ not only requires a compiler that understands it, but also
# the libc++ headers itself
set(_cxx_code "#include <iostream>
#include <cstdio>
int main() { return 0; }")
else()
set(_cxx_code "#include <cstdio>
int main() { return 0; }")
endif()

if(DEFINED _c_result)
check_c_compiler_flag("${_flag}" check_c_compiler_flag_${_flag_esc} "${_c_code}")
set(${_c_result} ${check_c_compiler_flag_${_flag_esc}})
endif()
if(DEFINED _cxx_result)
check_cxx_compiler_flag("${_flag}" check_cxx_compiler_flag_${_flag_esc} "${_cxx_code}")
set(${_cxx_result} ${check_cxx_compiler_flag_${_flag_esc}})
endif()

macro(my_append _list _flag _special)
if("x${_list}" STREQUAL "x${_special}")
set(${_list} "${${_list}} ${_flag}")
else()
list(APPEND ${_list} "${_flag}")
endif()
endmacro()

if(check_c_compiler_flag_${_flag_esc} AND DEFINED _c_flags)
my_append(${_c_flags} "${_flag}" CMAKE_C_FLAGS)
endif()
if(check_cxx_compiler_flag_${_flag_esc} AND DEFINED _cxx_flags)
my_append(${_cxx_flags} "${_flag}" CMAKE_CXX_FLAGS)
endif()
endmacro(AddCompilerFlag)
73 changes: 73 additions & 0 deletions cmake/CheckCCompilerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# - Check whether the C compiler supports a given flag.
# CHECK_C_COMPILER_FLAG(<flag> <var>)
# <flag> - the compiler flag
# <var> - variable to store the result
# This internally calls the check_c_source_compiles macro.
# See help for CheckCSourceCompiles for a listing of variables
# that can modify the build.

#=============================================================================
# Copyright 2006-2009 Kitware, Inc.
# Copyright 2006 Alexander Neundorf <[email protected]>
# Copyright 2011-2013 Matthias Kretz <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * The names of Kitware, Inc., the Insight Consortium, or the names of
# any consortium members, or of any contributors, may not be used to
# endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

INCLUDE(CheckCSourceCompiles)

MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
if(${ARGC} GREATER 2)
SET(TEST_SOURCE "${ARGV2}")
else()
SET(TEST_SOURCE "int main() { return 0;}")
endif()
CHECK_C_SOURCE_COMPILES("${TEST_SOURCE}" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "error: bad value (.*) for .* switch" # GNU
FAIL_REGEX "argument unused during compilation" # clang
FAIL_REGEX "is valid for .* but not for C" # GNU
FAIL_REGEX "unrecognized .*option" # GNU
FAIL_REGEX "ignored for target" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC
FAIL_REGEX "warning D9002" # MSVC
FAIL_REGEX "[Uu]nknown option" # HP
FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
FAIL_REGEX "command option .* is not recognized" # XL
FAIL_REGEX "WARNING: unknown flag:" # Open64
FAIL_REGEX "command line error" # ICC
FAIL_REGEX "command line warning" # ICC
FAIL_REGEX "#10236:" # ICC: File not found
FAIL_REGEX " #10159: " # ICC
FAIL_REGEX " #10353: " # ICC: option '-mfma' ignored, suggest using '-march=core-avx2'
)
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
ENDMACRO (CHECK_C_COMPILER_FLAG)

Loading