Skip to content

Commit 90d772c

Browse files
committed
Refactor j target and build tsdll & jconsole
1 parent 1c5e5b6 commit 90d772c

File tree

4 files changed

+127
-15
lines changed

4 files changed

+127
-15
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ endif()
2222

2323
set(CMAKE_C_STANDARD 11)
2424
set(CMAKE_C_STANDARD_REQUIRED ON)
25+
set(CMAKE_C_VISIBILITY_PRESET hidden)
2526
set(CMAKE_CXX_STANDARD 17)
2627
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2728
set(CMAKE_CXX_EXTENSIONS OFF)
29+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
2830

31+
find_package(StandardMathLibrary REQUIRED)
2932
find_package(OpenMP)
3033

3134
set(TARGET_ARCHITECTURE "skylake" CACHE STRING "CPU architecture")
@@ -79,10 +82,10 @@ add_subdirectory(dllsrc)
7982
add_subdirectory(jsrc/openssl/sha)
8083

8184
if(BUILD_SHARED_LIBS)
82-
set_target_properties(j-blis j-openssl-sha j-sleef j-base64 PROPERTIES
85+
set_target_properties(j-openssl-sha j-sleef j-base64 PROPERTIES
8386
POSITION_INDEPENDENT_CODE ON)
8487
endif()
85-
target_link_libraries(j PRIVATE j-blis j-openssl-sha j-sleef j-base64)
88+
target_link_libraries(j PRIVATE j-openssl-sha j-sleef j-base64)
8689
if(WIN32)
8790
target_link_libraries(j PRIVATE j-dll)
8891
target_sources(j PRIVATE dllsrc/jdll.def dllsrc/jdll.rc dllsrc/jdll.tlb)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# - Try to find how to link to the standard math library, if anything at all is needed to do.
2+
# On most platforms this is automatic, but for example it's not automatic on QNX.
3+
#
4+
# Once done this will define
5+
#
6+
# STANDARD_MATH_LIBRARY_FOUND - we found how to successfully link to the standard math library
7+
# STANDARD_MATH_LIBRARY - the name of the standard library that one has to link to.
8+
# -- this will be left empty if it's automatic (most platforms).
9+
# -- this will be set to "m" on platforms where one must explicitly
10+
# pass the "-lm" linker flag.
11+
#
12+
# Copyright (c) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
13+
# 2020 Susi Lehtola <susi.lehtola@gmail.com>
14+
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
15+
16+
17+
include(CheckCSourceCompiles)
18+
19+
# a little test program for c math functions.
20+
21+
# We read in the arguments from standard input to avoid the compiler optimizing away the calls
22+
set(find_standard_math_library_test_program
23+
"
24+
#include<fenv.h>
25+
int main(int argc, char **argv){
26+
return fetestexcept(argc);
27+
}")
28+
29+
# first try compiling/linking the test program without any linker flags
30+
31+
set(CMAKE_REQUIRED_FLAGS "")
32+
set(CMAKE_REQUIRED_LIBRARIES "")
33+
CHECK_C_SOURCE_COMPILES(
34+
"${find_standard_math_library_test_program}"
35+
standard_math_library_linked_to_automatically
36+
)
37+
38+
if(standard_math_library_linked_to_automatically)
39+
40+
# the test program linked successfully without any linker flag.
41+
set(STANDARD_MATH_LIBRARY "")
42+
set(STANDARD_MATH_LIBRARY_FOUND TRUE)
43+
44+
else()
45+
46+
# the test program did not link successfully without any linker flag.
47+
# This is a very uncommon case that so far we only saw on QNX. The next try is the
48+
# standard name 'm' for the standard math library.
49+
50+
set(CMAKE_REQUIRED_LIBRARIES "m")
51+
CHECK_C_SOURCE_COMPILES(
52+
"${find_standard_math_library_test_program}"
53+
standard_math_library_linked_to_as_m)
54+
55+
if(standard_math_library_linked_to_as_m)
56+
57+
# the test program linked successfully when linking to the 'm' library
58+
set(STANDARD_MATH_LIBRARY "m")
59+
set(STANDARD_MATH_LIBRARY_FOUND TRUE)
60+
61+
else()
62+
63+
# the test program still doesn't link successfully
64+
set(STANDARD_MATH_LIBRARY_FOUND FALSE)
65+
66+
endif()
67+
68+
endif()

dllsrc/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
add_library(j-dll OBJECT)
1+
add_library(j-dll OBJECT EXCLUDE_FROM_ALL)
22
target_compile_definitions(j-dll PRIVATE $<$<BOOL:BUILD_SHARED_LIBS>:_JDLL>)
33
target_compile_definitions(j-dll PRIVATE _CRT_SECURE_NO_WARNINGS)
4-
set_target_properties(j-dll PROPERTIES EXCLUDE_FROM_ALL YES)
54
target_sources(j-dll PRIVATE
65
jdll.c
76
jdll.h

jsrc/CMakeLists.txt

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
add_compile_definitions(C_NA=0 C_AVX=1 C_AVX2=1 EMU_AVX=1)
2-
if(WIN32)
3-
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
4-
endif()
5-
61
add_library(j)
7-
set_target_properties(j PROPERTIES CXX_VISIBILITY_PRESET hidden)
2+
target_compile_definitions(j PRIVATE C_NA=0 C_AVX=1 C_AVX2=1 EMU_AVX=1)
3+
target_compile_definitions(j PRIVATE $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>)
4+
target_link_libraries(j PRIVATE ${STANDARD_MATH_LIBRARY})
85
set_source_files_properties(aes-ni.c PROPERTIES COMPILE_FLAGS -maes)
96
target_sources(j PRIVATE
107
a.h
@@ -16,7 +13,6 @@ target_sources(j PRIVATE
1613
avxintrin-neon.h
1714
cip_t.h
1815
cipfloatmm_t.h
19-
com_jsoftware_j_JInterface.h
2016
cpuinfo.h
2117
cr_t.h
2218
crc32c.h
@@ -34,9 +30,7 @@ target_sources(j PRIVATE
3430
js.h
3531
jt.h
3632
jtype.h
37-
jversion-x.h
3833
jversion.h
39-
jx_utils_jnative.h
4034
linenoise.h
4135
m.h
4236
p.h
@@ -195,8 +189,9 @@ target_sources(j PRIVATE
195189
crc32c.c
196190
)
197191

198-
add_library(j-blis OBJECT)
199-
target_sources(j-blis PRIVATE
192+
configure_file(jversion-x.h ${CMAKE_CURRENT_SOURCE_DIR}/jversion.h COPYONLY)
193+
194+
target_sources(j PRIVATE
200195
blis.h
201196
blis/gemm_c-ref.c
202197
blis/gemm_int-aarch64.c
@@ -205,3 +200,50 @@ target_sources(j-blis PRIVATE
205200
blis/gemm_int-sse2.c
206201
blis/gemm_vec-ref.c
207202
)
203+
204+
if(NOT BUILD_SHARED_LIBS)
205+
return()
206+
endif()
207+
208+
add_library(tsdll SHARED)
209+
target_link_libraries(tsdll PRIVATE ${STANDARD_MATH_LIBRARY})
210+
target_sources(tsdll PRIVATE
211+
tsdll.c
212+
../makevs/tsdll/tsdll.def
213+
)
214+
215+
add_library(linenoise OBJECT EXCLUDE_FROM_ALL)
216+
target_compile_definitions(linenoise INTERFACE USE_LINENOISE)
217+
target_compile_definitions(linenoise PUBLIC $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>)
218+
target_sources(linenoise PRIVATE
219+
linenoise.h
220+
linenoise.c
221+
)
222+
223+
add_executable(jconsole)
224+
target_compile_definitions(jconsole PRIVATE READLINE)
225+
if(NOT UNIX OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(aarch64|arm)")
226+
target_link_libraries(jconsole PRIVATE linenoise)
227+
endif()
228+
if("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
229+
target_link_options(jconsole PRIVATE /STACK:0x1000000)
230+
endif()
231+
target_link_libraries(jconsole PRIVATE ${CMAKE_DL_LIBS})
232+
target_sources(jconsole PRIVATE
233+
jconsole.c
234+
jeload.h
235+
jeload.c
236+
jlib.h
237+
../makevs/jconsole/jconsole.rc
238+
../makevs/jconsole/resource1.h
239+
../makevs/jconsole/jgray.ico
240+
)
241+
242+
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/jlibrary/bin" J_BINPATH)
243+
file(TO_NATIVE_PATH "/profile.ijs" J_PROFILE_SCRIPT)
244+
file(GENERATE
245+
OUTPUT "$<${is_multi_config}:$<CONFIG>/>profile.ijs"
246+
CONTENT "NB. loaded under debug
247+
BINPATH_z_=: '${J_BINPATH}'
248+
0!:0<BINPATH,'${J_PROFILE_SCRIPT}'"
249+
)

0 commit comments

Comments
 (0)